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 | * {@inheritDoc} |
||
98 | */ |
||
99 | public function getDefaultAdapter(): array |
||
103 | |||
104 | |||
105 | /** |
||
106 | * {@inheritDoc} |
||
107 | */ |
||
108 | public function hasAdapter(string $name): bool |
||
112 | |||
113 | |||
114 | /** |
||
115 | * {@inheritDoc} |
||
116 | */ |
||
117 | public function injectAdapter($adapter, ?string $name=null) : AdapterAwareInterface |
||
134 | |||
135 | |||
136 | /** |
||
137 | * {@inheritDoc} |
||
138 | */ |
||
139 | public function getAdapter(string $name) |
||
147 | |||
148 | |||
149 | /** |
||
150 | * Get adapters |
||
151 | * |
||
152 | * @param array $adapters |
||
153 | * @return array |
||
154 | */ |
||
155 | public function getAdapters(array $adapters = []): array |
||
171 | |||
172 | |||
173 | /** |
||
174 | * Log message |
||
175 | * |
||
176 | * @param string $level |
||
177 | * @param string $message |
||
178 | * @param array $context |
||
179 | * @return bool |
||
180 | */ |
||
181 | public function log($level, $message, array $context = []): bool |
||
198 | |||
199 | |||
200 | /** |
||
201 | * Add static context |
||
202 | * |
||
203 | * @param string $name |
||
204 | * @param string $value |
||
205 | * @return Log |
||
206 | */ |
||
207 | public function addContext(string $name, string $value): Log |
||
212 | |||
213 | |||
214 | /** |
||
215 | * Log message |
||
216 | * |
||
217 | * @param string $message |
||
218 | * @param string $format |
||
219 | * @param string $date_format |
||
220 | * @param string $level |
||
221 | * @param array $context |
||
222 | * @return string |
||
223 | */ |
||
224 | protected function _format(string $message, string $format, string $date_format, string $level, array $context = []): string |
||
275 | } |
||
276 |
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: