mirror of
https://github.com/flarum/framework.git
synced 2024-12-03 15:43:59 +08:00
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:
parent
61834b006f
commit
2d4802d637
|
@ -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": {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user