Server   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 3 1
A __construct() 0 7 1
1
<?php
2
/**
3
 * Web server instance
4
 * User: moyo
5
 * Date: 2018/5/29
6
 * Time: 2:33 PM
7
 */
8
9
namespace Carno\Web;
10
11
use Carno\HTTP\Server as HTServer;
12
use Carno\Net\Address;
13
use Carno\Net\Contracts\Conn;
14
use Carno\Net\Events as NETEvs;
15
use Carno\Serving\Chips\Boots;
16
use Carno\Serving\Chips\Events;
17
use Carno\Serving\Chips\Plugins;
18
use Carno\Serving\Chips\Wants;
19
use Carno\Web\Chips\Chains;
20
21
class Server
22
{
23
    use Chains, Events, Boots, Wants, Plugins;
24
25
    /**
26
     * @var string
27
     */
28
    private $name = null;
29
30
    /**
31
     * @var Address
32
     */
33
    private $listen = null;
34
35
    /**
36
     * HTTP constructor.
37
     * @param string $name
38
     * @param Address $listen
39
     */
40
    public function __construct(string $name, Address $listen)
41
    {
42
        $this->name = $name;
43
        $this->listen = $listen;
44
45
        $this->events()->attach(NETEvs\Worker::STARTED, function (Conn $ctx) {
46
            $ctx->events()->attach(NETEvs\HTTP::REQUESTING, self::layers()->handler());
47
        });
48
    }
49
50
    /**
51
     * @param int $workers
52
     */
53
    public function run(int $workers) : void
54
    {
55
        HTServer::listen($this->listen, $this->events(), $workers, $this->name)->serve();
56
    }
57
}
58