1 | <?php |
||
17 | class ServiceProvider extends BaseServiceProvider |
||
18 | { |
||
19 | protected $defer = false; |
||
20 | |||
21 | /** |
||
22 | * @inheritdoc |
||
23 | */ |
||
24 | public function boot() |
||
35 | |||
36 | /** |
||
37 | * @inheritdoc |
||
38 | */ |
||
39 | public function register() |
||
55 | |||
56 | /** |
||
57 | * Define the services this provider will build & provide |
||
58 | * |
||
59 | * @return string[] |
||
60 | */ |
||
61 | public function provides() |
||
68 | |||
69 | /** |
||
70 | * Retrieve the storage engine, based on the current configuration |
||
71 | * |
||
72 | * @param Config $config |
||
73 | * @return StorageInterface |
||
74 | */ |
||
75 | protected function selectStorage($config) |
||
84 | |||
85 | /** |
||
86 | * Get an instance of the PDO storage engine |
||
87 | * |
||
88 | * @param Config $config |
||
89 | * @return Pdo |
||
90 | */ |
||
91 | protected function selectStoragePdo($config) |
||
98 | |||
99 | /** |
||
100 | * Get an instance of the Redis storage engine |
||
101 | * |
||
102 | * @param Config $config |
||
103 | * @return Redis |
||
104 | */ |
||
105 | protected function selectStorageRedis($config) |
||
110 | |||
111 | /** |
||
112 | * Get an instance of a custom defined storage engine |
||
113 | * |
||
114 | * @param Config $config [description] |
||
115 | * @return StorageInterface |
||
116 | */ |
||
117 | protected function selectStorageCustom($config) |
||
122 | |||
123 | /** |
||
124 | * Get an instance of the File storage engine |
||
125 | * |
||
126 | * @param Config $config |
||
127 | * @return File |
||
128 | */ |
||
129 | protected function selectStorageFile($config) |
||
134 | } |
||
135 |
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: