14 use Symfony\Component\Console\Command\Command;
15 use Symfony\Component\Console\Input\InputArgument;
16 use Symfony\Component\Console\Input\InputInterface;
17 use Symfony\Component\Console\Output\OutputInterface;
51 Hash $configHash =
null 53 $this->writer = $writer;
54 $this->sources = $sources;
56 parent::__construct();
64 $this->setName(
'app:config:dump');
65 $this->setDescription(
'Create dump of application');
67 $configTypes = array_unique(array_column($this->sources,
'namespace'));
69 self::INPUT_CONFIG_TYPES,
70 InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
71 sprintf(
'Space-separated list of config types or omit to dump all [%s]', implode(
', ', $configTypes))
84 protected function execute(InputInterface $input, OutputInterface
$output)
86 $this->groupSourcesByPool();
88 foreach ($this->sources as $pool => $sources) {
91 foreach ($sources as $sourceData) {
92 if ($this->skipDump($input, $sourceData)) {
96 $source = $sourceData[
'source'];
97 $namespace = $sourceData[
'namespace'];
98 $dump[$namespace] =
$source->get();
99 if (!empty($sourceData[
'comment'])) {
100 $comments[$namespace] = is_string($sourceData[
'comment'])
101 ? $sourceData[
'comment']
102 : $sourceData[
'comment']->get();
105 $this->writer->saveConfig(
111 $dumpedTypes = array_unique($dumpedTypes + array_keys($dump));
118 $output->writeln(
'<error>Nothing dumped. Check the config types specified and try again');
123 $this->configHash->regenerate();
125 $output->writeln(sprintf(
'<info>Done. Config types dumped: %s</info>', implode(
', ', $dumpedTypes)));
136 private function groupSourcesByPool()
139 foreach ($this->sources as $sourceData) {
140 if (!isset($sourceData[
'pool'])) {
144 $sources[$sourceData[
'pool']][] = $sourceData;
147 $this->sources = $sources;
157 private function skipDump(InputInterface $input, array $sourceData): bool
159 $allowedTypes = $input->getArgument(self::INPUT_CONFIG_TYPES);
160 if ($allowedTypes && !in_array($sourceData[
'namespace'], $allowedTypes)) {
__construct(Writer $writer, array $sources, Hash $configHash=null)