Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 118 lines (93 sloc) 3.601 kb
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
<?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;

use Symfony\Component\Config\Definition\ReferenceDumper;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Config\Definition\NodeInterface;
use Symfony\Component\Config\Definition\ArrayNode;
use Symfony\Component\Config\Definition\PrototypedArrayNode;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* A console command for dumping available configuration reference
*
* @author Kevin Bond <kevinbond@gmail.com>
*/
class ConfigDumpReferenceCommand extends ContainerDebugCommand
{
    /**
* @see Command
*/
    protected function configure()
    {
        $this
            ->setName('config:dump-reference')
            ->setDefinition(array(
                new InputArgument('name', InputArgument::REQUIRED, 'The Bundle or extension alias')
            ))
            ->setDescription('Dumps default configuration for an extension')
            ->setHelp(<<<EOF
The <info>%command.name%</info> command dumps the default configuration for an extension/bundle.

The extension alias or bundle name can be used:

Example:

  <info>php %command.full_name% framework</info>

or

  <info>php %command.full_name% FrameworkBundle</info>
EOF
            )
        ;
    }

    /**
* @see Command
*/
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $bundles = $this->getContainer()->get('kernel')->getBundles();
        $containerBuilder = $this->getContainerBuilder();

        $name = $input->getArgument('name');

        $extension = null;

        if (preg_match('/Bundle$/', $name)) {
            // input is bundle name

            if (isset($bundles[$name])) {
                $extension = $bundles[$name]->getContainerExtension();
            }

            if (!$extension) {
                throw new \LogicException('No extensions with configuration available for "'.$name.'"');
            }

            $message = 'Default configuration for "'.$name.'"';
        } else {
            foreach ($bundles as $bundle) {
                $extension = $bundle->getContainerExtension();

                if ($extension && $extension->getAlias() === $name) {
                    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');
        }

        if (!$configuration instanceof ConfigurationInterface) {
            throw new \LogicException(
                'Configuration class "'.get_class($configuration).
                '" should implement ConfigurationInterface in order to be dumpable');
        }

        $output->writeln($message);

        $dumper = new ReferenceDumper();
        $output->writeln($dumper->dump($configuration));
    }
}
Something went wrong with that request. Please try again.