From 2b174d50daf0598e8ea04586e1e0e97e4b9880eb Mon Sep 17 00:00:00 2001 From: CalebW Date: Fri, 2 Jun 2023 16:21:37 -0500 Subject: [PATCH] [10.x] Update Kernel::load() to use same `classFromFile` logic as events (#47327) * Update Kernel::load() to use same `classFromFile` logic as events * formatting --------- Co-authored-by: Taylor Otwell --- src/Illuminate/Foundation/Console/Kernel.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Foundation/Console/Kernel.php b/src/Illuminate/Foundation/Console/Kernel.php index 334b3a401b43..da77b1ab22e3 100644 --- a/src/Illuminate/Foundation/Console/Kernel.php +++ b/src/Illuminate/Foundation/Console/Kernel.php @@ -332,12 +332,15 @@ protected function load($paths) } $namespace = $this->app->getNamespace(); + $basePath = $this->app->basePath(); - 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) { + $class = trim(Str::replaceFirst($basePath, '', $file->getRealPath()), DIRECTORY_SEPARATOR); + + $command = str_replace( + [DIRECTORY_SEPARATOR, ucfirst(basename($this->app->path())).'\\'], + ['\\', $namespace], + ucfirst(Str::replaceLast('.php', '', $class)), ); if (is_subclass_of($command, Command::class) &&