|
12 | 12 | namespace Symfony\Bundle\FrameworkBundle\Command;
|
13 | 13 |
|
14 | 14 | use Symfony\Bundle\FrameworkBundle\Console\Descriptor\Descriptor;
|
| 15 | +use Symfony\Component\Console\Completion\CompletionInput; |
| 16 | +use Symfony\Component\Console\Completion\CompletionSuggestions; |
15 | 17 | use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
16 | 18 | use Symfony\Component\Console\Input\InputArgument;
|
17 | 19 | use Symfony\Component\Console\Input\InputInterface;
|
18 | 20 | use Symfony\Component\Console\Input\InputOption;
|
19 | 21 | use Symfony\Component\Console\Output\OutputInterface;
|
20 | 22 | use Symfony\Component\Console\Style\SymfonyStyle;
|
| 23 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
21 | 24 | use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
|
22 | 25 |
|
23 | 26 | /**
|
@@ -77,11 +80,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
|
77 | 80 | $errorIo = $io->getErrorStyle();
|
78 | 81 |
|
79 | 82 | $builder = $this->getContainerBuilder($this->getApplication()->getKernel());
|
80 |
| - $serviceIds = $builder->getServiceIds(); |
81 |
| - $serviceIds = array_filter($serviceIds, [$this, 'filterToServiceTypes']); |
| 83 | + $serviceIds = $this->getServices($builder); |
82 | 84 |
|
83 | 85 | if ($search = $input->getArgument('search')) {
|
84 |
| - $searchNormalized = preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', '', $search); |
| 86 | + $searchNormalized = $this->getSearchNormalized($search); |
| 87 | + |
85 | 88 | $serviceIds = array_filter($serviceIds, function ($serviceId) use ($searchNormalized) {
|
86 | 89 | return false !== stripos(str_replace('\\', '', $serviceId), $searchNormalized) && !str_starts_with($serviceId, '.');
|
87 | 90 | });
|
@@ -162,4 +165,33 @@ private function getFileLink(string $class): string
|
162 | 165 |
|
163 | 166 | return (string) $this->fileLinkFormatter->format($r->getFileName(), $r->getStartLine());
|
164 | 167 | }
|
| 168 | + |
| 169 | + public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void |
| 170 | + { |
| 171 | + $builder = $this->getContainerBuilder($this->getApplication()->getKernel()); |
| 172 | + $serviceIds = $this->getServices($builder); |
| 173 | + |
| 174 | + $searchNormalized = $this->getSearchNormalized($input->getArgument('search')); |
| 175 | + |
| 176 | + $serviceIds = array_filter($serviceIds, function ($serviceId) use ($searchNormalized) { |
| 177 | + $serviceId = str_replace('\\', '', $serviceId); |
| 178 | + $serviceId = str_replace('.', '', $serviceId); |
| 179 | + |
| 180 | + return false !== stripos($serviceId, $searchNormalized) && !str_starts_with($serviceId, '.'); |
| 181 | + }); |
| 182 | + |
| 183 | + $suggestions->suggestValues($serviceIds); |
| 184 | + } |
| 185 | + |
| 186 | + private function getServices(ContainerBuilder $builder): array |
| 187 | + { |
| 188 | + $serviceIds = $builder->getServiceIds(); |
| 189 | + |
| 190 | + return array_filter($serviceIds, [$this, 'filterToServiceTypes']); |
| 191 | + } |
| 192 | + |
| 193 | + private function getSearchNormalized(string $search): string |
| 194 | + { |
| 195 | + return preg_replace('/[^a-zA-Z0-9\x7f-\xff]++/', '', $search); |
| 196 | + } |
165 | 197 | }
|
0 commit comments