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