1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Oro\Bundle\ActionBundle\Command; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\Common\Util\Debug; |
7
|
|
|
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
11
|
|
|
use Symfony\Component\Console\Input\InputOption; |
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
13
|
|
|
|
14
|
|
|
use Oro\Bundle\ActionBundle\Configuration\ConfigurationProvider; |
15
|
|
|
use Oro\Bundle\ActionBundle\Model\ActionGroupRegistry; |
16
|
|
|
use Oro\Bundle\ActionBundle\Model\OperationRegistry; |
17
|
|
|
|
18
|
|
|
class DumpActionConfigurationCommand extends ContainerAwareCommand |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* {@inheritdoc} |
22
|
|
|
*/ |
23
|
|
|
protected function configure() |
24
|
|
|
{ |
25
|
|
|
$this->setName('oro:action:configuration:dump') |
26
|
|
|
->setDescription('Dump action configuration') |
27
|
|
|
->addArgument('name', InputArgument::OPTIONAL, 'Names of the name of node that should be dumped') |
28
|
|
|
->addOption('action-group', null, InputOption::VALUE_NONE, 'Dump action_group') |
29
|
|
|
->addOption('assemble', null, InputOption::VALUE_NONE, 'Assemble configuration'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
36
|
|
|
{ |
37
|
|
|
$errors = new ArrayCollection(); |
38
|
|
|
|
39
|
|
|
if ($input->getOption('action-group')) { |
40
|
|
|
$output->writeln('Load action_groups ...'); |
41
|
|
|
$provider = $this->getActionGroupsProvider(); |
42
|
|
|
} else { |
43
|
|
|
$output->writeln('Load operations ...'); |
44
|
|
|
$provider = $this->getOperationsProvider(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$configuration = $provider->getConfiguration(true, $errors); |
48
|
|
|
|
49
|
|
|
if ($input->getOption('assemble')) { |
50
|
|
|
if ($input->getOption('action-group')) { |
51
|
|
|
$registry = $this->getActionGroupRegistry(); |
52
|
|
|
} else { |
53
|
|
|
$registry = $this->getOperationRegistry(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
foreach ($configuration as $name => &$value) { |
57
|
|
|
$value = $registry->findByName($name)->getDefinition(); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
if ($configuration) { |
|
|
|
|
62
|
|
|
$name = $input->getArgument('name'); |
63
|
|
|
|
64
|
|
|
if ($name && isset($configuration[$name])) { |
65
|
|
|
$output->writeln($name); |
66
|
|
|
Debug::dump($configuration[$name], 100); |
67
|
|
|
} else { |
68
|
|
|
foreach (array_keys($configuration) as $key) { |
69
|
|
|
$output->writeln($key); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
} else { |
73
|
|
|
$output->writeln('No actions found.'); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return ConfigurationProvider |
79
|
|
|
*/ |
80
|
|
|
protected function getOperationsProvider() |
81
|
|
|
{ |
82
|
|
|
return $this->getContainer()->get('oro_action.configuration.provider.operations'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return ConfigurationProvider |
87
|
|
|
*/ |
88
|
|
|
protected function getActionGroupsProvider() |
89
|
|
|
{ |
90
|
|
|
return $this->getContainer()->get('oro_action.configuration.provider.action_groups'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return ActionGroupRegistry |
95
|
|
|
*/ |
96
|
|
|
public function getActionGroupRegistry() |
97
|
|
|
{ |
98
|
|
|
return $this->getContainer()->get('oro_action.action_group_registry'); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return OperationRegistry |
103
|
|
|
*/ |
104
|
|
|
public function getOperationRegistry() |
105
|
|
|
{ |
106
|
|
|
return $this->getContainer()->get('oro_action.operation_registry'); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.