This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
Example in documentation throws a fatal error #100
Labels
Comments
Which example, specifically? Also, the exception details what you need to do; what we'll be doing is updating the example to add the response prototype, but first we need to know which example is leading to the error you're seeing. |
this one: use Zend\Stratigility\MiddlewarePipe;
use Zend\Diactoros\Server;
require __DIR__ . '/../vendor/autoload.php';
$app = new MiddlewarePipe();
$server = Server::createServer($app, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
// Landing page
$app->pipe('/', function ($req, $res, $next) {
if (! in_array($req->getUri()->getPath(), ['/', ''], true)) {
return $next($req, $res);
}
$res->getBody()->write('Hello world!');
return $res;
});
// Another page
$app->pipe('/foo', function ($req, $res, $next) {
$res->getBody()->write('FOO!');
return $res;
});
$server->listen(); |
How about this: <?php
use Zend\Stratigility\MiddlewarePipe;
use Zend\Stratigility\NoopFinalHandler;
use Zend\Diactoros\Server;
require __DIR__ . '/vendor/autoload.php';
$app = new MiddlewarePipe();
$app->setResponsePrototype(new \Zend\Diactoros\Response());
$server = Server::createServer($app, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
// Landing page
$app->pipe('/', function ($req, $res, $next) {
if (! in_array($req->getUri()->getPath(), ['/', ''], true)) {
return $next($req, $res);
}
$res->getBody()->write('Hello world!');
return $res;
});
// Another page
$app->pipe('/foo', function ($req, $res, $next) {
$res->getBody()->write('FOO!');
return $res;
});
$server->listen(new NoopFinalHandler()); Original example code is here: https://github.com/zendframework/zend-stratigility/blob/master/doc/book/middleware.md |
Yep that works! |
weierophinney
added a commit
that referenced
this issue
Mar 9, 2017
As reported in #100, the example in the middleware page fails currently, as piping callable double-pass middleware requires a response prototype be composed in the pipeline. This patch adds that.
Fixed with 2c18525. Thanks for the report! |
@weierophinney That fixed the first part. You still need to supply a final handler to the listener as in my example:
|
weierophinney
added a commit
that referenced
this issue
Mar 9, 2017
Thanks, @xtreamwayz — updated now with that. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Using 2.0.1
https://zendframework.github.io/zend-stratigility/middleware/
Will throw
The text was updated successfully, but these errors were encountered: