ServerStart::firing()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 1
nop 1
dl 0
loc 14
rs 9.9332
c 0
b 0
f 0
1
<?php
2
/**
3
 * Web server -> start
4
 * User: moyo
5
 * Date: 12/12/2017
6
 * Time: 12:45 PM
7
 */
8
9
namespace Carno\Web\Commands;
10
11
use Carno\Console\Based;
12
use Carno\Console\Contracts\Application;
13
use Carno\Net\Address;
14
use Carno\Serving\Chips\HWIGet;
15
use Carno\Serving\Contracts\Options;
16
use Carno\Serving\Options as Opt;
17
use Carno\Serving\Plugins\LiveReloading;
18
use Carno\Serving\Plugins\MetricsExporter;
19
use Carno\Serving\Plugins\ServerMonitor;
20
use Carno\Web\Components\Serving;
21
use Carno\Web\Components\Monitor;
22
use Carno\Web\Components\Routing;
23
use Carno\Web\Components\Tracing;
24
use Carno\Web\Server;
25
26
class ServerStart extends Based
27
{
28
    use HWIGet;
29
    use Opt\Common, Opt\Metrics, Opt\Discovery, Opt\Listener;
30
31
    /**
32
     * @var string
33
     */
34
    protected $name = 'server:start';
35
36
    /**
37
     * @var string
38
     */
39
    protected $description = 'Start the HTTP server';
40
41
    /**
42
     * @var array
43
     */
44
    protected $components = [
45
        Routing::class,
46
        Serving::class,
47
        Monitor::class,
48
        Tracing::class,
49
    ];
50
51
    /**
52
     * @var bool
53
     */
54
    protected $ready = false;
55
56
    /**
57
     * @param Application $app
58
     */
59
    protected function firing(Application $app) : void
60
    {
61
        (new Server(
62
            $app->name(),
63
            new Address($app->input()->getOption(Options::LISTEN))
64
        ))
65
            ->bootstrap($this->bootstrap())
66
            ->plugins(
67
                new LiveReloading,
68
                new ServerMonitor,
69
                new MetricsExporter
70
            )
71
            ->wants($app->starting(), $app->stopping())
72
            ->run($app->input()->getOption(Options::WORKERS) ?: $this->numCPUs())
73
        ;
74
    }
75
}
76