1
0
mirror of https://github.com/flarum/core.git synced 2025-10-12 23:44:27 +02:00
Files
php-flarum/src/Http/Server.php
Franz Liedke 626d16de6f 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.
2018-08-22 07:58:50 +02:00

47 lines
1.1 KiB
PHP

<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Http;
use Psr\Http\Server\RequestHandlerInterface;
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
{
protected $requestHandler;
public function __construct(RequestHandlerInterface $requestHandler)
{
$this->requestHandler = $requestHandler;
}
public function 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();
}
}