-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReactConfiguration.php
More file actions
62 lines (54 loc) · 1.77 KB
/
ReactConfiguration.php
File metadata and controls
62 lines (54 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
declare(strict_types=1);
namespace Lit\Runner\React;
use Lit\Air\Configurator as C;
use Lit\Bolt\BoltApp;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use React\EventLoop\Factory;
use React\EventLoop\LoopInterface;
use React\Http\Response;
use React\Http\Server;
use React\Http\StreamingServer;
use React\Socket\Server as SocketServer;
/**
* react runner configuration class
*/
class ReactConfiguration
{
/**
* Return default configuration for react runner.
*
* @return array
*/
public static function default()
{
$serverConfiguration = C::provideParameter([
function (BoltApp $app) {
return function (ServerRequestInterface $request) use ($app) {
return $app->handle($request);
};
}
]);
return [
LoopInterface::class => [Factory::class, 'create'],
SocketServer::class => C::provideParameter([
$_ENV['LISTEN'] ?? 8080
]),
Server::class => $serverConfiguration,
StreamingServer::class => $serverConfiguration,
ReactRunner::class => C::provideParameter([
'server' => C::alias(ReactRunner::class, 'server'),
]),
C::join(ReactRunner::class, 'server') => C::alias(StreamingServer::class),
ResponseFactoryInterface::class => new class implements ResponseFactoryInterface
{
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
{
return new Response($code, [], null, '1,1', $reasonPhrase);
}
}
];
}
}