Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[debug:cotainer] Add --tag option to filter services. #3616

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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