Skip to content

Commit

Permalink
add recursive to getFiles helper into Commands loading
Browse files Browse the repository at this point in the history
  • Loading branch information
MoamenEltouny authored Jun 20, 2024
1 parent 5f63028 commit e48b84d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Core/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
use Symfony\Component\Finder\SplFileInfo;

class ServiceProvider extends IlluminateServiceProvider
{
Expand Down Expand Up @@ -87,12 +88,20 @@ protected function registerCommands()

if ($this->app->runningInConsole()) {
if (file_exists($commands = module_path(static::$module, 'Commands'))) {
$module = 'App\Modules\\' . str_replace('/', '\\', static::$module) . '\Commands\\';
$commands = array_map(function ($command) use ($module) {
return $module . str_replace('.php', '', $command->getFileName());
}, getFiles($commands));
$commandsList = [];

$this->commands($commands);
foreach (getFiles($commands, true) as $file) {
$ns = str_replace([$commands, DIRECTORY_SEPARATOR], ['', '\\'], $file->getPath());
$module = 'App\Modules\\' . str_replace('/', '\\', static::$module) . '\Commands\\';

if (!empty($ns)) {
$module .= ltrim($ns, '\\') . '\\';
}

$commandsList[] = $module . str_replace('.php', '', $file->getFileName());
}

$this->commands($commandsList);
}

$console = module_path(static::$module, 'routes/console.php');
Expand Down

0 comments on commit e48b84d

Please sign in to comment.