1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apix\Log\Emitter; |
4
|
|
|
|
5
|
|
|
use Apix\Log\Logger; |
6
|
|
|
use Apix\Log\Logger\LoggerInterface; |
7
|
|
|
|
8
|
|
|
abstract class AbstractEmitter implements EmitterInterface |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Holds the emitter/transporter's URL. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $url; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Holds the emitter/transporter's debug mode. |
19
|
|
|
* |
20
|
|
|
* @var bool |
21
|
|
|
*/ |
22
|
|
|
protected $debug = false; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Holds the query parameters. |
26
|
|
|
* |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
protected $params = array(); |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Sets the emitter/transporter's URL. |
33
|
|
|
* |
34
|
|
|
* @param string $url |
35
|
|
|
*/ |
36
|
64 |
|
public function setUrl($url) |
37
|
|
|
{ |
38
|
64 |
|
$this->url = vsprintf($url, $this->params); |
39
|
64 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Sets the emitter/transporter's debug mode. |
43
|
|
|
* |
44
|
|
|
* @param bool $bool |
45
|
|
|
*/ |
46
|
108 |
|
public function setDebug($bool = true) |
47
|
|
|
{ |
48
|
108 |
|
$this->debug = (bool) $bool; |
49
|
108 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Returns the current query parameters. |
53
|
|
|
* |
54
|
|
|
* @return array |
55
|
|
|
*/ |
56
|
76 |
|
public function getParams() |
57
|
|
|
{ |
58
|
76 |
|
return $this->params; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Checks wether the named query parameter exists. |
63
|
|
|
* |
64
|
|
|
* @param string $key |
65
|
|
|
* |
66
|
|
|
* @return bool |
67
|
|
|
*/ |
68
|
12 |
|
public function hasParam($key) |
69
|
|
|
{ |
70
|
12 |
|
return isset($this->params[$key]); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Returns the named query parameter. |
75
|
|
|
* |
76
|
|
|
* @param string $key |
77
|
|
|
* |
78
|
|
|
* @return mixed |
79
|
|
|
*/ |
80
|
16 |
|
public function getParam($key) |
81
|
|
|
{ |
82
|
16 |
|
return $this->params[$key]; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Sets a query parameter. |
87
|
|
|
* |
88
|
|
|
* @param string $key |
89
|
|
|
* @param mixed $value |
90
|
|
|
*/ |
91
|
76 |
|
public function setParam($key, $value) |
92
|
|
|
{ |
93
|
76 |
|
$this->params[$key] = $value; |
94
|
76 |
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Merges new query parameters. |
98
|
|
|
* |
99
|
|
|
* @param array $params |
100
|
|
|
* |
101
|
|
|
* @return array |
102
|
|
|
*/ |
103
|
108 |
|
public function setParams(array $params) |
104
|
|
|
{ |
105
|
108 |
|
$this->params = $params; |
106
|
108 |
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Merges new query parameters. |
110
|
|
|
* |
111
|
|
|
* @param array $params |
112
|
|
|
* |
113
|
|
|
* @return array |
114
|
|
|
*/ |
115
|
108 |
|
public function addParams(array $params) |
116
|
|
|
{ |
117
|
108 |
|
$this->params = array_merge($this->params, $params); |
118
|
108 |
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @var Logger |
122
|
|
|
*/ |
123
|
|
|
protected $error_handler = null; |
124
|
|
|
|
125
|
4 |
|
public function setErrorHandler(LoggerInterface $logger) |
126
|
|
|
{ |
127
|
4 |
|
$this->error_handler = $logger; |
|
|
|
|
128
|
4 |
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Returns the. |
132
|
|
|
*/ |
133
|
8 |
|
public function getErrorHandler() |
134
|
|
|
{ |
135
|
8 |
|
$this->error_handler = $this->error_handler ?: new Logger\ErrorLog('/dev/stdout'); |
|
|
|
|
136
|
|
|
|
137
|
8 |
|
return $this->error_handler; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Handle error. |
142
|
|
|
* |
143
|
|
|
* @param string $code |
144
|
|
|
* @param string $msg |
145
|
|
|
*/ |
146
|
4 |
|
public function handleError($code, $msg) |
147
|
|
|
{ |
148
|
4 |
|
$logger = $this->getErrorHandler(); |
149
|
4 |
|
$logger->error( |
150
|
4 |
|
'{0} - {1} - Code #{2}', |
151
|
4 |
|
array(get_class($this), $msg, $code) |
152
|
3 |
|
); |
153
|
4 |
|
} |
154
|
|
|
} |
155
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..