You are here

function drush_devel_container_services in Devel 8

Same name and namespace in other branches
  1. 8.3 drush/devel.drush8.inc \drush_devel_container_services()
  2. 8.2 drush/devel.drush8.inc \drush_devel_container_services()

Command callback to list available container services.

File

drush/devel.drush8.inc, line 255
This file is only used by Drush8. Drush9 discovers its commands via tagged service(s) in devel.services.yml. Also see classes in src/Commands.

Code

function drush_devel_container_services($prefix = NULL) {
  $container = Drupal::getContainer();
  if (empty($container)) {
    return drush_set_error(dt('No container was found.'));
  }

  // 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)) {
    return drush_log(dt('No container services found.'), 'ok');
  }
  sort($services);
  return $services;
}