function DevelServicesCommand::__invoke
Lists the services in the container.
File
-
src/
Command/ DevelServicesCommand.php, line 41
Class
- DevelServicesCommand
- Lists the services in the container.
Namespace
Drupal\devel\CommandCode
public function __invoke(OutputInterface $output, #[Argument('Optional prefix to filter the service list by.')] ?string $prefix = NULL, #[Option('The output format: table, json or yaml.')] string $format = 'table') : int {
// Both Drupal's container and Symfony's container builder have this method,
// though no interface that they share declares it.
// @phpstan-ignore method.notFound
$services = $this->container
->getServiceIds();
if ($prefix !== NULL && $prefix !== '') {
$services = preg_grep(sprintf('/%s/', $prefix), $services);
}
if (empty($services)) {
throw new \RuntimeException('No container services found.');
}
sort($services);
$rows = array_map(static fn(string $id): array => [
'id' => $id,
], $services);
$this->writeRows($output, $rows, [
'id' => 'Id',
], $format);
return Command::SUCCESS;
}