|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Sylius\Bundle\UiBundle\Command; |
|
15
|
|
|
|
|
16
|
|
|
use Sylius\Bundle\UiBundle\Registry\TemplateBlock; |
|
17
|
|
|
use Sylius\Bundle\UiBundle\Registry\TemplateBlockRegistryInterface; |
|
18
|
|
|
use Symfony\Component\Console\Command\Command; |
|
19
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
20
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
22
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
23
|
|
|
|
|
24
|
|
|
final class DebugTemplateEventCommand extends Command |
|
25
|
|
|
{ |
|
26
|
|
|
protected static $defaultName = 'sylius:debug:template-event'; |
|
27
|
|
|
|
|
28
|
|
|
/** @var TemplateBlockRegistryInterface */ |
|
29
|
|
|
private $templateBlockRegistry; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct(TemplateBlockRegistryInterface $templateBlockRegistry) |
|
32
|
|
|
{ |
|
33
|
|
|
parent::__construct(); |
|
34
|
|
|
|
|
35
|
|
|
$this->templateBlockRegistry = $templateBlockRegistry; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
protected function configure(): void |
|
39
|
|
|
{ |
|
40
|
|
|
$this |
|
41
|
|
|
->setDescription('Debug template events and associated blocks') |
|
42
|
|
|
->addArgument('event', InputArgument::OPTIONAL, 'Template event name', null) |
|
43
|
|
|
; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
47
|
|
|
{ |
|
48
|
|
|
$io = new SymfonyStyle($input, $output); |
|
49
|
|
|
$eventName = $input->getArgument('event'); |
|
50
|
|
|
|
|
51
|
|
|
if ($eventName === null) { |
|
52
|
|
|
$io->title('List of template events'); |
|
53
|
|
|
|
|
54
|
|
|
$io->listing(array_keys($this->templateBlockRegistry->all())); |
|
55
|
|
|
|
|
56
|
|
|
return 0; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$io->title(sprintf('Blocks registered for the template event "%s"', $eventName)); |
|
60
|
|
|
|
|
61
|
|
|
$io->table( |
|
62
|
|
|
['Block name', 'Template', 'Priority', 'Enabled'], |
|
63
|
|
|
array_map( |
|
64
|
|
|
static function (TemplateBlock $templateBlock): array { |
|
65
|
|
|
return [ |
|
66
|
|
|
$templateBlock->getName(), |
|
67
|
|
|
$templateBlock->getTemplate(), |
|
68
|
|
|
$templateBlock->getPriority(), |
|
69
|
|
|
$templateBlock->isEnabled() ? 'TRUE' : 'FALSE', |
|
70
|
|
|
]; |
|
71
|
|
|
}, |
|
72
|
|
|
$this->templateBlockRegistry->all()[$eventName] ?? [] |
|
73
|
|
|
) |
|
74
|
|
|
); |
|
75
|
|
|
|
|
76
|
|
|
return 0; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|