diff --git a/app/Providers/Blueprint/ExtensionCommandServiceProvider.php b/app/Providers/Blueprint/ExtensionCommandServiceProvider.php new file mode 100644 index 0000000..808de51 --- /dev/null +++ b/app/Providers/Blueprint/ExtensionCommandServiceProvider.php @@ -0,0 +1,65 @@ +app->booted(function () { + $this->loadCommandsFrom(base_path('app/Console/Commands/BlueprintFramework/Extensions')); + }); + } + + /** + * Load commands from the given directory. + * + * @param string $directory + */ + protected function loadCommandsFrom($directory) + { + $namespace = 'App\\Console\\Commands\\BlueprintFramework\\Extensions'; + + // Iterate through the directory to find command files + $iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($directory), + RecursiveIteratorIterator::LEAVES_ONLY + ); + + foreach ($iterator as $file) { + if ($file->isFile() && $file->getExtension() === 'php') { + // Get the relative path + $relativePath = str_replace([$directory . DIRECTORY_SEPARATOR, '.php'], '', $file->getPathname()); + + // Convert file path to class name + $className = $namespace . '\\' . str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath); + + // Use Reflection to check if the class exists and is a command + if (class_exists($className)) { + $reflection = new ReflectionClass($className); + if ($reflection->isSubclassOf('Illuminate\Console\Command') && !$reflection->isAbstract()) { + // Extract prefix from the parent folder + $prefix = $file->getPathInfo()->getPathInfo()->getFilename(); + + // Register the command with the prefix + Artisan::starting(function ($artisan) use ($className, $prefix) { + $command = $artisan->resolve($className); + $command->setName($prefix . ':' . $command->getName()); + $artisan->add($command); + }); + } + } + } + } + } +} diff --git a/config/app.php b/config/app.php index 9493ae9..9aa46a9 100644 --- a/config/app.php +++ b/config/app.php @@ -207,6 +207,7 @@ * Blueprint Service Providers */ Pterodactyl\Providers\Blueprint\RouteServiceProvider::class, + Pterodactyl\Providers\Blueprint\ExtensionCommandServiceProvider::class, /* * Additional Dependencies