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;
|
|
|
|
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Symfony\Component\DependencyInjection\Alias;
|
|
|
|
use Symfony\Component\DependencyInjection\Definition;
|
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'),
|
|
|
|
new InputOption('parameters', null, InputOption::VALUE_NONE, 'Displays parameters for an application')
|
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
|
|
|
|
|
|
|
$this->containerBuilder = $this->getContainerBuilder();
|
2012-09-16 16:15:14 +01:00
|
|
|
|
2013-03-30 15:35:41 +00:00
|
|
|
if ($input->getOption('parameters')) {
|
|
|
|
$parameters = $this->getContainerBuilder()->getParameterBag()->all();
|
|
|
|
|
|
|
|
// Sort parameters alphabetically
|
|
|
|
ksort($parameters);
|
|
|
|
|
|
|
|
$this->outputParameters($output, $parameters);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2012-07-15 21:43:34 +01:00
|
|
|
|
2013-03-30 15:35:41 +00:00
|
|
|
$parameter = $input->getOption('parameter');
|
|
|
|
if (null !== $parameter) {
|
|
|
|
$output->write($this->formatParameter($this->getContainerBuilder()->getParameter($parameter)));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($input->getOption('tags')) {
|
2012-09-16 16:15:14 +01:00
|
|
|
$this->outputTags($output, $input->getOption('show-private'));
|
2012-12-11 10:49:22 +00:00
|
|
|
|
2012-09-16 16:15:14 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-07-15 21:43:34 +01:00
|
|
|
|
2013-03-30 15:35:41 +00:00
|
|
|
$tag = $input->getOption('tag');
|
2012-09-16 16:15:14 +01:00
|
|
|
if (null !== $tag) {
|
|
|
|
$serviceIds = array_keys($this->containerBuilder->findTaggedServiceIds($tag));
|
|
|
|
} else {
|
|
|
|
$serviceIds = $this->containerBuilder->getServiceIds();
|
|
|
|
}
|
2011-04-19 23:01:22 +01:00
|
|
|
|
|
|
|
// sort so that it reads like an index of services
|
|
|
|
asort($serviceIds);
|
2011-03-10 15:09:40 +00:00
|
|
|
|
2013-05-17 19:12:23 +01:00
|
|
|
$name = $input->getArgument('name');
|
2011-04-19 23:01:22 +01:00
|
|
|
if ($name) {
|
|
|
|
$this->outputService($output, $name);
|
2011-03-10 15:09:40 +00:00
|
|
|
} else {
|
2012-09-16 16:15:14 +01:00
|
|
|
$this->outputServices($output, $serviceIds, $input->getOption('show-private'), $tag);
|
2011-03-10 15:09:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-16 16:15:14 +01:00
|
|
|
protected function outputServices(OutputInterface $output, $serviceIds, $showPrivate = false, $showTagAttributes = null)
|
2011-03-10 15:09:40 +00:00
|
|
|
{
|
|
|
|
// set the label to specify public or public+private
|
|
|
|
if ($showPrivate) {
|
|
|
|
$label = '<comment>Public</comment> and <comment>private</comment> services';
|
|
|
|
} else {
|
|
|
|
$label = '<comment>Public</comment> services';
|
|
|
|
}
|
2012-09-16 16:15:14 +01:00
|
|
|
if ($showTagAttributes) {
|
|
|
|
$label .= ' with tag <info>'.$showTagAttributes.'</info>';
|
|
|
|
}
|
2011-03-10 15:09:40 +00:00
|
|
|
|
|
|
|
$output->writeln($this->getHelper('formatter')->formatSection('container', $label));
|
|
|
|
|
2011-05-01 16:18:30 +01:00
|
|
|
// loop through to get space needed and filter private services
|
2011-03-10 15:09:40 +00:00
|
|
|
$maxName = 4;
|
|
|
|
$maxScope = 6;
|
2012-07-15 21:43:34 +01:00
|
|
|
$maxTags = array();
|
2011-03-10 15:09:40 +00:00
|
|
|
foreach ($serviceIds as $key => $serviceId) {
|
|
|
|
$definition = $this->resolveServiceDefinition($serviceId);
|
|
|
|
|
|
|
|
if ($definition instanceof Definition) {
|
|
|
|
// filter out private services unless shown explicitly
|
|
|
|
if (!$showPrivate && !$definition->isPublic()) {
|
|
|
|
unset($serviceIds[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen($definition->getScope()) > $maxScope) {
|
|
|
|
$maxScope = strlen($definition->getScope());
|
|
|
|
}
|
2012-07-15 21:43:34 +01:00
|
|
|
|
|
|
|
if (null !== $showTagAttributes) {
|
|
|
|
$tags = $definition->getTag($showTagAttributes);
|
2012-12-11 10:49:22 +00:00
|
|
|
foreach ($tags as $tag) {
|
|
|
|
foreach ($tag as $key => $value) {
|
2012-07-15 21:43:34 +01:00
|
|
|
if (!isset($maxTags[$key])) {
|
|
|
|
$maxTags[$key] = strlen($key);
|
|
|
|
}
|
|
|
|
if (strlen($value) > $maxTags[$key]) {
|
|
|
|
$maxTags[$key] = strlen($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-10 15:09:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen($serviceId) > $maxName) {
|
|
|
|
$maxName = strlen($serviceId);
|
|
|
|
}
|
|
|
|
}
|
2012-07-15 21:43:34 +01:00
|
|
|
$format = '%-'.$maxName.'s ';
|
|
|
|
$format .= implode("", array_map(function($length) { return "%-{$length}s "; }, $maxTags));
|
|
|
|
$format .= '%-'.$maxScope.'s %s';
|
2011-03-10 15:09:40 +00:00
|
|
|
|
|
|
|
// the title field needs extra space to make up for comment tags
|
2012-07-15 21:43:34 +01:00
|
|
|
$format1 = '%-'.($maxName + 19).'s ';
|
|
|
|
$format1 .= implode("", array_map(function($length) { return '%-'.($length + 19).'s '; }, $maxTags));
|
|
|
|
$format1 .= '%-'.($maxScope + 19).'s %s';
|
|
|
|
|
|
|
|
$tags = array();
|
2012-12-11 10:49:22 +00:00
|
|
|
foreach ($maxTags as $tagName => $length) {
|
2012-07-15 21:43:34 +01:00
|
|
|
$tags[] = '<comment>'.$tagName.'</comment>';
|
|
|
|
}
|
|
|
|
$output->writeln(vsprintf($format1, $this->buildArgumentsArray('<comment>Service Id</comment>', '<comment>Scope</comment>', '<comment>Class Name</comment>', $tags)));
|
2011-03-10 15:09:40 +00:00
|
|
|
|
|
|
|
foreach ($serviceIds as $serviceId) {
|
|
|
|
$definition = $this->resolveServiceDefinition($serviceId);
|
|
|
|
|
|
|
|
if ($definition instanceof Definition) {
|
2012-07-15 21:43:34 +01:00
|
|
|
$lines = array();
|
|
|
|
if (null !== $showTagAttributes) {
|
2012-12-11 10:49:22 +00:00
|
|
|
foreach ($definition->getTag($showTagAttributes) as $key => $tag) {
|
2012-07-15 21:43:34 +01:00
|
|
|
$tagValues = array();
|
2012-12-11 10:49:22 +00:00
|
|
|
foreach (array_keys($maxTags) as $tagName) {
|
2012-07-15 21:43:34 +01:00
|
|
|
$tagValues[] = isset($tag[$tagName]) ? $tag[$tagName] : "";
|
|
|
|
}
|
|
|
|
if (0 === $key) {
|
|
|
|
$lines[] = $this->buildArgumentsArray($serviceId, $definition->getScope(), $definition->getClass(), $tagValues);
|
|
|
|
} else {
|
|
|
|
$lines[] = $this->buildArgumentsArray(' "', '', '', $tagValues);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$lines[] = $this->buildArgumentsArray($serviceId, $definition->getScope(), $definition->getClass());
|
|
|
|
}
|
|
|
|
|
2012-12-11 10:49:22 +00:00
|
|
|
foreach ($lines as $arguments) {
|
2012-07-15 21:43:34 +01:00
|
|
|
$output->writeln(vsprintf($format, $arguments));
|
|
|
|
}
|
2011-03-10 15:09:40 +00:00
|
|
|
} elseif ($definition instanceof Alias) {
|
|
|
|
$alias = $definition;
|
2012-07-15 21:43:34 +01:00
|
|
|
$output->writeln(vsprintf($format, $this->buildArgumentsArray($serviceId, 'n/a', sprintf('<comment>alias for</comment> <info>%s</info>', (string) $alias), count($maxTags) ? array_fill(0, count($maxTags), "") : array())));
|
2011-03-10 15:09:40 +00:00
|
|
|
} else {
|
|
|
|
// we have no information (happens with "service_container")
|
|
|
|
$service = $definition;
|
2012-07-15 21:43:34 +01:00
|
|
|
$output->writeln(vsprintf($format, $this->buildArgumentsArray($serviceId, '', get_class($service), count($maxTags) ? array_fill(0, count($maxTags), "") : array())));
|
2012-09-16 16:15:14 +01:00
|
|
|
}
|
2011-03-10 15:09:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-15 21:43:34 +01:00
|
|
|
protected function buildArgumentsArray($serviceId, $scope, $className, array $tagAttributes = array())
|
|
|
|
{
|
|
|
|
$arguments = array($serviceId);
|
2012-12-11 10:49:22 +00:00
|
|
|
foreach ($tagAttributes as $tagAttribute) {
|
2012-07-15 21:43:34 +01:00
|
|
|
$arguments[] = $tagAttribute;
|
|
|
|
}
|
|
|
|
$arguments[] = $scope;
|
|
|
|
$arguments[] = $className;
|
|
|
|
|
|
|
|
return $arguments;
|
|
|
|
}
|
|
|
|
|
2011-03-10 15:09:40 +00:00
|
|
|
/**
|
|
|
|
* Renders detailed service information about one service
|
|
|
|
*/
|
|
|
|
protected function outputService(OutputInterface $output, $serviceId)
|
|
|
|
{
|
|
|
|
$definition = $this->resolveServiceDefinition($serviceId);
|
|
|
|
|
|
|
|
$label = sprintf('Information for service <info>%s</info>', $serviceId);
|
|
|
|
$output->writeln($this->getHelper('formatter')->formatSection('container', $label));
|
|
|
|
$output->writeln('');
|
|
|
|
|
|
|
|
if ($definition instanceof Definition) {
|
2011-10-18 13:54:39 +01:00
|
|
|
$output->writeln(sprintf('<comment>Service Id</comment> %s', $serviceId));
|
2012-07-15 21:43:34 +01:00
|
|
|
$output->writeln(sprintf('<comment>Class</comment> %s', $definition->getClass() ?: "-"));
|
|
|
|
|
|
|
|
$tags = $definition->getTags();
|
|
|
|
if (count($tags)) {
|
|
|
|
$output->writeln('<comment>Tags</comment>');
|
|
|
|
foreach ($tags as $tagName => $tagData) {
|
|
|
|
foreach ($tagData as $singleTagData) {
|
|
|
|
$output->writeln(sprintf(' - %-30s (%s)', $tagName, implode(', ', array_map(function($key, $value) {
|
|
|
|
return sprintf('<info>%s</info>: %s', $key, $value);
|
|
|
|
}, array_keys($singleTagData), array_values($singleTagData)))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$output->writeln('<comment>Tags</comment> -');
|
|
|
|
}
|
2011-03-10 15:09:40 +00:00
|
|
|
|
2011-10-18 13:54:39 +01:00
|
|
|
$output->writeln(sprintf('<comment>Scope</comment> %s', $definition->getScope()));
|
2011-03-10 15:09:40 +00:00
|
|
|
|
2011-03-14 13:23:39 +00:00
|
|
|
$public = $definition->isPublic() ? 'yes' : 'no';
|
2011-10-18 13:54:39 +01:00
|
|
|
$output->writeln(sprintf('<comment>Public</comment> %s', $public));
|
|
|
|
|
|
|
|
$synthetic = $definition->isSynthetic() ? 'yes' : 'no';
|
|
|
|
$output->writeln(sprintf('<comment>Synthetic</comment> %s', $synthetic));
|
|
|
|
|
|
|
|
$file = $definition->getFile() ? $definition->getFile() : '-';
|
|
|
|
$output->writeln(sprintf('<comment>Required File</comment> %s', $file));
|
2011-03-10 15:09:40 +00:00
|
|
|
} elseif ($definition instanceof Alias) {
|
|
|
|
$alias = $definition;
|
|
|
|
$output->writeln(sprintf('This service is an alias for the service <info>%s</info>', (string) $alias));
|
|
|
|
} else {
|
|
|
|
// edge case (but true for "service_container", all we have is the service itself
|
|
|
|
$service = $definition;
|
|
|
|
$output->writeln(sprintf('<comment>Service Id</comment> %s', $serviceId));
|
|
|
|
$output->writeln(sprintf('<comment>Class</comment> %s', get_class($service)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-30 15:35:41 +00:00
|
|
|
protected function outputParameters(OutputInterface $output, $parameters)
|
|
|
|
{
|
|
|
|
$output->writeln($this->getHelper('formatter')->formatSection('container', 'List of parameters'));
|
|
|
|
|
|
|
|
$terminalDimensions = $this->getApplication()->getTerminalDimensions();
|
|
|
|
$maxTerminalWidth = $terminalDimensions[0];
|
|
|
|
$maxParameterWidth = 0;
|
|
|
|
$maxValueWidth = 0;
|
|
|
|
|
|
|
|
// Determine max parameter & value length
|
|
|
|
foreach ($parameters as $parameter => $value) {
|
|
|
|
$parameterWidth = strlen($parameter);
|
|
|
|
if ($parameterWidth > $maxParameterWidth) {
|
|
|
|
$maxParameterWidth = $parameterWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
$valueWith = strlen($this->formatParameter($value));
|
|
|
|
if ($valueWith > $maxValueWidth) {
|
|
|
|
$maxValueWidth = $valueWith;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$maxValueWidth = min($maxValueWidth, $maxTerminalWidth - $maxParameterWidth - 1);
|
|
|
|
|
|
|
|
$formatTitle = '%-'.($maxParameterWidth + 19).'s %-'.($maxValueWidth + 19).'s';
|
|
|
|
$format = '%-'.$maxParameterWidth.'s %-'.$maxValueWidth.'s';
|
|
|
|
|
|
|
|
$output->writeln(sprintf($formatTitle, '<comment>Parameter</comment>', '<comment>Value</comment>'));
|
|
|
|
|
|
|
|
foreach ($parameters as $parameter => $value) {
|
|
|
|
$splits = str_split($this->formatParameter($value), $maxValueWidth);
|
|
|
|
|
|
|
|
foreach ($splits as $index => $split) {
|
|
|
|
if (0 === $index) {
|
|
|
|
$output->writeln(sprintf($format, $parameter, $split));
|
|
|
|
} else {
|
|
|
|
$output->writeln(sprintf($format, ' ', $split));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given an array of service IDs, this returns the array of corresponding
|
|
|
|
* Definition and Alias objects that those ids represent.
|
|
|
|
*
|
|
|
|
* @param string $serviceId The service id to resolve
|
2011-12-13 07:50:54 +00:00
|
|
|
*
|
2013-03-07 13:36:36 +00:00
|
|
|
* @return Definition|Alias
|
2011-03-10 15:09:40 +00:00
|
|
|
*/
|
2012-06-26 08:01:12 +01:00
|
|
|
protected function resolveServiceDefinition($serviceId)
|
2011-03-10 15:09:40 +00:00
|
|
|
{
|
|
|
|
if ($this->containerBuilder->hasDefinition($serviceId)) {
|
|
|
|
return $this->containerBuilder->getDefinition($serviceId);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Some service IDs don't have a Definition, they're simply an Alias
|
|
|
|
if ($this->containerBuilder->hasAlias($serviceId)) {
|
|
|
|
return $this->containerBuilder->getAlias($serviceId);
|
|
|
|
}
|
|
|
|
|
|
|
|
// the service has been injected in some special way, just return the service
|
|
|
|
return $this->containerBuilder->get($serviceId);
|
|
|
|
}
|
2012-09-16 16:15:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders list of tagged services grouped by tag
|
|
|
|
*
|
|
|
|
* @param OutputInterface $output
|
2013-03-07 13:36:36 +00:00
|
|
|
* @param Boolean $showPrivate
|
2012-09-16 16:15:14 +01:00
|
|
|
*/
|
|
|
|
protected function outputTags(OutputInterface $output, $showPrivate = false)
|
|
|
|
{
|
|
|
|
$tags = $this->containerBuilder->findTags();
|
|
|
|
asort($tags);
|
|
|
|
|
|
|
|
$label = 'Tagged services';
|
|
|
|
$output->writeln($this->getHelper('formatter')->formatSection('container', $label));
|
|
|
|
|
|
|
|
foreach ($tags as $tag) {
|
|
|
|
$serviceIds = $this->containerBuilder->findTaggedServiceIds($tag);
|
|
|
|
|
|
|
|
foreach ($serviceIds as $serviceId => $attributes) {
|
|
|
|
$definition = $this->resolveServiceDefinition($serviceId);
|
|
|
|
if ($definition instanceof Definition) {
|
|
|
|
if (!$showPrivate && !$definition->isPublic()) {
|
|
|
|
unset($serviceIds[$serviceId]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($serviceIds) === 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$output->writeln($this->getHelper('formatter')->formatSection('tag', $tag));
|
|
|
|
|
|
|
|
foreach ($serviceIds as $serviceId => $attributes) {
|
|
|
|
$output->writeln($serviceId);
|
|
|
|
}
|
|
|
|
|
|
|
|
$output->writeln('');
|
|
|
|
}
|
|
|
|
}
|
2013-03-30 15:35:41 +00:00
|
|
|
|
|
|
|
protected function formatParameter($value)
|
|
|
|
{
|
|
|
|
if (is_bool($value) || is_array($value) || (null === $value)) {
|
|
|
|
return json_encode($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
2011-03-10 15:09:40 +00:00
|
|
|
}
|