function DevelCommands::services

Same name in this branch
  1. 5.x src/Drush/Commands/DevelCommands.php \Drupal\devel\Drush\Commands\DevelCommands::services()
Same name in other branches
  1. 4.x src/Commands/DevelCommands.php \Drupal\devel\Commands\DevelCommands::services()

Get a list of available container services.

@command devel:services

@aliases devel-container-services,dcs,devel-services @usage drush devel-services Gets a list of all available container services @usage drush dcs plugin.manager Get all services containing "plugin.manager"

Parameters

string $prefix: Optional prefix to filter the service list by.

array $options: An array of options (is this used?)

Return value

array The container service ids.

File

src/Commands/DevelCommands.php, line 322

Class

DevelCommands
Class DevelCommands.

Namespace

Drupal\devel\Commands

Code

public function services($prefix = NULL, array $options = [
    'format' => 'yaml',
]) {
    $container = $this->getContainer();
    // Get a list of all available service IDs.
    $services = $container->getServiceIds();
    // If there is a prefix, try to find matches.
    if (isset($prefix)) {
        $services = preg_grep("/{$prefix}/", $services);
    }
    if (empty($services)) {
        throw new \Exception(dt('No container services found.'));
    }
    sort($services);
    return $services;
}