laravel-zero /
framework
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | /** |
||
| 6 | * This file is part of Laravel Zero. |
||
| 7 | * |
||
| 8 | * (c) Nuno Maduro <[email protected]> |
||
| 9 | * |
||
| 10 | * For the full copyright and license information, please view the LICENSE |
||
| 11 | * file that was distributed with this source code. |
||
| 12 | */ |
||
| 13 | |||
| 14 | namespace LaravelZero\Framework\Bootstrap; |
||
| 15 | |||
| 16 | use function basename; |
||
| 17 | use Illuminate\Contracts\Foundation\Application as ApplicationContract; |
||
| 18 | use Illuminate\Foundation\Bootstrap\LoadConfiguration; |
||
|
0 ignored issues
–
show
|
|||
| 19 | use function ksort; |
||
| 20 | use Symfony\Component\Finder\Finder; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @internal |
||
| 24 | */ |
||
| 25 | final class BaseLoadConfiguration extends LoadConfiguration |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * Get all of the configuration files for the application. |
||
| 29 | */ |
||
| 30 | 39 | protected function getConfigurationFiles(ApplicationContract $app): array |
|
| 31 | { |
||
| 32 | 39 | $files = []; |
|
| 33 | |||
| 34 | 39 | $configPath = $app->configPath(); |
|
| 35 | |||
| 36 | 39 | $configFiles = Finder::create() |
|
| 37 | 39 | ->files() |
|
| 38 | 39 | ->name('*.php') |
|
| 39 | 39 | ->in($configPath); |
|
| 40 | |||
| 41 | 39 | foreach ($configFiles as $file) { |
|
| 42 | 39 | $directory = $this->getNestedDirectory($file, $configPath); |
|
| 43 | 39 | $files[$directory.basename($file->getPathname(), '.php')] = $file->getPathname(); |
|
| 44 | } |
||
| 45 | |||
| 46 | 39 | ksort($files, SORT_NATURAL); |
|
| 47 | |||
| 48 | 39 | return $files; |
|
| 49 | } |
||
| 50 | } |
||
| 51 |
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: