class DevelServicesCommand

Same name in this branch
  1. 5.x src/Drush/Commands/DevelServicesCommand.php \Drupal\devel\Drush\Commands\DevelServicesCommand

Lists the services in the container.

Attributes

#[AsCommand(name: self::NAME, description: 'Get a list of available container services.', aliases: [ 'devel-container-services', 'dcs', 'devel-services', ], usages: [ 'devel:services plugin.manager', 'devel:services --format=json', ])]

Hierarchy

Expanded class hierarchy of DevelServicesCommand

2 files declare their use of DevelServicesCommand
DevelCommandsKernelTest.php in tests/src/Kernel/DevelCommandsKernelTest.php
DevelServicesCommand.php in src/Drush/Commands/DevelServicesCommand.php

File

src/Command/DevelServicesCommand.php, line 18

Namespace

Drupal\devel\Command
View source
class DevelServicesCommand {
  use FormatTrait;
  public const NAME = 'devel:services';
  public function __construct(#[Autowire(service: 'service_container')] protected readonly ContainerInterface $container) {
  }
  
  /**
   * Lists the services in the 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 {
    // 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;
  }

}

Members

Title Sort descending Modifiers Object type Summary
DevelServicesCommand::NAME public constant
DevelServicesCommand::__construct public function
DevelServicesCommand::__invoke public function Lists the services in the container.
FormatTrait::writeRows protected function Writes rows in the requested format.