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