-
-
Notifications
You must be signed in to change notification settings - Fork 137
/
ConfigurationShowLocalCommand.php
92 lines (79 loc) · 2.86 KB
/
ConfigurationShowLocalCommand.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
<?php
declare(strict_types=1);
namespace Helhum\Typo3Console\Command\Configuration;
/*
* This file is part of the TYPO3 Console project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read
* LICENSE file that was distributed with this source code.
*
*/
use Helhum\Typo3Console\Command\RelatableCommandInterface;
use Helhum\Typo3Console\Service\Configuration\ConfigurationService;
use Helhum\Typo3Console\Service\Configuration\ConsoleRenderer\ConsoleRenderer;
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;
class ConfigurationShowLocalCommand extends Command implements RelatableCommandInterface
{
public function __construct(private readonly bool $applicationIsReady)
{
parent::__construct('configuration:showlocal');
}
public function isEnabled(): bool
{
return $this->applicationIsReady || getenv('TYPO3_CONSOLE_RENDERING_REFERENCE') !== false;
}
public function getRelatedCommandNames(): array
{
return [
'typo3_console:configuration:show',
];
}
protected function configure()
{
$this->setDescription('Show local configuration value');
$this->setHelp(
<<<'EOH'
Shows local configuration option value by path.
Shows the value which is stored in system configuration file.
Note that this value could be overridden. Use <code>typo3 configuration:show <path></code> to see if this is the case.
<b>Example:</b>
<code>%command.full_name% DB</code>
EOH
);
$this->setDefinition([
new InputArgument(
'path',
InputArgument::REQUIRED,
'Path to local system configuration'
),
new InputOption(
'json',
'',
InputOption::VALUE_NONE,
'If set, the configuration is shown as JSON'
),
]);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$path = $input->getArgument('path');
$json = $input->getOption('json');
$configurationService = new ConfigurationService();
$consoleRenderer = new ConsoleRenderer();
if (!$configurationService->hasLocal($path)) {
$output->writeln(sprintf('<error>No configuration found for path "%s"</error>', $path));
return 1;
}
$active = $configurationService->getLocal($path);
$output->writeln($consoleRenderer->render($active, $json));
return 0;
}
}