Skip to content

Commit

Permalink
Allow load command from any namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
feng-yifan committed Sep 20, 2024
1 parent 4c78508 commit 73a0192
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/Illuminate/Foundation/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,8 @@ protected function load($paths)
array_unique(array_merge($this->loadedPaths, $paths))
);

$namespace = $this->app->getNamespace();

foreach (Finder::create()->in($paths)->files() as $file) {
$command = $this->commandClassFromFile($file, $namespace);
$command = $this->commandClassFromFile($file);

if (is_subclass_of($command, Command::class) &&
! (new ReflectionClass($command))->isAbstract()) {
Expand All @@ -382,15 +380,16 @@ protected function load($paths)
* Extract the command class name from the given file path.
*
* @param \SplFileInfo $file
* @param string $namespace
* @return string
*/
protected function commandClassFromFile(SplFileInfo $file, string $namespace): string
protected function commandClassFromFile(SplFileInfo $file): string
{
return $namespace.str_replace(
['/', '.php'],
['\\', ''],
Str::after($file->getRealPath(), realpath(app_path()).DIRECTORY_SEPARATOR)
return implode(
"\\",
array_map(
'ucfirst',
explode(DIRECTORY_SEPARATOR, substr($file->getRealPath(), strlen($this->app->basePath()) + 1, -4)),
),
);
}

Expand Down

0 comments on commit 73a0192

Please sign in to comment.