2011-06-03 19:38:47 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Bundle\FrameworkBundle\Command;
|
|
|
|
|
2013-09-09 15:57:50 +01:00
|
|
|
use Symfony\Component\Config\Definition\Dumper\YamlReferenceDumper;
|
|
|
|
use Symfony\Component\Config\Definition\Dumper\XmlReferenceDumper;
|
2011-06-03 19:38:47 +01:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
2013-09-18 13:22:34 +01:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2011-06-03 19:38:47 +01:00
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
/**
|
2014-03-13 04:05:55 +00:00
|
|
|
* A console command for dumping available configuration reference.
|
2011-06-03 19:38:47 +01:00
|
|
|
*
|
|
|
|
* @author Kevin Bond <kevinbond@gmail.com>
|
2013-09-09 15:57:50 +01:00
|
|
|
* @author Wouter J <waldio.webdesign@gmail.com>
|
2014-01-30 19:09:44 +00:00
|
|
|
* @author Grégoire Pineau <lyrixx@lyrixx.info>
|
2011-06-03 19:38:47 +01:00
|
|
|
*/
|
2014-01-30 19:09:44 +00:00
|
|
|
class ConfigDumpReferenceCommand extends AbstractConfigCommand
|
2011-06-03 19:38:47 +01:00
|
|
|
{
|
|
|
|
/**
|
2013-03-07 13:36:36 +00:00
|
|
|
* {@inheritdoc}
|
2011-06-03 19:38:47 +01:00
|
|
|
*/
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
2012-02-12 15:37:55 +00:00
|
|
|
->setName('config:dump-reference')
|
2011-06-03 19:38:47 +01:00
|
|
|
->setDefinition(array(
|
2013-09-18 13:22:34 +01:00
|
|
|
new InputArgument('name', InputArgument::OPTIONAL, 'The Bundle name or the extension alias'),
|
2013-09-09 15:57:50 +01:00
|
|
|
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The format, either yaml or xml', 'yaml'),
|
2011-06-03 19:38:47 +01:00
|
|
|
))
|
2013-09-18 13:22:34 +01:00
|
|
|
->setDescription('Dumps the default configuration for an extension')
|
2011-06-03 19:38:47 +01:00
|
|
|
->setHelp(<<<EOF
|
2013-09-18 13:22:34 +01:00
|
|
|
The <info>%command.name%</info> command dumps the default configuration for an
|
|
|
|
extension/bundle.
|
2011-06-03 19:38:47 +01:00
|
|
|
|
2014-01-30 19:09:44 +00:00
|
|
|
Either the extension alias or bundle name can be used:
|
2011-06-03 19:38:47 +01:00
|
|
|
|
2012-02-12 15:37:55 +00:00
|
|
|
<info>php %command.full_name% framework</info>
|
|
|
|
<info>php %command.full_name% FrameworkBundle</info>
|
2013-09-09 15:57:50 +01:00
|
|
|
|
2013-09-18 13:22:34 +01:00
|
|
|
With the <info>format</info> option specifies the format of the configuration,
|
2014-01-30 19:09:44 +00:00
|
|
|
this is either <comment>yaml</comment> or <comment>xml</comment>.
|
|
|
|
When the option is not provided, <comment>yaml</comment> is used.
|
|
|
|
|
|
|
|
<info>php %command.full_name% FrameworkBundle --format=xml</info>
|
2014-03-13 04:05:55 +00:00
|
|
|
|
2011-06-03 19:38:47 +01:00
|
|
|
EOF
|
|
|
|
)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-03-07 13:36:36 +00:00
|
|
|
* {@inheritdoc}
|
|
|
|
*
|
|
|
|
* @throws \LogicException
|
2011-06-03 19:38:47 +01:00
|
|
|
*/
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
|
|
|
$name = $input->getArgument('name');
|
|
|
|
|
2013-04-06 18:41:49 +01:00
|
|
|
if (empty($name)) {
|
2014-01-30 19:09:44 +00:00
|
|
|
$this->listBundles($output);
|
2013-04-06 18:41:49 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-23 16:22:13 +00:00
|
|
|
$extension = $this->findExtension($name);
|
2012-07-31 14:04:27 +01:00
|
|
|
|
2014-01-30 19:09:44 +00:00
|
|
|
$configuration = $extension->getConfiguration(array(), $this->getContainerBuilder());
|
2011-06-03 19:38:47 +01:00
|
|
|
|
2014-01-30 19:09:44 +00:00
|
|
|
$this->validateConfiguration($extension, $configuration);
|
2011-06-03 19:38:47 +01:00
|
|
|
|
2014-01-30 19:09:44 +00:00
|
|
|
if ($name === $extension->getAlias()) {
|
|
|
|
$message = sprintf('Default configuration for extension with alias: "%s"', $name);
|
2011-06-03 19:38:47 +01:00
|
|
|
} else {
|
2014-01-30 19:09:44 +00:00
|
|
|
$message = sprintf('Default configuration for "%s"', $name);
|
2012-06-26 09:46:00 +01:00
|
|
|
}
|
|
|
|
|
2013-09-09 15:57:50 +01:00
|
|
|
switch ($input->getOption('format')) {
|
|
|
|
case 'yaml':
|
2013-09-18 13:22:34 +01:00
|
|
|
$output->writeln(sprintf('# %s', $message));
|
2013-09-09 15:57:50 +01:00
|
|
|
$dumper = new YamlReferenceDumper();
|
|
|
|
break;
|
|
|
|
case 'xml':
|
2013-09-18 13:22:34 +01:00
|
|
|
$output->writeln(sprintf('<!-- %s -->', $message));
|
2013-09-09 15:57:50 +01:00
|
|
|
$dumper = new XmlReferenceDumper();
|
|
|
|
break;
|
|
|
|
default:
|
2013-09-18 13:22:34 +01:00
|
|
|
$output->writeln($message);
|
2013-09-09 15:57:50 +01:00
|
|
|
throw new \InvalidArgumentException('Only the yaml and xml formats are supported.');
|
|
|
|
}
|
|
|
|
|
2013-10-18 10:29:21 +01:00
|
|
|
$output->writeln($dumper->dump($configuration, $extension->getNamespace()));
|
2011-06-03 19:38:47 +01:00
|
|
|
}
|
|
|
|
}
|