Same filename in this branch
- 5.x src/Drush/Commands/DevelServicesCommand.php
Namespace
Drupal\devel\Command
File
-
src/Command/DevelServicesCommand.php
View source
<?php
declare (strict_types=1);
namespace Drupal\devel\Command;
use Symfony\Component\Console\Attribute\Argument;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Attribute\Option;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\DependencyInjection\ContainerInterface;
class DevelServicesCommand {
use FormatTrait;
public const NAME = 'devel:services';
public function __construct(#[Autowire(service: 'service_container')] protected readonly ContainerInterface $container) {
}
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 {
$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;
}
}
Classes