diff --git a/components/runtime.rst b/components/runtime.rst index 5e6e173240c..bdb5a9f6e20 100644 --- a/components/runtime.rst +++ b/components/runtime.rst @@ -396,9 +396,8 @@ is added in a new class implementing :class:`Symfony\\Component\\Runtime\\Runner use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; - use React\EventLoop\Factory as ReactFactory; - use React\Http\Server as ReactHttpServer; - use React\Socket\Server as ReactSocketServer; + use React\Http\HttpServer as ReactHttpServer; + use React\Socket\SocketServer as ReactSocketServer; use Symfony\Component\Runtime\RunnerInterface; class ReactPHPRunner implements RunnerInterface @@ -412,21 +411,18 @@ is added in a new class implementing :class:`Symfony\\Component\\Runtime\\Runner public function run(): int { $application = $this->application; - $loop = ReactFactory::create(); - // configure ReactPHP to correctly handle the PSR-15 application - $server = new ReactHttpServer( - $loop, - function (ServerRequestInterface $request) use ($application): ResponseInterface { - return $application->handle($request); - } - ); + $serverAddress = '127.0.0.1:' . $this->port; + $socket = new ReactSocketServer($serverAddress); + + $server = new ReactHttpServer(function (ServerRequestInterface $requestHandler) use ($application) { + return $application->handle($requestHandler) ; + }); - // start the ReactPHP server - $socket = new ReactSocketServer($this->port, $loop); + // listen the ReactPHP socket $server->listen($socket); - $loop->run(); + echo "Server running at http://" . $serverAddress . PHP_EOL; return 0; } @@ -462,9 +458,11 @@ always using this ``ReactPHPRunner``:: The end user will now be able to create front controller like:: + use Psr\Http\Server\RequestHandlerInterface; + require_once dirname(__DIR__).'/vendor/autoload_runtime.php'; - return function (array $context): SomeCustomPsr15Application { + return function (array $context): RequestHandlerInterface { return new SomeCustomPsr15Application(); };