src/Viserio/Component/OptionsResolver/Command/OptionDumpCommand.php
public function handle(): int
    {
        $format = $this->option('format');
        $dumper = null;

        if ($this->container !== null && $this->getContainer()->has(Dumper::class)) {
            $dumper = $this->getContainer()->get(Dumper::class);
        }

        if ($dumper === null && $format !== 'php') {
            $this->error('Only the php format is supported; use composer req viserio/parser to get [json], [xml], [yml] output.');

            return 1;
        }

        $dirPath = $this->argument('dir');

        if (! \is_dir($dirPath) && ! @\mkdir($dirPath, 0777, true)) {
            throw new \RuntimeException(\sprintf('Config directory [%s] cannot be created or is write protected.', $dirPath));
        }

        $className = $this->argument('class');
        $configs   = $this->getConfigReader()->readConfig(new ReflectionClass($className));

        foreach ($configs as $key => $config) {
            $file = $dirPath . \DIRECTORY_SEPARATOR . $key . '.' . $format;

            if ($this->hasOption('merge') && \file_exists($file)) {
                $existingConfig = includeFile($file);
                $config         = \array_replace_recursive($existingConfig, $config);
            }

            if ($dumper !== null && $format !== 'php') {
                $content = $dumper->dump($config, $format) . \PHP_EOL;
            } else {
                $content = '<?php' . \PHP_EOL . 'declare(strict_types=1);' . \PHP_EOL . \PHP_EOL . 'return ';
                $content .= VarExporter::export($config) . ';' . \PHP_EOL;
            }

            if ($this->hasOption('show')) {
                $this->info('Output array:' . \PHP_EOL . \PHP_EOL . $content);

                if ($this->confirm(\sprintf('Write content to [%s]?', $file)) === false) {
                    continue;
                }
            }

            $this->info(\sprintf('Dumping [%s] configuration to [%s].', $className, $file));
            $this->putContentToFile($file, $content, $key);
        }

        return 0;
    }
public function handle(): int
    {
        $format = $this->option('format');
        $dumper = null;

        if ($this->container !== null && $this->getContainer()->has(Dumper::class)) {
            $dumper = $this->getContainer()->get(Dumper::class);
        }

        if ($dumper === null && $format !== 'php') {
            $this->error('Only the php format is supported; use composer req viserio/parser to get [json], [xml], [yml] output.');

            return 1;
        }

        $dirPath = $this->argument('dir');

        if (! \is_dir($dirPath) && ! @\mkdir($dirPath, 0777, true)) {
            throw new \RuntimeException(\sprintf('Config directory [%s] cannot be created or is write protected.', $dirPath));
        }

        $className = $this->argument('class');
        $configs   = $this->getConfigReader()->readConfig(new ReflectionClass($className));

        foreach ($configs as $key => $config) {
            $file = $dirPath . \DIRECTORY_SEPARATOR . $key . '.' . $format;

            if ($this->hasOption('merge') && \file_exists($file)) {
                $existingConfig = includeFile($file);
                $config         = \array_replace_recursive($existingConfig, $config);
            }

            if ($dumper !== null && $format !== 'php') {
                $content = $dumper->dump($config, $format) . \PHP_EOL;
            } else {
                $content = '<?php' . \PHP_EOL . 'declare(strict_types=1);' . \PHP_EOL . \PHP_EOL . 'return ';
                $content .= VarExporter::export($config) . ';' . \PHP_EOL;
            }

            if ($this->hasOption('show')) {
                $this->info('Output array:' . \PHP_EOL . \PHP_EOL . $content);

                if ($this->confirm(\sprintf('Write content to [%s]?', $file)) === false) {
                    continue;
                }
            }

            $this->info(\sprintf('Dumping [%s] configuration to [%s].', $className, $file));
            $this->putContentToFile($file, $content, $key);
        }

        return 0;
    }
{@inheritdoc}

@throws \Viserio\Component\Contract\OptionsResolver\Exception\InvalidArgumentException if dir cant be created or is not writable