Skip to content

Commit

Permalink
[debug:cotainer] Add --tag option to filter services. (#3616)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmolivas authored Dec 5, 2017
1 parent b19e75d commit 615cd40
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
43 changes: 38 additions & 5 deletions src/Command/Debug/ContainerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ protected function configure()
'arguments',
InputArgument::OPTIONAL,
$this->trans('commands.debug.container.arguments.arguments')
)->addOption(
'tag',
null,
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL,
$this->trans('commands.debug.container.options.tag')
)
->setAliases(['dco']);
}
Expand All @@ -60,6 +65,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$io = new DrupalStyle($input, $output);
$service = $input->getArgument('service');
$parameters = $input->getOption('parameters');
$tag = $input->getOption('tag');
$method = $input->getArgument('method');
$args = $input->getArgument('arguments');

Expand Down Expand Up @@ -90,8 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->trans('commands.debug.container.messages.service-id'),
$this->trans('commands.debug.container.messages.class-name')
];

$tableRows = $this->getServiceList();
$tableRows = $this->getServiceList($tag);
$io->table($tableHeader, $tableRows, 'compact');
}

Expand Down Expand Up @@ -142,18 +147,46 @@ private function getCallbackReturnList($service, $method, $args)
];
return $serviceDetail;
}
private function getServiceList()

private function getServiceList($tag)
{
if ($tag) {
return $this->getServiceListByTag($tag);
}

$services = [];
$serviceDefinitions = $this->container
->getParameter('console.service_definitions');
$serviceDefinitions = $this->container->getDefinitions();

foreach ($serviceDefinitions as $serviceId => $serviceDefinition) {
$services[] = [$serviceId, $serviceDefinition->getClass()];
}
usort($services, [$this, 'compareService']);
return $services;
}

private function getServiceListByTag($tag) {
$services = [];
$serviceIds = [];
$serviceDefinitions = $this->container->getDefinitions();

foreach ($tag as $tagId) {
$serviceIds = array_merge(
$serviceIds,
array_keys($this->container->findTaggedServiceIds($tagId))
);
}

foreach ($serviceIds as $serviceId) {
$serviceDefinition = $serviceDefinitions[$serviceId];
if ($serviceDefinition) {
$services[] = [$serviceId, $serviceDefinition->getClass()];
}
}

usort($services, [$this, 'compareService']);
return $services;
}

private function compareService($a, $b)
{
return strcmp($a[0], $b[0]);
Expand Down
3 changes: 1 addition & 2 deletions src/Command/Debug/PluginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->trans('commands.debug.plugin.table-headers.plugin-type-class')
];
$tableRows = [];
$serviceDefinitions = $this->container
->getParameter('console.service_definitions');
$serviceDefinitions = $this->container->getDefinitions();

foreach ($serviceDefinitions as $serviceId => $serviceDefinition) {
if (strpos($serviceId, 'plugin.manager.') === 0) {
Expand Down

0 comments on commit 615cd40

Please sign in to comment.