1 | <?php |
||
23 | class Log extends AbstractLogger implements LoggerInterface, AdapterAwareInterface |
||
24 | { |
||
25 | /** |
||
26 | * Priorities |
||
27 | */ |
||
28 | const PRIORITIES = [ |
||
29 | LogLevel::EMERGENCY => 0, |
||
30 | LogLevel::ALERT => 1, |
||
31 | LogLevel::CRITICAL => 2, |
||
32 | LogLevel::ERROR => 3, |
||
33 | LogLevel::WARNING => 4, |
||
34 | LogLevel::NOTICE => 5, |
||
35 | LogLevel::INFO => 6, |
||
36 | LogLevel::DEBUG => 7, |
||
37 | ]; |
||
38 | |||
39 | |||
40 | /** |
||
41 | * Adapters |
||
42 | * |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $adapter = []; |
||
46 | |||
47 | |||
48 | /** |
||
49 | * static context |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $context = []; |
||
54 | |||
55 | |||
56 | /** |
||
57 | * Initialize logger |
||
58 | * |
||
59 | * @param Iterable $config |
||
60 | * @return void |
||
61 | */ |
||
62 | public function __construct(? Iterable $config = null) |
||
66 | |||
67 | |||
68 | /** |
||
69 | * Set options |
||
70 | * |
||
71 | * @param Iterable $config |
||
72 | * @return Log |
||
73 | */ |
||
74 | public function setOptions(? Iterable $config = null): Log |
||
94 | |||
95 | |||
96 | /** |
||
97 | * Get default adapter |
||
98 | * |
||
99 | * @return array |
||
100 | */ |
||
101 | public function getDefaultAdapter(): array |
||
105 | |||
106 | |||
107 | /** |
||
108 | * Has adapter |
||
109 | * |
||
110 | * @param string $name |
||
111 | * @return bool |
||
112 | */ |
||
113 | public function hasAdapter(string $name): bool |
||
117 | |||
118 | |||
119 | /** |
||
120 | * Add adapter |
||
121 | * |
||
122 | * @param string $name |
||
123 | * @param string $class |
||
124 | * @param Iterable $config |
||
125 | * @return AdapterInterface |
||
126 | */ |
||
127 | public function addAdapter(string $name, string $class, ? Iterable $config = null) : AdapterInterface |
||
140 | |||
141 | |||
142 | /** |
||
143 | * Inject adapter |
||
144 | * |
||
145 | * @param string $name |
||
146 | * @param AdapterInterface $adapter |
||
147 | * @return AdapterInterface |
||
148 | */ |
||
149 | public function injectAdapter(string $name, AdapterInterface $adapter) : AdapterInterface |
||
158 | |||
159 | |||
160 | /** |
||
161 | * Get adapter |
||
162 | * |
||
163 | * @param string $name |
||
164 | * @return AdapterInterface |
||
165 | */ |
||
166 | public function getAdapter(string $name): AdapterInterface |
||
174 | |||
175 | |||
176 | /** |
||
177 | * Get adapters |
||
178 | * |
||
179 | * @param array $adapters |
||
180 | * @return array |
||
181 | */ |
||
182 | public function getAdapters(array $adapters = []): array |
||
198 | |||
199 | |||
200 | /** |
||
201 | * Log message |
||
202 | * |
||
203 | * @param string $level |
||
204 | * @param string $message |
||
205 | * @param array $context |
||
206 | * @return bool |
||
207 | */ |
||
208 | public function log($level, $message, array $context = []): bool |
||
225 | |||
226 | |||
227 | /** |
||
228 | * Add static context |
||
229 | * |
||
230 | * @param string $name |
||
231 | * @param string $value |
||
232 | * @return Log |
||
233 | */ |
||
234 | public function addContext(string $name, string $value): Log |
||
239 | |||
240 | |||
241 | /** |
||
242 | * Log message |
||
243 | * |
||
244 | * @param string $message |
||
245 | * @param string $format |
||
246 | * @param string $date_format |
||
247 | * @param string $level |
||
248 | * @param array $context |
||
249 | * @return string |
||
250 | */ |
||
251 | protected function _format(string $message, string $format, string $date_format, string $level, array $context = []): string |
||
302 | } |
||
303 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: