| 1 | <?php |
||
| 17 | class ServiceProvider extends ServiceProvider |
||
| 18 | { |
||
| 19 | protected $defer = false; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Boot the configuration component |
||
| 23 | * |
||
| 24 | * @return nil |
||
| 25 | */ |
||
| 26 | public function boot() |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Register an instance of the component |
||
| 40 | * |
||
| 41 | * @return void |
||
| 42 | */ |
||
| 43 | public function register() |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Define the services this provider will build & provide |
||
| 52 | * |
||
| 53 | * @return array |
||
| 54 | */ |
||
| 55 | public function provides() |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Get the configuration destination path |
||
| 65 | * |
||
| 66 | * @return string |
||
| 67 | */ |
||
| 68 | protected function getConfigPath() |
||
| 72 | } |
||
| 73 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes 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: