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(); } }