function drush_get_engines

8.0.x engines.inc drush_get_engines($engine_type)
6.x engines.inc drush_get_engines($engine_type)
7.x engines.inc drush_get_engines($engine_type)
3.x drush.inc drush_get_engines($type)
4.x drush.inc drush_get_engines($type)
5.x drush.inc drush_get_engines($engine_type)
master engines.inc drush_get_engines($engine_type)

Return a structured array of engines of a specific type.

Engines are pluggable subsystems. Each engine of a specific type will implement the same set of API functions and perform the same high-level task using a different backend or approach.

This function/hook is useful when you have a selection of several mutually exclusive options to present to a user to select from.

Other commands are able to extend this list and provide their own engines. The hook can return useful information to help users decide which engine they need, such as description or list of available engine options.

The engine path element will automatically default to a subdirectory (within the directory of the commandfile that implemented the hook) with the name of the type of engine - e.g. an engine "wget" of type "handler" provided by the "pm" commandfile would automatically be found if the file "pm/handler/wget.inc" exists and a specific path is not provided.

Parameters

$engine_type: The type of engine.

Return value

A structured array of engines.

7 calls to drush_get_engines()
drush_engine_topic_command in includes/engines.inc
Implementation of command hook for docs-output-formats
drush_include_engine in includes/engines.inc
Include the engine code for a specific named engine of a certain type.
drush_load_command_engine in includes/engines.inc
Selects and loads an engine implementing the given type.
drush_load_engine in includes/engines.inc
Loads and validate an engine of the given type.
drush_merge_engine_data in includes/engines.inc
Add command structure info from each engine type back into the command.

... See full list

File

includes/engines.inc, line 59
The drush engines API implementation and helpers.

Code

function drush_get_engines($engine_type) {
  $info = drush_get_engine_types_info();
  if (!isset($info[$engine_type])) {
    return drush_set_error('DRUSH_UNKNOWN_ENGINE_TYPE', dt('Unknown engine type !engine_type', array('!engine_type' => $engine_type)));
  }

  $engines = array(
    'info' => $info[$engine_type],
    'engines' => array(),
  );
  $list = drush_commandfile_list();
  $hook = 'drush_engine_' . str_replace('-', '_', $engine_type);
  foreach ($list as $commandfile => $path) {
    if (drush_command_hook($commandfile, $hook)) {
      $function = $commandfile . '_' . $hook;
      $result = $function();
      foreach ($result as $engine_name => $engine) {
        // Add some defaults.
        $engine += array(
          'commandfile' => $commandfile,
          'options' => array(),
          'sub-options' => array(),
          'drupal dependencies' => array(),
        );

        // Legacy engines live in a subdirectory
        // of the commandfile that declared them.
        $engine_path = sprintf("%s/%s", dirname($path), $engine_type);
        if (file_exists($engine_path)) {
          $engine['path'] = $engine_path;
        }
        // Build engine class name, in case the engine doesn't provide it.
        // The class name is based on the engine type and name, converted
        // from snake_case to CamelCase.
        // For example for type 'package_handler' and engine 'git_drupalorg'
        // the class is \Drush\PackageHandler\GitDrupalorg
        elseif (!isset($engine['class'])) {
          $parts = array();
          $parts[] = '\Drush';
          $parts[] = str_replace(' ', '', ucwords(strtr($engine_type, '_', ' ')));
          $parts[] = str_replace(' ', '', ucwords(strtr($engine_name, '_', ' ')));
          $engine['class'] = implode('\\', $parts);
        }

        $engines['engines'][$engine_name] = $engine;
      }
    }
  }

  return $engines;
}