feat ExtensionCommandService
: Add debug lines and attempt to handle symlinks correctly.
This commit is contained in:
parent
6730116228
commit
1afa732a6c
1 changed files with 27 additions and 9 deletions
|
@ -7,18 +7,27 @@ use Illuminate\Console\Application as Artisan;
|
|||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use ReflectionClass;
|
||||
use Log;
|
||||
|
||||
class ExtensionCommandServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register the service provider.
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
// Register the commands when the application is booted.
|
||||
$this->app->booted(function () {
|
||||
$this->loadCommandsFrom(base_path('app/Console/Commands/BlueprintFramework/Extensions'));
|
||||
});
|
||||
// This method is intentionally left blank
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
// Log the base path for debugging
|
||||
Log::info('Base path: ' . base_path());
|
||||
|
||||
$this->loadCommandsFrom(base_path('app/Console/Commands/BlueprintFramework/Extensions'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,18 +37,21 @@ class ExtensionCommandServiceProvider extends ServiceProvider
|
|||
*/
|
||||
protected function loadCommandsFrom($directory)
|
||||
{
|
||||
Log::info('Loading commands from: ' . $directory);
|
||||
|
||||
$namespace = 'Pterodactyl\\Console\\Commands\\BlueprintFramework\\Extensions';
|
||||
|
||||
// Iterate through the directory to find command files
|
||||
$iterator = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($directory),
|
||||
new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::FOLLOW_SYMLINKS),
|
||||
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());
|
||||
// Get the real path of the file
|
||||
$realPath = $file->getRealPath();
|
||||
$relativePath = str_replace([$directory . DIRECTORY_SEPARATOR, '.php'], '', $realPath);
|
||||
|
||||
// Convert file path to class name
|
||||
$className = $namespace . '\\' . str_replace(DIRECTORY_SEPARATOR, '\\', $relativePath);
|
||||
|
@ -49,7 +61,7 @@ class ExtensionCommandServiceProvider extends ServiceProvider
|
|||
$reflection = new ReflectionClass($className);
|
||||
if ($reflection->isSubclassOf('Illuminate\Console\Command') && !$reflection->isAbstract()) {
|
||||
// Extract prefix from the parent folder
|
||||
$prefix = $file->getPathInfo()->getPathInfo()->getFilename();
|
||||
$prefix = basename(dirname($file->getPath()));
|
||||
|
||||
// Register the command with the prefix
|
||||
Artisan::starting(function ($artisan) use ($className, $prefix) {
|
||||
|
@ -57,7 +69,13 @@ class ExtensionCommandServiceProvider extends ServiceProvider
|
|||
$command->setName('ext:' . $prefix . ':' . $command->getName());
|
||||
$artisan->add($command);
|
||||
});
|
||||
|
||||
Log::info("Registered command: {$prefix}:{$className}");
|
||||
} else {
|
||||
Log::warning("Class {$className} is not a valid command.");
|
||||
}
|
||||
} else {
|
||||
Log::warning("Class {$className} does not exist.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue