Test Failed
Push — master ( 46a9e3...b06516 )
by Koldo
05:39
created

ReactHttpServer::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
rs 10
ccs 0
cts 8
cp 0
cc 2
nc 2
nop 2
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antidot\React;
6
7
use Antidot\Application\Http\Application;
8
use React\EventLoop\LoopInterface;
9
use React\Http\Server;
10
use React\Socket\Server as Socketserver;
11
use Symfony\Component\Console\Command\Command;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
class ReactHttpServer extends Command
16
{
17
    public const NAME = 'react-server:http';
18
    private $config;
19
20
    public function __construct(array $config)
21
    {
22
        parent::__construct();
23
        $this->config = $config;
24
    }
25
26
    protected function configure(): void
27
    {
28
        $this->setName(self::NAME);
29
    }
30
31
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33
        $middleware = require $this->config['middleware_path'];
34
        $routes = require $this->config['router_path'];
35
        $container = require $this->config['container_path'];
36
        /** @var LoopInterface $loop */
37
        $loop = $container->get(LoopInterface::class);
38
        /** @var ReactPHPApplication $application */
39
        $application = $container->get(Application::class);
40
        $middleware($application, $container);
41
        $routes($application, $container);
42
        $server = new Server($application);
43
44
        $socket = new Socketserver($this->config['uri'], $loop);
45
        $server->listen($socket);
46
47
        $loop->run();
48
    }
49
}
50