Initial commit

This commit is contained in:
2021-12-07 17:26:34 +01:00
commit 0c9fd2e892
15 changed files with 674 additions and 0 deletions

View File

@ -0,0 +1,57 @@
<?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;
}
}