1 | <?php |
||
22 | class Log extends AbstractLogger implements LoggerInterface |
||
23 | { |
||
24 | /** |
||
25 | * Priorities |
||
26 | */ |
||
27 | const PRIORITIES = [ |
||
28 | LogLevel::EMERGENCY => 0, |
||
29 | LogLevel::ALERT => 1, |
||
30 | LogLevel::CRITICAL => 2, |
||
31 | LogLevel::ERROR => 3, |
||
32 | LogLevel::WARNING => 4, |
||
33 | LogLevel::NOTICE => 5, |
||
34 | LogLevel::INFO => 6, |
||
35 | LogLevel::DEBUG => 7, |
||
36 | ]; |
||
37 | |||
38 | |||
39 | /** |
||
40 | * Adapters |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $adapter = []; |
||
45 | |||
46 | |||
47 | /** |
||
48 | * static context |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $context = []; |
||
53 | |||
54 | |||
55 | /** |
||
56 | * Initialize logger |
||
57 | * |
||
58 | * @param Iterable $config |
||
59 | * @return void |
||
60 | */ |
||
61 | public function __construct(? Iterable $config = null) |
||
65 | |||
66 | |||
67 | /** |
||
68 | * Set options |
||
69 | * |
||
70 | * @param Iterable $config |
||
71 | * @return Log |
||
72 | */ |
||
73 | public function setOptions(? Iterable $config = null): Log |
||
97 | |||
98 | |||
99 | /** |
||
100 | * Has adapter |
||
101 | * |
||
102 | * @param string $name |
||
103 | * @return bool |
||
104 | */ |
||
105 | public function hasAdapter(string $name): bool |
||
109 | |||
110 | |||
111 | /** |
||
112 | * Add adapter |
||
113 | * |
||
114 | * @param string $name |
||
115 | * @param string $class |
||
116 | * @param Iterable $config |
||
117 | * @return AdapterInterface |
||
118 | */ |
||
119 | public function addAdapter(string $name, string $class, ? Iterable $config = null) : AdapterInterface |
||
132 | |||
133 | |||
134 | /** |
||
135 | * Get adapter |
||
136 | * |
||
137 | * @param string $name |
||
138 | * @return AdapterInterface |
||
139 | */ |
||
140 | public function getAdapter(string $name): AdapterInterface |
||
148 | |||
149 | |||
150 | /** |
||
151 | * Get adapters |
||
152 | * |
||
153 | * @param array $adapters |
||
154 | * @return array |
||
155 | */ |
||
156 | public function getAdapters(array $adapters = []): array |
||
172 | |||
173 | |||
174 | /** |
||
175 | * Log message |
||
176 | * |
||
177 | * @param string $level |
||
178 | * @param string $message |
||
179 | * @param array $context |
||
180 | * @return bool |
||
181 | */ |
||
182 | public function log($level, $message, array $context = []): bool |
||
199 | |||
200 | |||
201 | /** |
||
202 | * Add static context |
||
203 | * |
||
204 | * @param string $name |
||
205 | * @param string $value |
||
206 | * @return Log |
||
207 | */ |
||
208 | public function addContext(string $name, string $value): Log |
||
213 | |||
214 | |||
215 | /** |
||
216 | * Log message |
||
217 | * |
||
218 | * @param string $message |
||
219 | * @param string $format |
||
220 | * @param string $date_format |
||
221 | * @param string $level |
||
222 | * @param array $context |
||
223 | * @return string |
||
224 | */ |
||
225 | protected function _format(string $message, string $format, string $date_format, string $level, array $context = []): string |
||
276 | } |
||
277 |
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: