Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Runtime] Update ReactPHP example #19727

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 13 additions & 15 deletions components/runtime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,9 @@

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

Check failure on line 398 in components/runtime.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[Missing class] Class, interface or trait with name "Psr\Http\Server\RequestHandlerInterface" does not exist
use React\EventLoop\Factory as ReactFactory;
use React\Http\Server as ReactHttpServer;
use React\Socket\Server as ReactSocketServer;
use React\Http\HttpServer as ReactHttpServer;

Check failure on line 399 in components/runtime.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[Missing class] Class, interface or trait with name "React\Http\HttpServer" does not exist
use React\Socket\SocketServer as ReactSocketServer;

Check failure on line 400 in components/runtime.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[Missing class] Class, interface or trait with name "React\Socket\SocketServer" does not exist
use Symfony\Component\Runtime\RunnerInterface;

class ReactPHPRunner implements RunnerInterface
Expand All @@ -412,21 +411,18 @@
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;
}
Expand Down Expand Up @@ -462,9 +458,11 @@

The end user will now be able to create front controller like::

use Psr\Http\Server\RequestHandlerInterface;

Check failure on line 461 in components/runtime.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[Missing class] Class, interface or trait with name "Psr\Http\Server\RequestHandlerInterface" does not exist

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context): SomeCustomPsr15Application {
return function (array $context): RequestHandlerInterface {
return new SomeCustomPsr15Application();
};

Expand Down