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;
|
|
|
|
|
2012-09-20 12:28:43 +01:00
|
|
|
use Symfony\Component\Config\Definition\ReferenceDumper;
|
2011-06-03 19:38:47 +01:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2012-06-26 09:46:00 +01:00
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
2011-06-03 19:38:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A console command for dumping available configuration reference
|
|
|
|
*
|
|
|
|
* @author Kevin Bond <kevinbond@gmail.com>
|
|
|
|
*/
|
2012-02-02 16:47:41 +00:00
|
|
|
class ConfigDumpReferenceCommand extends ContainerDebugCommand
|
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-04-06 18:41:49 +01:00
|
|
|
new InputArgument('name', InputArgument::OPTIONAL, 'The Bundle or extension alias')
|
2011-06-03 19:38:47 +01:00
|
|
|
))
|
2012-02-12 15:37:55 +00:00
|
|
|
->setDescription('Dumps default configuration for an extension')
|
2011-06-03 19:38:47 +01:00
|
|
|
->setHelp(<<<EOF
|
2012-02-12 15:37:55 +00:00
|
|
|
The <info>%command.name%</info> command dumps the default configuration for an extension/bundle.
|
2011-06-03 19:38:47 +01:00
|
|
|
|
|
|
|
The extension alias or bundle name can be used:
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2012-02-12 15:37:55 +00:00
|
|
|
<info>php %command.full_name% framework</info>
|
2011-06-03 19:38:47 +01:00
|
|
|
|
|
|
|
or
|
|
|
|
|
2012-02-12 15:37:55 +00:00
|
|
|
<info>php %command.full_name% FrameworkBundle</info>
|
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)
|
|
|
|
{
|
2012-07-31 14:04:27 +01:00
|
|
|
$bundles = $this->getContainer()->get('kernel')->getBundles();
|
2011-06-03 19:38:47 +01:00
|
|
|
$containerBuilder = $this->getContainerBuilder();
|
|
|
|
|
|
|
|
$name = $input->getArgument('name');
|
|
|
|
|
2013-04-06 18:41:49 +01:00
|
|
|
if (empty($name)) {
|
|
|
|
$output->writeln('Available registered bundles with their extension alias if available:');
|
|
|
|
foreach ($bundles as $bundle) {
|
|
|
|
$extension = $bundle->getContainerExtension();
|
|
|
|
$output->writeln($bundle->getName().($extension ? ': '.$extension->getAlias() : ''));
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-03 19:38:47 +01:00
|
|
|
$extension = null;
|
|
|
|
|
|
|
|
if (preg_match('/Bundle$/', $name)) {
|
|
|
|
// input is bundle name
|
2012-07-31 14:04:27 +01:00
|
|
|
|
|
|
|
if (isset($bundles[$name])) {
|
|
|
|
$extension = $bundles[$name]->getContainerExtension();
|
|
|
|
}
|
2011-06-03 19:38:47 +01:00
|
|
|
|
|
|
|
if (!$extension) {
|
|
|
|
throw new \LogicException('No extensions with configuration available for "'.$name.'"');
|
|
|
|
}
|
|
|
|
|
|
|
|
$message = 'Default configuration for "'.$name.'"';
|
|
|
|
} else {
|
2012-07-31 14:04:27 +01:00
|
|
|
foreach ($bundles as $bundle) {
|
2011-06-03 19:38:47 +01:00
|
|
|
$extension = $bundle->getContainerExtension();
|
|
|
|
|
2012-01-24 20:51:23 +00:00
|
|
|
if ($extension && $extension->getAlias() === $name) {
|
2011-06-03 19:38:47 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$extension = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$extension) {
|
|
|
|
throw new \LogicException('No extension with alias "'.$name.'" is enabled');
|
|
|
|
}
|
|
|
|
|
|
|
|
$message = 'Default configuration for extension with alias: "'.$name.'"';
|
|
|
|
}
|
|
|
|
|
|
|
|
$configuration = $extension->getConfiguration(array(), $containerBuilder);
|
|
|
|
|
|
|
|
if (!$configuration) {
|
|
|
|
throw new \LogicException('The extension with alias "'.$extension->getAlias().
|
|
|
|
'" does not have it\'s getConfiguration() method setup');
|
|
|
|
}
|
|
|
|
|
2012-06-26 09:46:00 +01:00
|
|
|
if (!$configuration instanceof ConfigurationInterface) {
|
|
|
|
throw new \LogicException(
|
|
|
|
'Configuration class "'.get_class($configuration).
|
|
|
|
'" should implement ConfigurationInterface in order to be dumpable');
|
|
|
|
}
|
|
|
|
|
2011-06-03 19:38:47 +01:00
|
|
|
$output->writeln($message);
|
|
|
|
|
2012-09-20 12:28:43 +01:00
|
|
|
$dumper = new ReferenceDumper();
|
|
|
|
$output->writeln($dumper->dump($configuration));
|
2011-06-03 19:38:47 +01:00
|
|
|
}
|
|
|
|
}
|