function DevelServicesCommand::doExecute

1 call to DevelServicesCommand::doExecute()
DevelServicesCommand::execute in src/Drush/Commands/DevelServicesCommand.php

File

src/Drush/Commands/DevelServicesCommand.php, line 53

Class

DevelServicesCommand
#[AsCommand(name: self::NAME, description: 'Get a list of available container services.', aliases: [ 'devel-container-services', 'dcs', 'devel-services', ])] #[CLI\FieldLabels(labels: [ 'id' => 'Id', ])] #[CLI\DefaultTableFields(fields:…

Namespace

Drupal\devel\Drush\Commands

Code

protected function doExecute(InputInterface $input, OutputInterface $output) : RowsOfFields {
  $prefix = $input->getArgument('prefix');
  $services = \Drupal::getContainer()->getServiceIds();
  if ($prefix !== NULL && $prefix !== '') {
    $services = preg_grep(sprintf('/%s/', $prefix), $services);
  }
  if (empty($services)) {
    throw new \RuntimeException(dt('No container services found.'));
  }
  sort($services);
  foreach ($services as $service) {
    $all[]['id'] = $service;
  }
  return new RowsOfFields($all);
}