Use zend-httphandlerrunner for marshalling requests and returning responses

Since Diactoros 1.8, the emitter and server classes have been
deprecated. They can be replaced by using this new package
directly.
This commit is contained in:
Franz Liedke 2018-08-02 23:46:39 +02:00
parent 61834b006f
commit 2d4802d637
2 changed files with 19 additions and 9 deletions

View File

@ -58,6 +58,7 @@
"symfony/yaml": "^3.3",
"tobscure/json-api": "^0.3.0",
"zendframework/zend-diactoros": "^1.8.4",
"zendframework/zend-httphandlerrunner": "^1.0",
"zendframework/zend-stratigility": "^3.0"
},
"require-dev": {

View File

@ -12,7 +12,13 @@
namespace Flarum\Http;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Server as DiactorosServer;
use Throwable;
use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\ServerRequestFactory;
use Zend\HttpHandlerRunner\Emitter\SapiEmitter;
use Zend\HttpHandlerRunner\RequestHandlerRunner;
use Zend\Stratigility\Middleware\ErrorResponseGenerator;
class Server
{
@ -25,13 +31,16 @@ class Server
public function listen()
{
DiactorosServer::createServer(
[$this->requestHandler, 'handle'],
$_SERVER,
$_GET,
$_POST,
$_COOKIE,
$_FILES
)->listen();
$runner = new RequestHandlerRunner(
$this->requestHandler,
new SapiEmitter,
[ServerRequestFactory::class, 'fromGlobals'],
function (Throwable $e) {
$generator = new ErrorResponseGenerator;
return $generator($e, new ServerRequest, new Response);
}
);
$runner->run();
}
}