Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Move class from file logic in Console Kernel to dedicated method #47665

Merged
merged 2 commits into from
Jul 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/Illuminate/Foundation/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Illuminate\Support\InteractsWithTime;
use Illuminate\Support\Str;
use ReflectionClass;
use SplFileInfo;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleCommandEvent;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
Expand Down Expand Up @@ -339,12 +340,8 @@ protected function load($paths)

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

foreach ((new Finder)->in($paths)->files() as $command) {
$command = $namespace.str_replace(
['/', '.php'],
['\\', ''],
Str::after($command->getRealPath(), realpath(app_path()).DIRECTORY_SEPARATOR)
);
foreach ((new Finder)->in($paths)->files() as $file) {
$command = $this->commandClassFromFile($file, $namespace);

if (is_subclass_of($command, Command::class) &&
! (new ReflectionClass($command))->isAbstract()) {
Expand All @@ -355,6 +352,22 @@ 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
{
return $namespace.str_replace(
['/', '.php'],
['\\', ''],
Str::after($file->getRealPath(), realpath(app_path()).DIRECTORY_SEPARATOR)
);
}

/**
* Register the given command with the console application.
*
Expand Down