feature #11339 [FrameworkBundle] container:debug : list services if no service match exacly the name argument (agallou)
This PR was merged into the 2.6-dev branch.
Discussion
----------
[FrameworkBundle] container:debug : list services if no service match exacly the name argument
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #11303
| License | MIT
| Doc PR |
If we launch the command "container:debug log" and there is no
service nammed log, it will print something like this :
```
[0] logger
[1] monolog.handler.console
[2] monolog.handler.debug
```
After the service has been chosen, usual container:debug informations
are displayed.
Commits
-------
16201b6
[FrameworkBundle] container:debug : list services if no service match exacly the name argument
This commit is contained in:
commit
d318e09eef
@ -19,6 +19,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||
|
||||
/**
|
||||
* A console command for retrieving information about services.
|
||||
@ -109,6 +110,7 @@ EOF
|
||||
$options = array('tag' => $tag, 'show_private' => $input->getOption('show-private'));
|
||||
} elseif ($name = $input->getArgument('name')) {
|
||||
$object = $this->getContainerBuilder();
|
||||
$name = $this->findProperServiceName($input, $output, $object, $name);
|
||||
$options = array('id' => $name);
|
||||
} else {
|
||||
$object = $this->getContainerBuilder();
|
||||
@ -119,6 +121,10 @@ EOF
|
||||
$options['format'] = $input->getOption('format');
|
||||
$options['raw_text'] = $input->getOption('raw');
|
||||
$helper->describe($output, $object, $options);
|
||||
|
||||
if (!$input->getArgument('name') && $input->isInteractive()) {
|
||||
$output->writeln('To search for a service, re-run this command with a search term. <comment>container:debug log</comment>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -171,4 +177,31 @@ EOF
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
private function findProperServiceName(InputInterface $input, OutputInterface $output, ContainerBuilder $builder, $name)
|
||||
{
|
||||
if ($builder->has($name) || !$input->isInteractive()) {
|
||||
return $name;
|
||||
}
|
||||
|
||||
$question = new ChoiceQuestion('Choose a number for more information on the service', $this->findServiceIdsContaining($builder, $name));
|
||||
$question->setErrorMessage('Service %s is invalid.');
|
||||
|
||||
return $this->getHelper('question')->ask($input, $output, $question);
|
||||
}
|
||||
|
||||
private function findServiceIdsContaining(ContainerBuilder $builder, $name)
|
||||
{
|
||||
$serviceIds = $builder->getServiceIds();
|
||||
$foundServiceIds = array();
|
||||
$name = strtolower($name);
|
||||
foreach ($serviceIds as $serviceId) {
|
||||
if (false === strpos($serviceId, $name)) {
|
||||
continue;
|
||||
}
|
||||
$foundServiceIds[] = $serviceId;
|
||||
}
|
||||
|
||||
return $foundServiceIds;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user