1 | <?php |
||
20 | class Auth |
||
21 | { |
||
22 | /** |
||
23 | * Adapter |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $adapter = []; |
||
28 | |||
29 | |||
30 | /** |
||
31 | * Identity |
||
32 | * |
||
33 | * @var Identity |
||
34 | */ |
||
35 | protected $identity; |
||
36 | |||
37 | |||
38 | /** |
||
39 | * Logger |
||
40 | * |
||
41 | * @var Logger |
||
42 | */ |
||
43 | protected $logger; |
||
44 | |||
45 | |||
46 | /** |
||
47 | * Identity class |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $identity_class = Identity::class; |
||
52 | |||
53 | |||
54 | /** |
||
55 | * Attribute map class |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $attribute_map_class = AttributeMap::class; |
||
60 | |||
61 | |||
62 | /** |
||
63 | * Initialize |
||
64 | * |
||
65 | * @param Iterable $config |
||
66 | * @param Logger $logger |
||
67 | * @return void |
||
68 | */ |
||
69 | public function __construct(? Iterable $config = null, Logger $logger) |
||
74 | |||
75 | |||
76 | /** |
||
77 | * Set options |
||
78 | * |
||
79 | * @param Iterable $config |
||
80 | * @return Auth |
||
81 | */ |
||
82 | public function setOptions(? Iterable $config = null) : Auth |
||
120 | |||
121 | |||
122 | /** |
||
123 | * Has adapter |
||
124 | * |
||
125 | * @param string $name |
||
126 | * @return bool |
||
127 | */ |
||
128 | public function hasAdapter(string $name): bool |
||
132 | |||
133 | |||
134 | /** |
||
135 | * Add adapter |
||
136 | * |
||
137 | * @param string $name |
||
138 | * @param string $class |
||
139 | * @param Iterable $config |
||
140 | * @return AdapterInterface |
||
141 | */ |
||
142 | public function addAdapter(string $name, string $class, ? Iterable $config = null) : AdapterInterface |
||
155 | |||
156 | |||
157 | /** |
||
158 | * Inject adapter |
||
159 | * |
||
160 | * @param string $name |
||
161 | * @param AdapterInterface $adapter |
||
162 | * @return AdapterInterface |
||
163 | */ |
||
164 | public function injectAdapter(string $name, AdapterInterface $adapter) : AdapterInterface |
||
173 | |||
174 | |||
175 | /** |
||
176 | * Get adapter |
||
177 | * |
||
178 | * @param string $name |
||
179 | * @return AdapterInterface |
||
180 | */ |
||
181 | public function getAdapter(string $name): AdapterInterface |
||
189 | |||
190 | |||
191 | /** |
||
192 | * Get adapters |
||
193 | * |
||
194 | * @param array $adapters |
||
195 | * @return array |
||
196 | */ |
||
197 | public function getAdapters(array $adapters = []): array |
||
213 | |||
214 | |||
215 | /** |
||
216 | * Create identity |
||
217 | * |
||
218 | * @param AdapterInterface $adapter |
||
219 | * @return Identity |
||
220 | */ |
||
221 | protected function createIdentity(AdapterInterface $adapter): Identity |
||
227 | |||
228 | |||
229 | /** |
||
230 | * Authenticate |
||
231 | * |
||
232 | * @return bool |
||
233 | */ |
||
234 | public function requireOne(): bool |
||
268 | |||
269 | |||
270 | /** |
||
271 | * Get identity |
||
272 | * |
||
273 | * @return Identity |
||
274 | */ |
||
275 | public function getIdentity(): Identity |
||
283 | |||
284 | |||
285 | /** |
||
286 | * Check if valid identity exists |
||
287 | * |
||
288 | * @return bool |
||
289 | */ |
||
290 | public function isAuthenticated(): bool |
||
294 | } |
||
295 |
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: