class DevelServicesCommand
Attributes
#[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: [
'id',
])]
#[CLI\Formatter(returnType: RowsOfFields::class, defaultFormatter: 'table')]
Hierarchy
- class \Drupal\devel\Drush\Commands\DevelServicesCommand uses \Drush\Commands\AutowireTrait, \Drush\Formatters\FormatterTrait extends \Symfony\Component\Console\Command\Command
Expanded class hierarchy of DevelServicesCommand
1 file declares its use of DevelServicesCommand
- DevelCommandsTest.php in tests/
src/ Functional/ DevelCommandsTest.php
File
-
src/
Drush/ Commands/ DevelServicesCommand.php, line 18
Namespace
Drupal\devel\Drush\CommandsView source
final class DevelServicesCommand extends Command {
use AutowireTrait;
use FormatterTrait;
public const NAME = 'devel:services';
public function __construct(protected FormatterManager $formatterManager) {
parent::__construct();
}
protected function configure() : void {
$this->addArgument('prefix', InputArgument::OPTIONAL, 'Optional prefix to filter the service list by.')
->addUsage('dcs plugin.manager');
}
public function execute(InputInterface $input, OutputInterface $output) : int {
$data = $this->doExecute($input, $output);
$this->writeFormattedOutput($input, $output, $data);
return Command::SUCCESS;
}
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);
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary |
|---|---|---|---|
| DevelServicesCommand::configure | protected | function | |
| DevelServicesCommand::doExecute | protected | function | |
| DevelServicesCommand::execute | public | function | |
| DevelServicesCommand::NAME | public | constant | |
| DevelServicesCommand::__construct | public | function |