diff --git a/src/Command/Debug/ContainerCommand.php b/src/Command/Debug/ContainerCommand.php index 03255a54f..d54fa6564 100644 --- a/src/Command/Debug/ContainerCommand.php +++ b/src/Command/Debug/ContainerCommand.php @@ -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']); } @@ -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'); @@ -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'); } @@ -142,11 +147,15 @@ 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()]; @@ -154,6 +163,30 @@ private function getServiceList() 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]); diff --git a/src/Command/Debug/PluginCommand.php b/src/Command/Debug/PluginCommand.php index bc6e9096b..728c90083 100644 --- a/src/Command/Debug/PluginCommand.php +++ b/src/Command/Debug/PluginCommand.php @@ -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) {