function DevelCommands::services

Same name in this branch
  1. 5.x src/Commands/DevelCommands.php \Drupal\devel\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.

File

src/Drush/Commands/DevelCommands.php, line 283

Class

DevelCommands

Namespace

Drupal\devel\Drush\Commands

Code

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