1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
namespace eZ\Bundle\EzPublishCoreBundle\Command; |
8
|
|
|
|
9
|
|
|
use eZ\Publish\Core\MVC\ConfigResolverInterface; |
10
|
|
|
use eZ\Publish\Core\MVC\Symfony\SiteAccess; |
11
|
|
|
use Symfony\Component\Console\Command\Command; |
12
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
14
|
|
|
use Symfony\Component\Console\Input\InputOption; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
use Symfony\Component\VarDumper\Cloner\VarCloner; |
17
|
|
|
use Symfony\Component\VarDumper\Dumper\CliDumper; |
18
|
|
|
|
19
|
|
|
class DebugConfigResolverCommand extends Command |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var \eZ\Publish\Core\MVC\ConfigResolverInterface |
23
|
|
|
*/ |
24
|
|
|
private $configResolver; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var \eZ\Publish\Core\MVC\Symfony\SiteAccess |
28
|
|
|
*/ |
29
|
|
|
private $siteAccess; |
30
|
|
|
|
31
|
|
|
public function __construct( |
32
|
|
|
ConfigResolverInterface $configResolver, |
33
|
|
|
SiteAccess $siteAccess |
34
|
|
|
) { |
35
|
|
|
$this->configResolver = $configResolver; |
36
|
|
|
$this->siteAccess = $siteAccess; |
37
|
|
|
|
38
|
|
|
parent::__construct(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc}. |
44
|
|
|
*/ |
45
|
|
|
public function configure() |
46
|
|
|
{ |
47
|
|
|
$this->setName('ezplatform:debug:config-resolver'); |
48
|
|
|
$this->setAliases(['ezplatform:debug:config']); |
49
|
|
|
$this->setDescription('Debug / Retrive parameter from Config Resolver'); |
50
|
|
|
$this->addArgument( |
51
|
|
|
'parameter', |
52
|
|
|
InputArgument::REQUIRED, |
53
|
|
|
'The configuration resolver parameter to return, for instance "languages" or "http_cache.purge_servers"' |
54
|
|
|
); |
55
|
|
|
$this->addOption( |
56
|
|
|
'json', |
57
|
|
|
null, |
58
|
|
|
InputOption::VALUE_NONE, |
59
|
|
|
'Only return value, for automation / testing use on a single line in json format.' |
60
|
|
|
); |
61
|
|
|
$this->addOption( |
62
|
|
|
'scope', |
63
|
|
|
null, |
64
|
|
|
InputOption::VALUE_REQUIRED, |
65
|
|
|
'Set another scope (siteaccess) to use, alternative to using the global --siteaccess[=SITEACCESS] option.' |
66
|
|
|
); |
67
|
|
|
$this->addOption( |
68
|
|
|
'namespace', |
69
|
|
|
null, |
70
|
|
|
InputOption::VALUE_REQUIRED, |
71
|
|
|
'Set another namespace than default "ezsettings" used by siteaccess settings.' |
72
|
|
|
); |
73
|
|
|
$this->setHelp(<<<EOM |
74
|
|
|
Outputs a given config resolver parameter, more commonly known as a SiteAccess setting. |
75
|
|
|
|
76
|
|
|
By default it will give value depending on global <comment>--siteaccess[=SITEACCESS]</comment> (default siteaccess is used if not set). |
77
|
|
|
|
78
|
|
|
However you can also manually set <comment>--scope[=NAME]</comment> yourself if you don't want to affect the siteaccess |
79
|
|
|
set by the system. You can also override namespace to get something else than default "ezsettings" namespace using |
80
|
|
|
<comment>--namespace[=NS]</comment> option. |
81
|
|
|
|
82
|
|
|
NOTE: To rather see *all* compiled siteaccess settings, use: <comment>debug:config ezpublish [system.default]</comment> |
83
|
|
|
|
84
|
|
|
EOM |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritdoc}. |
90
|
|
|
*/ |
91
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
92
|
|
|
{ |
93
|
|
|
$parameter = $input->getArgument('parameter'); |
94
|
|
|
$namespace = $input->getOption('namespace'); |
95
|
|
|
$scope = $input->getOption('scope'); |
96
|
|
|
$parameterData = $this->configResolver->getParameter($parameter, $namespace, $scope); |
|
|
|
|
97
|
|
|
|
98
|
|
|
// In case of json output return early with no newlines and only the parameter data |
99
|
|
|
if ($input->getOption('json')) { |
100
|
|
|
$output->write(json_encode($parameterData)); |
101
|
|
|
|
102
|
|
|
return; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
$output->writeln('<comment>SiteAccess name:</comment> ' . $this->siteAccess->name); |
106
|
|
|
|
107
|
|
|
$output->writeln("<comment>Parameter:</comment>"); |
108
|
|
|
$cloner = new VarCloner(); |
109
|
|
|
$dumper = new CliDumper(); |
110
|
|
|
$output->write( |
111
|
|
|
$dumper->dump( |
112
|
|
|
$cloner->cloneVar($parameterData), |
113
|
|
|
true |
114
|
|
|
) |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.