function drush_select_engine

8.0.x engines.inc drush_select_engine($config, $engine_info, $preferred = NULL)
7.x engines.inc drush_select_engine($config, $engine_info, $preferred = NULL)
master engines.inc drush_select_engine($config, $engine_info, $preferred = NULL)

Selects an engine between the available ones.

Precedence:

  • preferred engine, if available.
  • user supplied engine via cli.
  • default engine from engine type / command declaration.
  • the first engine available.

Parameters

array $config: Engine type configuration. My be overridden in command declaration.

array $engine_info: Engine type declaration.

string $default: Preferred engine.

Return value

string Selected engine.

3 calls to drush_select_engine()
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.

File

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

Code

function drush_select_engine($config, $engine_info, $preferred = NULL) {
  $engines = array_keys($engine_info['engines']);

  if (in_array($preferred, $engines)) {
    return $preferred;
  }

  if (!empty($config['option'])) {
    $engine = drush_get_option($config['option'], FALSE);
    if ($engine && in_array($engine, $engines)) {
      return $engine;
    }
  }

  if (isset($config['default']) && in_array($config['default'], $engines)) {
    return $config['default'];
  }

  return current($engines);
}