-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReactRunner.php
More file actions
72 lines (63 loc) · 1.68 KB
/
ReactRunner.php
File metadata and controls
72 lines (63 loc) · 1.68 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
63
64
65
66
67
68
69
70
71
72
<?php
declare(strict_types=1);
namespace Lit\Runner\React;
use Lit\Air\Factory;
use Lit\Bolt\BoltContainerConfiguration;
use Psr\Container\ContainerInterface;
use React\EventLoop\LoopInterface;
use React\Http\Server;
use React\Http\StreamingServer;
use React\Socket\Server as SocketServer;
/**
* react runner
*/
class ReactRunner
{
/**
* @var LoopInterface
*/
protected $loop;
/**
* @var SocketServer
*/
protected $socketServer;
/**
* @var Server|StreamingServer
*/
protected $server;
/**
* ReactRunner constructor.
*
* @param Server|StreamingServer $server React server.
* @param LoopInterface $loop React eventloop.
* @param SocketServer $socketServer React socket server.
*/
public function __construct($server, LoopInterface $loop, SocketServer $socketServer)
{
assert($server instanceof Server || $server instanceof StreamingServer);
$this->loop = $loop;
$this->socketServer = $socketServer;
$this->server = $server;
}
/**
* run a bolt app with react
*
* @param array $config The application configuration.
*/
public static function run($config = [])
{
$container = $config instanceof ContainerInterface
? $config
: BoltContainerConfiguration::createContainer($config + ReactConfiguration::default());
/**
* @var static
*/
$instance = Factory::of($container)->getOrProduce(static::class);
$instance->work();
}
protected function work()
{
$this->server->listen($this->socketServer);
$this->loop->run();
}
}