20
20
use Illuminate \Support \InteractsWithTime ;
21
21
use Illuminate \Support \Str ;
22
22
use ReflectionClass ;
23
+ use SplFileInfo ;
23
24
use Symfony \Component \Console \ConsoleEvents ;
24
25
use Symfony \Component \Console \Event \ConsoleCommandEvent ;
25
26
use Symfony \Component \Console \Event \ConsoleTerminateEvent ;
@@ -339,12 +340,8 @@ protected function load($paths)
339
340
340
341
$ namespace = $ this ->app ->getNamespace ();
341
342
342
- foreach ((new Finder )->in ($ paths )->files () as $ command ) {
343
- $ command = $ namespace .str_replace (
344
- ['/ ' , '.php ' ],
345
- ['\\' , '' ],
346
- Str::after ($ command ->getRealPath (), realpath (app_path ()).DIRECTORY_SEPARATOR )
347
- );
343
+ foreach ((new Finder )->in ($ paths )->files () as $ file ) {
344
+ $ command = $ this ->commandClassFromFile ($ file , $ namespace );
348
345
349
346
if (is_subclass_of ($ command , Command::class) &&
350
347
! (new ReflectionClass ($ command ))->isAbstract ()) {
@@ -355,6 +352,22 @@ protected function load($paths)
355
352
}
356
353
}
357
354
355
+ /**
356
+ * Extract the command class name from the given file path.
357
+ *
358
+ * @param \SplFileInfo $file
359
+ * @param string $namespace
360
+ * @return string
361
+ */
362
+ protected function commandClassFromFile (SplFileInfo $ file , string $ namespace ): string
363
+ {
364
+ return $ namespace .str_replace (
365
+ ['/ ' , '.php ' ],
366
+ ['\\' , '' ],
367
+ Str::after ($ file ->getRealPath (), realpath (app_path ()).DIRECTORY_SEPARATOR )
368
+ );
369
+ }
370
+
358
371
/**
359
372
* Register the given command with the console application.
360
373
*
0 commit comments