From 83f5dfb544ceb91758615f5087ea90ca77f0601e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 2 Oct 2018 19:22:50 +0200 Subject: [PATCH] [FrameworkBundle] dont suggest hidden services in debug:container and debug:autow commands --- .../FrameworkBundle/Command/ContainerDebugCommand.php | 11 +++++++---- .../Command/DebugAutowiringCommand.php | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php index bba19d60e82e..d25ffaf9b157 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ContainerDebugCommand.php @@ -132,7 +132,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } elseif ($tag = $input->getOption('tag')) { $options = array('tag' => $tag); } elseif ($name = $input->getArgument('name')) { - $name = $this->findProperServiceName($input, $errorIo, $object, $name); + $name = $this->findProperServiceName($input, $errorIo, $object, $name, $input->getOption('show-hidden')); $options = array('id' => $name); } else { $options = array(); @@ -208,13 +208,13 @@ protected function getContainerBuilder() return $this->containerBuilder = $container; } - private function findProperServiceName(InputInterface $input, SymfonyStyle $io, ContainerBuilder $builder, $name) + private function findProperServiceName(InputInterface $input, SymfonyStyle $io, ContainerBuilder $builder, string $name, bool $showHidden) { if ($builder->has($name) || !$input->isInteractive()) { return $name; } - $matchingServices = $this->findServiceIdsContaining($builder, $name); + $matchingServices = $this->findServiceIdsContaining($builder, $name, $showHidden); if (empty($matchingServices)) { throw new InvalidArgumentException(sprintf('No services found that match "%s".', $name)); } @@ -224,11 +224,14 @@ private function findProperServiceName(InputInterface $input, SymfonyStyle $io, return $io->choice('Select one of the following services to display its information', $matchingServices, $default); } - private function findServiceIdsContaining(ContainerBuilder $builder, $name) + private function findServiceIdsContaining(ContainerBuilder $builder, string $name, bool $showHidden) { $serviceIds = $builder->getServiceIds(); $foundServiceIds = array(); foreach ($serviceIds as $serviceId) { + if (!$showHidden && 0 === strpos($serviceId, '.')) { + continue; + } if (false === stripos($serviceId, $name)) { continue; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php index 41c9cc9fabc1..7ef48c78b106 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/DebugAutowiringCommand.php @@ -66,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($search = $input->getArgument('search')) { $serviceIds = array_filter($serviceIds, function ($serviceId) use ($search) { - return false !== stripos($serviceId, $search); + return false !== stripos($serviceId, $search) && 0 !== strpos($serviceId, '.'); }); if (empty($serviceIds)) {