1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Antidot\React\Container\Config; |
4
|
|
|
|
5
|
|
|
use Antidot\Application\Http\Application; |
6
|
|
|
use Antidot\React\LoopFactory; |
7
|
|
|
use Antidot\React\ReactApplicationFactory; |
8
|
|
|
use Antidot\React\RunServerCommandFactory; |
9
|
|
|
use Antidot\React\ServerFactory; |
10
|
|
|
use Antidot\React\SocketFactory; |
11
|
|
|
use Antidot\React\WatchServerCommandFactory; |
12
|
|
|
use Drift\Server\Console\RunServerCommand; |
13
|
|
|
use Drift\Server\Console\WatchServerCommand; |
14
|
|
|
use React\EventLoop\LoopInterface; |
15
|
|
|
use React\Http\Server; |
16
|
|
|
use React\Socket\Server as Socket; |
17
|
|
|
|
18
|
|
|
class ConfigProvider |
19
|
|
|
{ |
20
|
|
|
private const DEFAULT_HOST = '0.0.0.0'; |
21
|
|
|
private const DEFAULT_PORT = 8080; |
22
|
|
|
private const DEFAULT_CONCURRENCY = 100; |
23
|
|
|
private const DEFAULT_BUFFER_SIZE = 4 * 1024 * 1024; |
24
|
|
|
|
25
|
1 |
|
public function __invoke(): array |
26
|
|
|
{ |
27
|
|
|
return [ |
28
|
|
|
'dependencies' => [ |
29
|
|
|
'factories' => [ |
30
|
1 |
|
Application::class => ReactApplicationFactory::class, |
31
|
|
|
LoopInterface::class => LoopFactory::class, |
32
|
|
|
Server::class => ServerFactory::class, |
33
|
|
|
Socket::class => SocketFactory::class, |
34
|
|
|
], |
35
|
|
|
], |
36
|
1 |
|
'console' => $this->getConsoleConfig(), |
37
|
|
|
'server' => [ |
38
|
|
|
'host' => '0.0.0.0', |
39
|
|
|
'port' => 5555, |
40
|
|
|
'buffer_size' => 4096, |
41
|
|
|
'max_concurrency' => 100, |
42
|
|
|
'workers' => 1, |
43
|
|
|
'static_folder' => 'public' |
44
|
|
|
] |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
|
|
48
|
1 |
|
private function getConsoleConfig(): array |
49
|
|
|
{ |
50
|
1 |
|
$hasWatcher = class_exists(WatchServerCommand::class); |
51
|
|
|
|
52
|
1 |
|
return $hasWatcher |
53
|
|
|
? [ |
54
|
|
|
'commands' => [ |
55
|
1 |
|
'server:run' => RunServerCommand::class, |
56
|
|
|
'server:watch' => WatchServerCommand::class |
57
|
|
|
], |
58
|
|
|
'factories' => [ |
59
|
|
|
RunServerCommand::class => RunServerCommandFactory::class, |
60
|
|
|
WatchServerCommand::class => WatchServerCommandFactory::class, |
61
|
|
|
] |
62
|
|
|
] |
63
|
|
|
: [ |
64
|
|
|
'commands' => [ |
65
|
1 |
|
'server:run' => RunServerCommand::class, |
66
|
|
|
], |
67
|
|
|
'factories' => [ |
68
|
|
|
RunServerCommand::class => RunServerCommandFactory::class, |
69
|
|
|
] |
70
|
|
|
]; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|