1 | <?php |
||
23 | class Kernel extends BaseKernel |
||
24 | { |
||
25 | /** |
||
26 | * The application's development commands. |
||
27 | * |
||
28 | * @var string[] |
||
29 | */ |
||
30 | protected $developmentCommands = [ |
||
31 | Commands\App\Builder::class, |
||
32 | Commands\App\Renamer::class, |
||
33 | Commands\App\CommandMaker::class, |
||
34 | Commands\App\Installer::class, |
||
35 | ]; |
||
36 | |||
37 | /** |
||
38 | * The application's bootstrap classes. |
||
39 | * |
||
40 | * @var string[] |
||
41 | */ |
||
42 | protected $bootstrappers = [ |
||
43 | \LaravelZero\Framework\Bootstrap\CoreBindings::class, |
||
44 | \LaravelZero\Framework\Bootstrap\LoadEnvironmentVariables::class, |
||
45 | \LaravelZero\Framework\Bootstrap\LoadConfiguration::class, |
||
46 | \Illuminate\Foundation\Bootstrap\HandleExceptions::class, |
||
47 | \Illuminate\Foundation\Bootstrap\RegisterFacades::class, |
||
48 | \LaravelZero\Framework\Bootstrap\RegisterProviders::class, |
||
49 | \Illuminate\Foundation\Bootstrap\BootProviders::class, |
||
50 | ]; |
||
51 | |||
52 | /** |
||
53 | * Kernel constructor. |
||
54 | * |
||
55 | * @param \Illuminate\Contracts\Foundation\Application $app |
||
56 | * @param \Illuminate\Contracts\Events\Dispatcher $events |
||
57 | */ |
||
58 | 19 | public function __construct( |
|
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | public function handle($input, $output = null) |
||
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | 19 | public function bootstrap() |
|
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | 19 | protected function commands(): void |
|
98 | { |
||
99 | 19 | $config = $this->app['config']; |
|
100 | |||
101 | /* |
||
102 | * Loads commands paths. |
||
103 | */ |
||
104 | 19 | $this->load($config->get('commands.paths', $this->app->path('Commands'))); |
|
105 | |||
106 | /** |
||
107 | * Loads configurated commands. |
||
108 | */ |
||
109 | 19 | $commands = collect($config->get('commands.add', [])) |
|
110 | 19 | ->merge($config->get('commands.hidden', [])); |
|
111 | |||
112 | 19 | if ($command = $config->get('commands.default')) { |
|
113 | 19 | $commands->push($config->get('commands.default')); |
|
114 | } |
||
115 | |||
116 | /* |
||
117 | * Loads development commands. |
||
118 | */ |
||
119 | 19 | if ($this->app->environment() !== 'production') { |
|
120 | 19 | $commands = $commands->merge($this->developmentCommands); |
|
121 | } |
||
122 | |||
123 | 19 | $commands = $commands->diff($toRemoveCommands = $config->get('commands.remove', [])); |
|
124 | |||
125 | Artisan::starting(function ($artisan) use ($toRemoveCommands) { |
||
126 | 19 | $reflectionClass = new ReflectionClass(Artisan::class); |
|
127 | 19 | $commands = collect($artisan->all()) |
|
128 | 19 | ->filter( |
|
129 | function ($command) use ($toRemoveCommands) { |
||
130 | 19 | return ! in_array(get_class($command), $toRemoveCommands); |
|
131 | 19 | } |
|
132 | ) |
||
133 | 19 | ->toArray(); |
|
134 | |||
135 | 19 | $property = $reflectionClass->getParentClass() |
|
136 | 19 | ->getProperty('commands'); |
|
137 | |||
138 | 19 | $property->setAccessible(true); |
|
139 | 19 | $property->setValue($artisan, $commands); |
|
140 | 19 | $property->setAccessible(false); |
|
141 | 19 | }); |
|
142 | |||
143 | /* |
||
144 | * Registers a bootstrap callback on the artisan console application |
||
145 | * in order to call the schedule method on each Laravel Zero |
||
146 | * command class. |
||
147 | */ |
||
148 | Artisan::starting(function ($artisan) use ($commands) { |
||
149 | 19 | $artisan->resolveCommands($commands->toArray()); |
|
150 | 19 | }); |
|
151 | |||
152 | Artisan::starting(function ($artisan) use ($config) { |
||
153 | collect($artisan->all())->each(function ($command) use ($config) { |
||
154 | 19 | if (in_array(get_class($command), $config->get('commands.hidden', []))) { |
|
155 | 19 | $command->setHidden(true); |
|
156 | } |
||
157 | |||
158 | 19 | if ($command instanceof Commands\Command) { |
|
159 | 19 | $this->app->call([$command, 'schedule']); |
|
160 | } |
||
161 | 19 | } |
|
162 | ); |
||
163 | 19 | }); |
|
164 | 19 | } |
|
165 | |||
166 | /** |
||
167 | * Gets the application name. |
||
168 | * |
||
169 | * @return string |
||
170 | */ |
||
171 | 1 | public function getName(): string |
|
176 | } |
||
177 |
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: