2011-03-10 15:09:40 +00: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-04-30 16:08:17 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper;
|
2011-03-10 15:09:40 +00:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2011-05-01 16:18:30 +01:00
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
use Symfony\Component\Config\FileLocator;
|
2011-03-10 15:09:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A console command for retrieving information about services
|
|
|
|
*
|
|
|
|
* @author Ryan Weaver <ryan@thatsquality.com>
|
|
|
|
*/
|
2011-09-15 15:46:01 +01:00
|
|
|
class ContainerDebugCommand extends ContainerAwareCommand
|
2011-03-10 15:09:40 +00:00
|
|
|
{
|
|
|
|
/**
|
2013-03-07 13:36:36 +00:00
|
|
|
* @var ContainerBuilder|null
|
2011-03-10 15:09:40 +00:00
|
|
|
*/
|
2012-06-26 08:01:12 +01:00
|
|
|
protected $containerBuilder;
|
2011-03-10 15:09:40 +00:00
|
|
|
|
|
|
|
/**
|
2013-03-07 13:36:36 +00:00
|
|
|
* {@inheritdoc}
|
2011-03-10 15:09:40 +00:00
|
|
|
*/
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
2012-02-12 15:37:55 +00:00
|
|
|
->setName('container:debug')
|
2011-03-10 15:09:40 +00:00
|
|
|
->setDefinition(array(
|
2012-03-07 11:09:07 +00:00
|
|
|
new InputArgument('name', InputArgument::OPTIONAL, 'A service name (foo)'),
|
2011-03-10 15:09:40 +00:00
|
|
|
new InputOption('show-private', null, InputOption::VALUE_NONE, 'Use to show public *and* private services'),
|
2012-09-16 16:15:14 +01:00
|
|
|
new InputOption('tag', null, InputOption::VALUE_REQUIRED, 'Show all services with a specific tag'),
|
2013-03-30 15:35:41 +00:00
|
|
|
new InputOption('tags', null, InputOption::VALUE_NONE, 'Displays tagged services for an application'),
|
|
|
|
new InputOption('parameter', null, InputOption::VALUE_REQUIRED, 'Displays a specific parameter for an application'),
|
2013-04-30 16:08:17 +01:00
|
|
|
new InputOption('parameters', null, InputOption::VALUE_NONE, 'Displays parameters for an application'),
|
2013-10-02 15:03:04 +01:00
|
|
|
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'To output description in other formats', 'txt'),
|
2013-04-30 16:08:17 +01:00
|
|
|
new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw description'),
|
2011-03-10 15:09:40 +00:00
|
|
|
))
|
|
|
|
->setDescription('Displays current services for an application')
|
|
|
|
->setHelp(<<<EOF
|
2012-02-12 15:37:55 +00:00
|
|
|
The <info>%command.name%</info> command displays all configured <comment>public</comment> services:
|
2011-03-10 15:09:40 +00:00
|
|
|
|
2012-02-12 15:37:55 +00:00
|
|
|
<info>php %command.full_name%</info>
|
2011-03-10 15:09:40 +00:00
|
|
|
|
2011-04-19 23:01:22 +01:00
|
|
|
To get specific information about a service, specify its name:
|
2011-03-10 15:09:40 +00:00
|
|
|
|
2012-02-12 15:37:55 +00:00
|
|
|
<info>php %command.full_name% validator</info>
|
2011-03-10 15:09:40 +00:00
|
|
|
|
|
|
|
By default, private services are hidden. You can display all services by
|
|
|
|
using the --show-private flag:
|
|
|
|
|
2012-02-12 15:37:55 +00:00
|
|
|
<info>php %command.full_name% --show-private</info>
|
2012-09-16 16:15:14 +01:00
|
|
|
|
|
|
|
Use the --tags option to display tagged <comment>public</comment> services grouped by tag:
|
|
|
|
|
|
|
|
<info>php %command.full_name% --tags</info>
|
|
|
|
|
|
|
|
Find all services with a specific tag by specifying the tag name with the --tag option:
|
|
|
|
|
|
|
|
<info>php %command.full_name% --tag=form.type</info>
|
2013-03-30 15:35:41 +00:00
|
|
|
|
|
|
|
Use the --parameters option to display all parameters:
|
|
|
|
|
|
|
|
<info>php %command.full_name% --parameters</info>
|
|
|
|
|
|
|
|
Display a specific parameter by specifying his name with the --parameter option:
|
|
|
|
|
|
|
|
<info>php %command.full_name% --parameter=kernel.debug</info>
|
2011-03-10 15:09:40 +00:00
|
|
|
EOF
|
|
|
|
)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-03-07 13:36:36 +00:00
|
|
|
* {@inheritdoc}
|
|
|
|
*
|
|
|
|
* @throws \LogicException
|
2011-03-10 15:09:40 +00:00
|
|
|
*/
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
2013-03-30 15:35:41 +00:00
|
|
|
$this->validateInput($input);
|
2011-03-10 15:09:40 +00:00
|
|
|
|
2013-03-30 15:35:41 +00:00
|
|
|
if ($input->getOption('parameters')) {
|
2013-04-30 16:08:17 +01:00
|
|
|
$object = $this->getContainerBuilder()->getParameterBag();
|
|
|
|
$options = array();
|
|
|
|
} elseif ($parameter = $input->getOption('parameter')) {
|
|
|
|
$object = $this->getContainerBuilder();
|
|
|
|
$options = array('parameter' => $parameter);
|
|
|
|
} elseif ($input->getOption('tags')) {
|
|
|
|
$object = $this->getContainerBuilder();
|
|
|
|
$options = array('group_by' => 'tags', 'show_private' => $input->getOption('show-private'));
|
|
|
|
} elseif ($tag = $input->getOption('tag')) {
|
|
|
|
$object = $this->getContainerBuilder();
|
|
|
|
$options = array('tag' => $tag, 'show_private' => $input->getOption('show-private'));
|
|
|
|
} elseif ($name = $input->getArgument('name')) {
|
|
|
|
$object = $this->getContainerBuilder();
|
|
|
|
$options = array('id' => $name);
|
2012-09-16 16:15:14 +01:00
|
|
|
} else {
|
2013-04-30 16:08:17 +01:00
|
|
|
$object = $this->getContainerBuilder();
|
|
|
|
$options = array('show_private' => $input->getOption('show-private'));
|
2012-09-16 16:15:14 +01:00
|
|
|
}
|
2011-04-19 23:01:22 +01:00
|
|
|
|
2013-04-30 16:08:17 +01:00
|
|
|
$helper = new DescriptorHelper();
|
2013-10-02 15:03:04 +01:00
|
|
|
$options['format'] = $input->getOption('format');
|
|
|
|
$options['raw_text'] = $input->getOption('raw');
|
|
|
|
$helper->describe($output, $object, $options);
|
2011-03-10 15:09:40 +00:00
|
|
|
}
|
|
|
|
|
2013-04-30 16:08:17 +01:00
|
|
|
/**
|
|
|
|
* Validates input arguments and options.
|
|
|
|
*
|
|
|
|
* @param InputInterface $input
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
*/
|
2013-03-30 15:35:41 +00:00
|
|
|
protected function validateInput(InputInterface $input)
|
|
|
|
{
|
|
|
|
$options = array('tags', 'tag', 'parameters', 'parameter');
|
|
|
|
|
|
|
|
$optionsCount = 0;
|
|
|
|
foreach ($options as $option) {
|
|
|
|
if ($input->getOption($option)) {
|
|
|
|
$optionsCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$name = $input->getArgument('name');
|
|
|
|
if ((null !== $name) && ($optionsCount > 0)) {
|
|
|
|
throw new \InvalidArgumentException('The options tags, tag, parameters & parameter can not be combined with the service name argument.');
|
|
|
|
} elseif ((null === $name) && $optionsCount > 1) {
|
2013-04-21 12:14:35 +01:00
|
|
|
throw new \InvalidArgumentException('The options tags, tag, parameters & parameter can not be combined together.');
|
2013-03-30 15:35:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-10 15:09:40 +00:00
|
|
|
/**
|
|
|
|
* Loads the ContainerBuilder from the cache.
|
|
|
|
*
|
2011-05-01 16:18:30 +01:00
|
|
|
* @return ContainerBuilder
|
2012-12-16 12:02:54 +00:00
|
|
|
*
|
|
|
|
* @throws \LogicException
|
2011-03-10 15:09:40 +00:00
|
|
|
*/
|
2011-09-15 15:46:01 +01:00
|
|
|
protected function getContainerBuilder()
|
2011-03-10 15:09:40 +00:00
|
|
|
{
|
2011-05-01 16:18:30 +01:00
|
|
|
if (!$this->getApplication()->getKernel()->isDebug()) {
|
|
|
|
throw new \LogicException(sprintf('Debug information about the container is only available in debug mode.'));
|
|
|
|
}
|
2011-03-10 15:09:40 +00:00
|
|
|
|
2011-08-29 14:28:03 +01:00
|
|
|
if (!is_file($cachedFile = $this->getContainer()->getParameter('debug.container.dump'))) {
|
2011-03-10 15:09:40 +00:00
|
|
|
throw new \LogicException(sprintf('Debug information about the container could not be found. Please clear the cache and try again.'));
|
|
|
|
}
|
|
|
|
|
2011-05-01 16:18:30 +01:00
|
|
|
$container = new ContainerBuilder();
|
|
|
|
|
|
|
|
$loader = new XmlFileLoader($container, new FileLocator());
|
|
|
|
$loader->load($cachedFile);
|
|
|
|
|
|
|
|
return $container;
|
2011-03-10 15:09:40 +00:00
|
|
|
}
|
|
|
|
}
|