|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* HTTP server init |
|
4
|
|
|
* User: moyo |
|
5
|
|
|
* Date: 2018/5/29 |
|
6
|
|
|
* Time: 2:45 PM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Carno\Web\Components; |
|
10
|
|
|
|
|
11
|
|
|
use Carno\Console\Component; |
|
12
|
|
|
use Carno\Console\Contracts\Application; |
|
13
|
|
|
use Carno\Console\Contracts\Bootable; |
|
14
|
|
|
use Carno\Container\DI; |
|
15
|
|
|
use Carno\Monitor\Daemon; |
|
16
|
|
|
use Carno\Web\Dispatcher; |
|
17
|
|
|
use Carno\Web\Handlers\AccessLogger; |
|
18
|
|
|
use Carno\Web\Handlers\ExceptionReview; |
|
19
|
|
|
use Carno\Web\Handlers\IngressReplier; |
|
20
|
|
|
use Carno\Web\Handlers\IngressWrapper; |
|
21
|
|
|
use Carno\Web\Handlers\TrafficMonitor; |
|
22
|
|
|
use Carno\Web\Options; |
|
23
|
|
|
use Carno\Web\Server; |
|
24
|
|
|
|
|
25
|
|
|
class Serving extends Component implements Bootable |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $dependencies = [Dispatcher::class]; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param Application $app |
|
34
|
|
|
*/ |
|
35
|
|
|
public function starting(Application $app) : void |
|
36
|
|
|
{ |
|
37
|
|
|
// controller invoker |
|
38
|
|
|
Server::layers()->append( |
|
39
|
|
|
null, |
|
40
|
|
|
DI::object(AccessLogger::class), |
|
41
|
|
|
DI::object(IngressReplier::class), |
|
42
|
|
|
DI::object(IngressWrapper::class, DI::get(Dispatcher::class), $options = new Options) |
|
43
|
|
|
); |
|
44
|
|
|
|
|
45
|
|
|
// exception dumps |
|
46
|
|
|
Server::layers()->prepend(null, DI::object(ExceptionReview::class)); |
|
47
|
|
|
|
|
48
|
|
|
// starting wait |
|
49
|
|
|
$app->starting()->add(static function () use ($options) { |
|
50
|
|
|
// add traffic monitor layer |
|
51
|
|
|
DI::has(Daemon::class) && Server::layers()->prepend( |
|
52
|
|
|
IngressWrapper::class, |
|
53
|
|
|
DI::object(TrafficMonitor::class) |
|
54
|
|
|
); |
|
55
|
|
|
// configurable options link |
|
56
|
|
|
config()->bind($options, ['web.serv.opts' => ['tt.exec' => 'ttExec']]); |
|
57
|
|
|
}); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|