From 2d4802d63748351f451ebcbdad323006b3610682 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Thu, 2 Aug 2018 23:46:39 +0200 Subject: [PATCH] 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. --- framework/core/composer.json | 1 + framework/core/src/Http/Server.php | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/framework/core/composer.json b/framework/core/composer.json index 1ba12df12..f0f3ce9ff 100644 --- a/framework/core/composer.json +++ b/framework/core/composer.json @@ -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": { diff --git a/framework/core/src/Http/Server.php b/framework/core/src/Http/Server.php index 825dc4bce..6c24afba6 100644 --- a/framework/core/src/Http/Server.php +++ b/framework/core/src/Http/Server.php @@ -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(); } }