You are here

public function DevelCommands::services in Devel 8.2

Same name and namespace in other branches
  1. 8.3 src/Commands/DevelCommands.php \Drupal\devel\Commands\DevelCommands::services()
  2. 8 src/Commands/DevelCommands.php \Drupal\devel\Commands\DevelCommands::services()
  3. 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

$prefix A prefix to filter the service list by.:

Return value

array

File

src/Commands/DevelCommands.php, line 246

Class

DevelCommands
For commands that are parts of modules, Drush expects to find commandfiles in __MODULE__/src/Commands, and the namespace is Drupal/__MODULE__/Commands.

Namespace

Drupal\devel\Commands

Code

public function services($prefix = NULL, $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;
}