57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace Spark\Commands;
|
|
|
|
use Spark\SparkApplication;
|
|
use Symfony\Component\Console\Attribute\AsCommand;
|
|
use Symfony\Component\Console\Helper\Table;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
#[AsCommand(name:'resources', description:'List defined resources')]
|
|
class ResourcesCommand extends Command
|
|
{
|
|
protected function configure()
|
|
{
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
$env = $this->getEnvironment();
|
|
$app = $this->getApplication();
|
|
|
|
/** @var SparkApplication $app */
|
|
$resources = $app->getResourceManager();
|
|
|
|
$types = $resources->getAllResourceTypes();
|
|
$named = $resources->getAllNamedResources();
|
|
|
|
$output->writeln("<options=bold>Resource Types:</>");
|
|
$table = new Table($output);
|
|
$table->setStyle("compact");
|
|
$table->setHeaders([ "Type", "Class" ]);
|
|
$table->setColumnWidth(0, 10);
|
|
$map = [];
|
|
foreach ($types as $type=>$class) {
|
|
$map[$class] = $type;
|
|
$table->addRow([ $type, $class ]);
|
|
}
|
|
$table->render();
|
|
|
|
$output->writeln("");
|
|
|
|
$output->writeln("<options=bold>Named Resources:</>");
|
|
$table = new Table($output);
|
|
$table->setStyle("compact");
|
|
$table->setHeaders([ "Name", "Type", "Info" ]);
|
|
$table->setColumnWidth(0, 10);
|
|
$table->setColumnWidth(1, 6);
|
|
foreach ($named as $name=>$class) {
|
|
$table->addRow([ $name, $map[get_class($class)], $class->info() ]);
|
|
}
|
|
$table->render();
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
} |