-
Notifications
You must be signed in to change notification settings - Fork 0
/
AerysInternals.php
112 lines (90 loc) · 2.5 KB
/
AerysInternals.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
namespace DataValidata\AsyncApp;
use Aerys\Bootable;
use Aerys\Server;
use Psr\Log\LoggerInterface as PsrLogger;
class AerysInternals implements Bootable, PsrLogger
{
/** @var Server */
private $server = null;
/** @var PsrLogger */
private $logger = null;
private $booted = false;
private $logBuffer = [];
function boot(Server $server, PsrLogger $logger)
{
$this->server = $server;
$this->logger = $logger;
$this->booted = true;
while(($bufferedMessage = array_shift($this->logBuffer))) {
var_dump($bufferedMessage);
call_user_func_array([$this, 'delegateLog'], $bufferedMessage);
}
}
/**
* @return Server
*/
public function getServer()
{
return $this->server;
}
/**
* @return PsrLogger
*/
public function getLogger()
{
return $this->logger;
}
/**
* @return bool
*/
public function isBooted()
{
return $this->booted;
}
private function delegateLog(...$args)
{
if($this->isBooted()) {
$logType = array_shift($args);
call_user_func_array([$this->logger, $logType], $args);
} else {
$this->logBuffer[] = $args;
}
}
public function emergency($message, array $context = array())
{
$this->delegateLog(__FUNCTION__, $message, $context);
}
public function alert($message, array $context = array())
{
$this->delegateLog(__FUNCTION__, $message, $context);
}
public function critical($message, array $context = array())
{
$this->delegateLog(__FUNCTION__, $message, $context);
}
public function error($message, array $context = array())
{
$this->delegateLog(__FUNCTION__, $message, $context);
}
public function warning($message, array $context = array())
{
$this->delegateLog(__FUNCTION__, $message, $context);
}
public function notice($message, array $context = array())
{
$this->delegateLog(__FUNCTION__, $message, $context);
}
public function info($message, array $context = array())
{
$this->delegateLog(__FUNCTION__, $message, $context);
}
public function debug($message, array $context = array())
{
$this->delegateLog(__FUNCTION__, $message, $context);
}
public function log($level, $message, array $context = array())
{
$this->delegateLog(__FUNCTION__, $level, $message, $context);
}
}