mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 09:02:12 +00:00
Add a command to debug template events
This commit is contained in:
parent
c815e4c506
commit
4b969d3fcd
2 changed files with 83 additions and 0 deletions
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Bundle\UiBundle\Command;
|
||||
|
||||
use Sylius\Bundle\UiBundle\Registry\TemplateBlock;
|
||||
use Sylius\Bundle\UiBundle\Registry\TemplateBlockRegistryInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
final class DebugTemplateEventCommand extends Command
|
||||
{
|
||||
protected static $defaultName = 'sylius:debug:template-event';
|
||||
|
||||
/** @var TemplateBlockRegistryInterface */
|
||||
private $templateBlockRegistry;
|
||||
|
||||
public function __construct(TemplateBlockRegistryInterface $templateBlockRegistry)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->templateBlockRegistry = $templateBlockRegistry;
|
||||
}
|
||||
|
||||
protected function configure(): void
|
||||
{
|
||||
$this
|
||||
->setDescription('Debug template events and associated blocks')
|
||||
->addArgument('event', InputArgument::OPTIONAL, 'Template event name', null)
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
$eventName = $input->getArgument('event');
|
||||
|
||||
if ($eventName === null) {
|
||||
$io->title('List of template events');
|
||||
|
||||
$io->listing(array_keys($this->templateBlockRegistry->all()));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$io->title(sprintf('Blocks registered for the template event "%s"', $eventName));
|
||||
|
||||
$io->table(
|
||||
['Block name', 'Template', 'Priority', 'Enabled'],
|
||||
array_map(
|
||||
static function (TemplateBlock $templateBlock): array {
|
||||
return [
|
||||
$templateBlock->getName(),
|
||||
$templateBlock->getTemplate(),
|
||||
$templateBlock->getPriority(),
|
||||
$templateBlock->isEnabled() ? 'TRUE' : 'FALSE',
|
||||
];
|
||||
},
|
||||
$this->templateBlockRegistry->all()[$eventName] ?? []
|
||||
)
|
||||
);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -26,5 +26,10 @@
|
|||
<argument type="service" id="Sylius\Bundle\UiBundle\Registry\TemplateBlockRegistryInterface" />
|
||||
<argument type="service" id="Sylius\Bundle\UiBundle\Renderer\TemplateBlockRendererInterface" />
|
||||
</service>
|
||||
|
||||
<service id="Sylius\Bundle\UiBundle\Command\DebugTemplateEventCommand">
|
||||
<argument type="service" id="Sylius\Bundle\UiBundle\Registry\TemplateBlockRegistryInterface" />
|
||||
<tag name="console.command" command="sylius:debug:template-event" />
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue