Master::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace mpyw\HyperBuiltinServer;
4
use mpyw\HyperBuiltinServer\Internal\ConnectionHandler;
5
use mpyw\HyperBuiltinServer\Internal\Queue;
6
use React\EventLoop\LoopInterface;
7
use React\Socket\Server;
8
9
class Master
10
{
11
    public $loop;
12
    public $queue;
13
14
    public function __construct(LoopInterface $loop, array $processes)
15
    {
16
        $this->loop = $loop;
17
        $this->queue = new Queue($processes);
18
    }
19
20
    public function addListener($host = '127.0.0.1', $port = 8080, $use_ssl = false, $cert = null)
21
    {
22
        $proxy = new Server($this->loop);
23
        $proxy->on('connection', new ConnectionHandler($this));
24
        $context = !$use_ssl ? [] : [
25
            'ssl' => [
26
                'local_cert' => $cert === null ? (__DIR__ . '/../certificate.pem') : $cert,
27
                'allow_self_signed' => true,
28
                'verify_peer' => false,
29
            ],
30
        ];
31
        $proxy->listen($port, $host, $context);
32
    }
33
}
34