Drush: includes/engines.inc Source File

  1. 7.x doxygen/html/engines_8inc_source.html
  2. master doxygen/html/engines_8inc_source.html
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * @file
5  * The drush engines API implementation and helpers.
6  */
7 
8 /**
9  * Obtain all engine types info and normalize with defaults.
10  *
12  */
14  $info = drush_command_invoke_all('drush_engine_type_info');
15  foreach ($info as $type => $data) {
16  $info[$type] += array(
17  'description' => '',
18  'option' => FALSE,
19  'default' => NULL,
20  'options' => array(),
21  'sub-options' => array(),
22  'config-aliases' => array(),
23  'add-options-to-command' => FALSE,
24  'combine-help' => FALSE,
25  );
26  }
27 
28  return $info;
29 }
30 
31 /**
32  * Return a structured array of engines of a specific type.
33  *
34  * Engines are pluggable subsystems. Each engine of a specific type will
35  * implement the same set of API functions and perform the same high-level
36  * task using a different backend or approach.
37  *
38  * This function/hook is useful when you have a selection of several mutually
39  * exclusive options to present to a user to select from.
40  *
41  * Other commands are able to extend this list and provide their own engines.
42  * The hook can return useful information to help users decide which engine
43  * they need, such as description or list of available engine options.
44  *
45  * The engine path element will automatically default to a subdirectory (within
46  * the directory of the commandfile that implemented the hook) with the name of
47  * the type of engine - e.g. an engine "wget" of type "handler" provided by
48  * the "pm" commandfile would automatically be found if the file
49  * "pm/handler/wget.inc" exists and a specific path is not provided.
50  *
51  * @param $engine_type
52  * The type of engine.
53  *
54  * @return
55  * A structured array of engines.
56  */
57 function drush_get_engines($engine_type) {
59  if (!isset($info[$engine_type])) {
60  return drush_set_error('DRUSH_UNKNOWN_ENGINE_TYPE', dt('Unknown engine type !engine_type', array('!engine_type' => $engine_type)));
61  }
62 
63  $engines = array(
64  'info' => $info[$engine_type],
65  'engines' => array(),
66  );
67  $list = drush_commandfile_list();
68  $hook = 'drush_engine_' . str_replace('-', '_', $engine_type);
69  foreach ($list as $commandfile => $path) {
70  if (drush_command_hook($commandfile, $hook)) {
71  $function = $commandfile . '_' . $hook;
72  $result = $function();
73  foreach ($result as $key => $engine) {
74  // Add some defaults
75  $engine += array(
76  'commandfile' => $commandfile,
77  // Engines by default live in a subdirectory of the commandfile that
78  // declared them, named as per the type of engine they are.
79  'path' => sprintf("%s/%s", dirname($path), $engine_type),
80  'options' => array(),
81  'sub-options' => array(),
82  'drupal dependencies' => array(),
83  );
84  $engines['engines'][$key] = $engine;
85  }
86  }
87  }
88  return $engines;
89 }
90 
91 /**
92  * Take a look at all of the available engines,
93  * and create topic commands for each one that
94  * declares a topic.
95  */
97  $items = array();
99  foreach ($info as $engine => $data) {
100  if (array_key_exists('topic', $data)) {
101  $items[$data['topic']] = array(
102  'description' => $data['description'],
103  'hidden' => TRUE,
104  'topic' => TRUE,
105  'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
106  'callback' => 'drush_engine_topic_command',
107  'callback arguments' => array($engine),
108  );
109  }
110  }
111  return $items;
112 }
113 
114 /**
115  * Include, instantiate and validate command engines.
116  *
117  * @return FALSE if a engine doesn't validate.
118  */
119 function drush_load_command_engines($command) {
120  $result = TRUE;
121  foreach ($command['engines'] as $engine_type => $config) {
122  $result = drush_load_command_engine($command, $engine_type);
123  // Stop loading engines if any of them fails.
124  if ($result === FALSE) {
125  break;
126  }
127  }
128  return $result;
129 }
130 
131 /**
132  * Returns engine config supplied in the command definition.
133  */
134 function drush_get_command_engine_config($command, $engine_type, $metadata = array()) {
135  if (isset($command['engines'][$engine_type])) {
136  $metadata = array_merge($metadata, $command['engines'][$engine_type]);
137  }
138  return $metadata;
139 }
140 
141 /**
142  * Selects and loads an engine implementing the given type.
143  *
144  * Loaded engines are stored as a context.
145  */
146 function drush_load_command_engine($command, $engine_type, $metadata = array()) {
147  drush_log(dt("Loading !engine engine.", array('!engine' => $engine_type), 'bootstrap'));
148 
149  $config = drush_get_command_engine_config($command, $engine_type, $metadata);
150  $engine_info = drush_get_engines($engine_type);
151  $selected_engine = drush_get_user_selected_engine($config, $engine_info);
152  $version = drush_drupal_major_version();
153 
154  $context = $engine_type . '_engine_' . $selected_engine . '_' . $version;
155  $instance = drush_get_context($context, FALSE);
156  if ($instance != FALSE) {
157  drush_set_engine($engine_type, $instance);
158  }
159  else {
160  $instance = drush_load_engine($engine_type, $selected_engine, NULL, NULL, $config);
161  $command['bootstrap_errors']["FOO"] = "BAR";
162  if ($instance == FALSE) {
163  return FALSE;
164  }
165  drush_set_context($context, $instance);
166  }
167  return $instance;
168 }
169 
170 /**
171  * Add command structure info from each engine type back into the command.
172  */
173 function drush_merge_engine_data(&$command) {
174  // First remap engine data from the shortcut location
175  // ($command['engine_type']) to the standard location
176  // ($command['engines']['engine_type'])
177  $info = drush_get_engine_types_info();
178  foreach ($info as $engine_type => $info) {
179  if (isset($command[$engine_type])) {
180  $config = $command[$engine_type];
181  foreach ($info['config-aliases'] as $engine_option_alias_name => $engine_option_standard_name) {
182  if (array_key_exists($engine_option_alias_name, $config)) {
183  $config[$engine_option_standard_name] = $config[$engine_option_alias_name];
184  unset($config[$engine_option_alias_name]);
185  }
186  }
187  // Convert single string values of 'require-engine-capability' to an array.
188  if (isset($config['require-engine-capability']) && is_string($config['require-engine-capability'])) {
189  $config['require-engine-capability'] = array($config['require-engine-capability']);
190  }
191  $command['engines'][$engine_type] = $config;
192  }
193  }
194 
195  foreach ($command['engines'] as $engine_type => $config) {
196  // Normalize engines structure.
197  if (!is_array($config)) {
198  unset($command['engines'][$engine_type]);
199  $command['engines'][$config] = array();
200  $engine_type = $config;
201  }
202 
203  // Get all implementations for this engine type.
204  $engine_info = drush_get_engines($engine_type);
205  if ($engine_info === FALSE) {
206  return FALSE;
207  }
208 
209  // Complete command-declared engine type with default info.
210  $command['engines'][$engine_type] += $engine_info['info'];
211  $config = $command['engines'][$engine_type];
212 
213  $engine_data = array();
214 
215  // If there's a single implementation for this engine type, it will be
216  // loaded by default, and makes no sense to provide a command line option
217  // to select the only flavor (ie. --release_info=updatexml), so we won't
218  // add an option in this case.
219  // Additionally, depending on the command, it may be convenient to extend
220  // the command with the engine options.
221  if (count($engine_info['engines']) == 1) {
222  if ($config['add-options-to-command'] !== FALSE) {
223  // Add options and suboptions of the engine type and
224  // the sole implementation.
225  $engine = key($engine_info['engines']);
226  $data = $engine_info['engines'][$engine];
227  $engine_data += array(
228  'options' => $config['options'] + $data['options'],
229  'sub-options' => $config['sub-options'] + $data['sub-options'],
230  );
231  }
232  }
233  // Otherwise, provide a command option to choose between engines and add
234  // the engine options and sub-options.
235  else {
236  // Add engine type global options and suboptions.
237  $engine_data += array(
238  'options' => $config['options'],
239  'sub-options' => $config['sub-options'],
240  );
241 
242  // If the 'combine-help' flag is set in the engine config,
243  // then we will combine all of the help items into the help
244  // text for $config['option'].
245  $combine_help = $config['combine-help'];
246  $combine_help_data = array();
247 
248  // Process engines in order. First the default engine, the rest alphabetically.
249  $default = drush_find_engine_to_use($config, $engine_info);
250  $engines = array_keys($engine_info['engines']);
251  asort($engines);
252  array_unshift($engines, $default);
253  $engines = array_unique($engines);
254  foreach ($engines as $engine) {
255  $data = $engine_info['engines'][$engine];
256  // Check to see if the command requires any particular
257  // capabilities. If no capabilities are required, then
258  // all engines are acceptable.
259  $engine_is_usable = TRUE;
260  if (array_key_exists('require-engine-capability', $config)) {
261  // See if the engine declares that it provides any
262  // capabilities. If no capabilities are listed, then
263  // it is assumed that the engine can satisfy all requirements.
264  if (array_key_exists('engine-capabilities', $data)) {
265  $engine_is_usable = FALSE;
266  // If 'require-engine-capability' is TRUE instead of an array,
267  // then only engines that are universal (do not declare any
268  // particular capabilities) are usable.
269  if (is_array($config['require-engine-capability'])) {
270  foreach ($config['require-engine-capability'] as $required) {
271  // We need an engine that provides any one of the requirements.
272  if (in_array($required, $data['engine-capabilities'])) {
273  $engine_is_usable = TRUE;
274  }
275  }
276  }
277  }
278  }
279  if ($engine_is_usable) {
280  $command['engines'][$engine_type]['usable'][] = $engine;
281  if (!isset($data['hidden'])) {
282  $option = $config['option'] . '=' . $engine;
283  $engine_data['options'][$option]['description'] = array_key_exists('description', $data) ? $data['description'] : NULL;
284  if ($combine_help) {
285  $engine_data['options'][$option]['hidden'] = TRUE;
286  if (drush_get_context('DRUSH_VERBOSE') || ($default == $engine) || !isset($data['verbose-only'])) {
287  $combine_help_data[$engine] = $engine . ': ' . $data['description'];
288  }
289  }
290  if (isset($data['options'])) {
291  $engine_data['sub-options'][$option] = $data['options'];
292  }
293  if (isset($data['sub-options'])) {
294  $engine_data['sub-options'] += $data['sub-options'];
295  }
296  }
297  }
298  }
299  if (!empty($combine_help_data)) {
300  $engine_selection_option = $config['option'];
301  if (!is_array($engine_data['options'][$engine_selection_option])) {
302  $engine_data['options'][$engine_selection_option] = array('description' => $config['options'][$engine_selection_option]);
303  }
304  if (drush_get_context('DRUSH_VERBOSE')) {
305  $engine_data['options'][$engine_selection_option]['description'] .= "\n" . dt("All available values are:") . "\n - " . implode("\n - ", $combine_help_data) . "\n";
306  }
307  else {
308  $engine_data['options'][$engine_selection_option]['description'] .= " " . dt("Available: ") . implode(', ', array_keys($combine_help_data)) . ". ";
309  }
310  $engine_data['options'][$engine_selection_option]['description'] .= dt("Default is !default.", array('!default' => $default));
311  }
312  else {
313  // If the help options are not combined, then extend the
314  // default engine description.
315  $desc = $engine_info['engines'][$default]['description'];
316  $engine_info['engines'][$default]['description'] = dt('Default !type engine.', array('!type' => $engine_type)) . ' ' . $desc;
317  }
318  }
319  $command = array_merge_recursive($command, $engine_data);
320  }
321 }
322 
323 /**
324  * Implementation of command hook for docs-output-formats
325  */
326 function drush_engine_topic_command($engine) {
327  $engine_instances = drush_get_engines($engine);
328  $option = $engine_instances['info']['option'];
329 
330  if (isset($engine_instances['info']['topic-file'])) {
331  // To do: put this file next to the commandfile that defines the
332  // engine type, not in the core docs directory.
333  $docs_dir = drush_get_context('DOC_PREFIX', DRUSH_BASE_PATH);
334  $path = $engine_instances['info']['topic-file'];
335  $docs_file = (drush_is_absolute_path($path) ? '' : $docs_dir . '/') . $path;
336  $doc_text = drush_html_to_text(file_get_contents($docs_file));
337  }
338  elseif (isset($engine_instances['info']['topic-text'])) {
339  $doc_text = $engine_instances['info']['topic-text'];
340  }
341  else {
342  return drush_set_error('DRUSH_BAD_ENGINE_TOPIC', dt("The engine !engine did not define its topic command correctly.", array('!engine' => $engine)));
343  }
344 
345  // Look at each instance of the engine; if it has an html
346  // file in the the 'topics' folder named after itself, then
347  // include the file contents in the engine topic text.
348  $instances = $engine_instances['engines'];
349  ksort($instances);
350  foreach ($instances as $instance => $config) {
351  if (isset($config['description'])) {
352  $doc_text .= "\n\n::: --$option=$instance :::\n" . $config['description'];
353  $path = $config['path'] . '/topics/' . $instance . '.html';
354  if (file_exists($path)) {
355  $doc_text .= "\n" . drush_html_to_text(file_get_contents($path));
356  }
357  $additional_topic_text = drush_command_invoke_all('drush_engine_topic_additional_text', $engine, $instance, $config);
358  if (!empty($additional_topic_text)) {
359  $doc_text .= "\n\n" . implode("\n\n", $additional_topic_text);
360  }
361  }
362  }
363 
364  // Write the topic text to a file so that is can be paged
365  $file = drush_save_data_to_temp_file($doc_text);
366  drush_print_file($file);
367 }
368 
369 /**
370  * Obtains the engine to use.
371  *
372  * Precedence:
373  *
374  * - user supplied engine via cli.
375  * - default engine configured for the command.
376  * - the first engine of all available.
377  *
378  * @see drush_find_engine_to_use().
379  *
380  * #TODO# clarify naming of functions and entrance point.
381  */
382 function drush_get_user_selected_engine(&$config, $engine_info) {
383  $engines = array_keys($engine_info['engines']);
384  $default = isset($config['default']) ? $config['default'] : current($engines);
385  if (!empty($config['option'])) {
386  $selected_engine = drush_get_option($config['option'], $default);
387  }
388  // Otherwise the default engine is the only option.
389  else {
390  $selected_engine = $default;
391  }
392  return $selected_engine;
393 }
394 
395 /**
396  * Returns a valid engine to use.
397  *
398  * If no preference is passed in $selected_engine, it will pick the
399  * 'default' engine provided within the command config.
400  *
401  * $config is altered to add the engine info to $config['engine-info'].
402  *
403  * @see drush_get_user_selected_engine().
404  *
405  * #TODO# clarify naming of functions and entrance point.
406  */
407 function drush_find_engine_to_use(&$config, $engine_info, $selected_engine = NULL) {
408  if (!isset($selected_engine)) {
409  $selected_engine = $config['default'];
410  }
411  if (array_key_exists($selected_engine, $engine_info['engines'])) {
412  $config['engine-info'] = $engine_info['engines'][$selected_engine];
413  }
414  return $selected_engine;
415 }
416 
417 /**
418  * Loads and validate an engine of the given type.
419  */
420 function drush_load_engine($type, $engine, $version = NULL, $path = NULL, $engine_config = NULL) {
421  $engine_info = drush_get_engines($type);
422  $selected_engine = drush_find_engine_to_use($engine_config, $engine_info, $engine);
423  if (!array_key_exists($selected_engine, $engine_info['engines'])) {
424  return drush_set_error('DRUSH_UNKNOWN_ENGINE_TYPE', dt('Unknown !engine_type engine !engine', array('!engine' => $selected_engine, '!engine_type' => $type)));
425  }
426  // Check engine dependency on drupal modules before include.
427  foreach ($engine_config['engine-info']['drupal dependencies'] as $dependency) {
428  if (!drush_module_exists($dependency)) {
429  return drush_set_error('DRUSH_ENGINE_DEPENDENCY_ERROR', dt('!engine_type: !engine engine needs the following modules installed/enabled to run: !dependencies.', array('!engine_type' => $type, '!engine' => $selected_engine, '!dependencies' => implode(', ', $engine_config['engine-info']['drupal dependencies']))));
430  }
431  }
432  $result = drush_include_engine($type, $selected_engine, $version, $path, $engine_config);
433  if (is_object($result)) {
434  $valid = method_exists($result, 'validate') ? $result->validate() : TRUE;
435  if ($valid) {
436  drush_set_engine($type, $result);
437  }
438  }
439  else {
440  $function = strtr($type, '-', '_') . '_validate';
441  $valid = function_exists($function) ? call_user_func($function) : TRUE;
442  }
443  if (!$valid) {
444  return FALSE;
445  }
446  return $result;
447 }
448 
449 /**
450  * Include the engine code for a specific named engine of a certain type.
451  *
452  * If the engine type has implemented hook_drush_engine_$type the path to the
453  * engine specified in the array will be used.
454  *
455  * If a class named in the form drush_$type_$engine exists, it will be an
456  * object of that class will be created and returned.
457  *
458  * If you don't need to present any user options for selecting the engine
459  * (which is common if the selection is implied by the running environment)
460  * and you don't need to allow other modules to define their own engines you can
461  * simply pass the $path to the directory where the engines are, and the
462  * appropriate one will be included.
463  *
464  * Unlike drush_include this function will set errors if the requested engine
465  * cannot be found.
466  *
467  * @param $type
468  * The type of engine.
469  * @param $engine
470  * The key for the engine to be included.
471  * @param $version
472  * The version of the engine to be included - defaults to the current Drupal core
473  * major version.
474  * @param $path
475  * A path to include from, if the engine has no corresponding
476  * hook_drush_engine_$type item path.
477  * @return TRUE or instanced object of available class on success. FALSE on fail.
478  */
479 function drush_include_engine($type, $selected_engine, $version = NULL, $path = NULL, $engine_config = NULL) {
480  $engine_info = drush_get_engines($type);
481  $engine = isset($engine_info['engines'][$selected_engine]['engine-class']) ? $engine_info['engines'][$selected_engine]['engine-class'] : $selected_engine;
482  if (!$path && isset($engine_info['engines'][$engine])) {
483  $path = $engine_info['engines'][$engine]['path'];
484  }
485  if (!$path) {
486  return drush_set_error('DRUSH_ENGINE_INCLUDE_NO_PATH', dt('No path was set for including the !type engine !engine.', array('!type' => $type, '!engine' => $engine)));
487  }
488  if (drush_include($path, $engine, $version)) {
489  $class = 'drush_' . $type . '_' . str_replace('-', '_', $engine);
490  if (class_exists($class)) {
491  $instance = new $class($engine_config);
492  $instance->engine_type = $type;
493  $instance->engine = $engine;
494  $instance->selected_engine = $selected_engine;
495  return $instance;
496  }
497  return TRUE;
498  }
499  return drush_set_error('DRUSH_ENGINE_INCLUDE_FAILED', dt('Unable to include the !type engine !engine from !path.' , array('!path' => $path, '!type' => $type, '!engine' => $engine)));
500 }
501 
502 /**
503  * Return the engine of the specified type that was loaded
504  * by the Drush command.
505  */
506 function drush_get_engine($type) {
507  return drush_get_context($type . '_engine', FALSE);
508 }
509 
510 /**
511  * Called by the Drush command (@see _drush_load_command_engines())
512  * to cache the active engine instance.
513  */
514 function drush_set_engine($type, $instance) {
515  drush_set_context($type . '_engine', $instance);
516 }
517 
518 /**
519  * Add engine topics to the command topics, if any.
520  */
521 function drush_engine_add_help_topics(&$command) {
522  $engine_types = drush_get_engine_types_info();
523  foreach ($command['engines'] as $engine_type => $config) {
524  $info = $engine_types[$engine_type];
525  if (isset($info['topics'])) {
526  $command['topics'] = array_merge($command['topics'], $info['topics']);
527  }
528  if (isset($info['topic'])) {
529  $command['topics'][] = $info['topic'];
530  }
531  }
532 }

File

doxygen/html/engines_8inc_source.html
View source
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Drush: includes/engines.inc Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Drush
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.2 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_09e761304027c904456130627fd4dcf5.html">includes</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">engines.inc</div>  </div>
</div><!--header-->
<div class="contents">
<a href="engines_8inc.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;&lt;?php</div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * @file</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> * The drush engines API implementation and helpers.</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment"> * Obtain all engine types info and normalize with defaults.</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment"> * @see hook_drush_engine_type_info().</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00013"></a><span class="lineno"><a class="code" href="engines_8inc.html#a50374de188af3d1cb754476607b9c375">   13</a></span>&#160;<span class="keyword">function</span> <a class="code" href="engines_8inc.html#a50374de188af3d1cb754476607b9c375">drush_get_engine_types_info</a>() {</div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;  $info = <a class="code" href="includes_2command_8inc.html#a19eba9666aba673a64fbd78a2c5ef4f9">drush_command_invoke_all</a>(<span class="stringliteral">&#39;drush_engine_type_info&#39;</span>);</div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;  <span class="keywordflow">foreach</span> ($info as $type =&gt; $data) {</div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;    $info[$type] += array(</div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;      <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;&#39;</span>,</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;      <span class="stringliteral">&#39;option&#39;</span> =&gt; FALSE,</div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;      <span class="stringliteral">&#39;default&#39;</span> =&gt; NULL,</div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;      <span class="stringliteral">&#39;options&#39;</span> =&gt; array(),</div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;      <span class="stringliteral">&#39;sub-options&#39;</span> =&gt; array(),</div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;      <span class="stringliteral">&#39;config-aliases&#39;</span> =&gt; array(),</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;      <span class="stringliteral">&#39;add-options-to-command&#39;</span> =&gt; FALSE,</div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;      <span class="stringliteral">&#39;combine-help&#39;</span> =&gt; FALSE,</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;    );</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;  }</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;  <span class="keywordflow">return</span> $info;</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;}</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;<span class="comment"> * Return a structured array of engines of a specific type.</span></div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;<span class="comment"> * Engines are pluggable subsystems. Each engine of a specific type will</span></div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;<span class="comment"> * implement the same set of API functions and perform the same high-level</span></div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;<span class="comment"> * task using a different backend or approach.</span></div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;<span class="comment"> * This function/hook is useful when you have a selection of several mutually</span></div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;<span class="comment"> * exclusive options to present to a user to select from.</span></div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;<span class="comment"> * Other commands are able to extend this list and provide their own engines.</span></div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;<span class="comment"> * The hook can return useful information to help users decide which engine</span></div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;<span class="comment"> * they need, such as description or list of available engine options.</span></div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;<span class="comment"> * The engine path element will automatically default to a subdirectory (within</span></div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;<span class="comment"> * the directory of the commandfile that implemented the hook) with the name of</span></div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;<span class="comment"> * the type of engine - e.g. an engine &quot;wget&quot; of type &quot;handler&quot; provided by</span></div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;<span class="comment"> * the &quot;pm&quot; commandfile would automatically be found if the file</span></div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;<span class="comment"> * &quot;pm/handler/wget.inc&quot; exists and a specific path is not provided.</span></div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;<span class="comment"> * @param $engine_type</span></div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;<span class="comment"> *   The type of engine.</span></div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;<span class="comment"> *   A structured array of engines.</span></div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00057"></a><span class="lineno"><a class="code" href="engines_8inc.html#ae94a82d80d5e90cb126de1f16a7f8fe4">   57</a></span>&#160;<span class="keyword">function</span> <a class="code" href="engines_8inc.html#ae94a82d80d5e90cb126de1f16a7f8fe4">drush_get_engines</a>($engine_type) {</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;  $info = <a class="code" href="engines_8inc.html#a50374de188af3d1cb754476607b9c375">drush_get_engine_types_info</a>();</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;  <span class="keywordflow">if</span> (!isset($info[$engine_type])) {</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_UNKNOWN_ENGINE_TYPE&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Unknown engine type !engine_type&#39;</span>, array(<span class="stringliteral">&#39;!engine_type&#39;</span> =&gt; $engine_type)));</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;  }</div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;  $engines = array(</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;    <span class="stringliteral">&#39;info&#39;</span> =&gt; $info[$engine_type],</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;    <span class="stringliteral">&#39;engines&#39;</span> =&gt; array(),</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;  );</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;  $list = <a class="code" href="includes_2command_8inc.html#ad51d79509a4a134947703f3e58564444">drush_commandfile_list</a>();</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;  $hook = <span class="stringliteral">&#39;drush_engine_&#39;</span> . str_replace(<span class="charliteral">&#39;-&#39;</span>, <span class="charliteral">&#39;_&#39;</span>, $engine_type);</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;  <span class="keywordflow">foreach</span> ($list as $commandfile =&gt; $path) {</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;    <span class="keywordflow">if</span> (<a class="code" href="includes_2command_8inc.html#a2ce77284c0002dda3a5d0527e583e017">drush_command_hook</a>($commandfile, $hook)) {</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;      $function = $commandfile . <span class="charliteral">&#39;_&#39;</span> . $hook;</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;      $result = $function();</div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;      <span class="keywordflow">foreach</span> ($result as $key =&gt; $engine) {</div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;        <span class="comment">// Add some defaults</span></div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;        $engine += array(</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;          <span class="stringliteral">&#39;commandfile&#39;</span> =&gt; $commandfile,</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;          <span class="comment">// Engines by default live in a subdirectory of the commandfile that</span></div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;          <span class="comment">// declared them, named as per the type of engine they are.</span></div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;          <span class="stringliteral">&#39;path&#39;</span> =&gt; sprintf(<span class="stringliteral">&quot;%s/%s&quot;</span>, dirname($path), $engine_type),</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;          <span class="stringliteral">&#39;options&#39;</span> =&gt; array(),</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;          <span class="stringliteral">&#39;sub-options&#39;</span> =&gt; array(),</div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;          <span class="stringliteral">&#39;drupal dependencies&#39;</span> =&gt; array(),</div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;        );</div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;        $engines[<span class="stringliteral">&#39;engines&#39;</span>][$key] = $engine;</div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;      }</div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;    }</div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;  }</div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;  <span class="keywordflow">return</span> $engines;</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;}</div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;<span class="comment"> * Take a look at all of the available engines,</span></div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;<span class="comment"> * and create topic commands for each one that</span></div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;<span class="comment"> * declares a topic.</span></div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00096"></a><span class="lineno"><a class="code" href="engines_8inc.html#ad7c7ef01f88180e6010e2d2cbb24b347">   96</a></span>&#160;<span class="keyword">function</span> <a class="code" href="engines_8inc.html#ad7c7ef01f88180e6010e2d2cbb24b347">drush_get_engine_topics</a>() {</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;  $items = array();</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;  $info = <a class="code" href="engines_8inc.html#a50374de188af3d1cb754476607b9c375">drush_get_engine_types_info</a>();</div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;  <span class="keywordflow">foreach</span> ($info as $engine =&gt; $data) {</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;    <span class="keywordflow">if</span> (array_key_exists(<span class="stringliteral">&#39;topic&#39;</span>, $data)) {</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;      $items[$data[<span class="stringliteral">&#39;topic&#39;</span>]] = array(</div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;        <span class="stringliteral">&#39;description&#39;</span> =&gt; $data[<span class="stringliteral">&#39;description&#39;</span>],</div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;        <span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE,</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;        <span class="stringliteral">&#39;topic&#39;</span> =&gt; TRUE,</div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;        <span class="stringliteral">&#39;bootstrap&#39;</span> =&gt; <a class="code" href="lib_2Drush_2Boot_2bootstrap_8inc.html#aaa7e693dd78d632c3d0f5baa3ba2d200">DRUSH_BOOTSTRAP_DRUSH</a>,</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;        <span class="stringliteral">&#39;callback&#39;</span> =&gt; <span class="stringliteral">&#39;drush_engine_topic_command&#39;</span>,</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;        <span class="stringliteral">&#39;callback arguments&#39;</span> =&gt; array($engine),</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;      );</div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;    }</div>
<div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;  }</div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;  <span class="keywordflow">return</span> $items;</div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;}</div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;<span class="comment"> * Include, instantiate and validate command engines.</span></div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;<span class="comment"> * @return FALSE if a engine doesn&#39;t validate.</span></div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00119"></a><span class="lineno"><a class="code" href="engines_8inc.html#a04e206fccfe9fe74aacda617336f5b87">  119</a></span>&#160;<span class="keyword">function</span> <a class="code" href="engines_8inc.html#a04e206fccfe9fe74aacda617336f5b87">drush_load_command_engines</a>($command) {</div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;  $result = TRUE;</div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;  <span class="keywordflow">foreach</span> ($command[<span class="stringliteral">&#39;engines&#39;</span>] as $engine_type =&gt; $config) {</div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;    $result = <a class="code" href="engines_8inc.html#af4e4689479142932fa789c5e314d29e9">drush_load_command_engine</a>($command, $engine_type);</div>
<div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;    <span class="comment">// Stop loading engines if any of them fails.</span></div>
<div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;    <span class="keywordflow">if</span> ($result === FALSE) {</div>
<div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;      <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;    }</div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;  }</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;  <span class="keywordflow">return</span> $result;</div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;}</div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;<span class="comment"> * Returns engine config supplied in the command definition.</span></div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00134"></a><span class="lineno"><a class="code" href="engines_8inc.html#a316fd3a909b19c6b88ce4ffc521756da">  134</a></span>&#160;<span class="keyword">function</span> <a class="code" href="engines_8inc.html#a316fd3a909b19c6b88ce4ffc521756da">drush_get_command_engine_config</a>($command, $engine_type, $metadata = array()) {</div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;  <span class="keywordflow">if</span> (isset($command[<span class="stringliteral">&#39;engines&#39;</span>][$engine_type])) {</div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;    $metadata = array_merge($metadata, $command[<span class="stringliteral">&#39;engines&#39;</span>][$engine_type]);</div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;  }</div>
<div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;  <span class="keywordflow">return</span> $metadata;</div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;}</div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;<span class="comment"> * Selects and loads an engine implementing the given type.</span></div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;<span class="comment"> * Loaded engines are stored as a context.</span></div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00146"></a><span class="lineno"><a class="code" href="engines_8inc.html#af4e4689479142932fa789c5e314d29e9">  146</a></span>&#160;<span class="keyword">function</span> <a class="code" href="engines_8inc.html#af4e4689479142932fa789c5e314d29e9">drush_load_command_engine</a>($command, $engine_type, $metadata = array()) {</div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;  <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&quot;Loading !engine engine.&quot;</span>, array(<span class="stringliteral">&#39;!engine&#39;</span> =&gt; $engine_type), <span class="stringliteral">&#39;bootstrap&#39;</span>));</div>
<div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;</div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;  $config = <a class="code" href="engines_8inc.html#a316fd3a909b19c6b88ce4ffc521756da">drush_get_command_engine_config</a>($command, $engine_type, $metadata);</div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;  $engine_info = <a class="code" href="engines_8inc.html#ae94a82d80d5e90cb126de1f16a7f8fe4">drush_get_engines</a>($engine_type);</div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;  $selected_engine = <a class="code" href="engines_8inc.html#afc75f35fe69601eee5e1c11a303dbbd0">drush_get_user_selected_engine</a>($config, $engine_info);</div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;  $version = <a class="code" href="includes_2drupal_8inc.html#ad2ccab77d4bc8e7355186f26cd328ac0">drush_drupal_major_version</a>();</div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;</div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;  $context = $engine_type . <span class="stringliteral">&#39;_engine_&#39;</span> . $selected_engine . <span class="charliteral">&#39;_&#39;</span> . $version;</div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;  $instance = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>($context, FALSE);</div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;  <span class="keywordflow">if</span> ($instance != FALSE) {</div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;    <a class="code" href="engines_8inc.html#a1eb2ea4e50529f3c7953f419956ce51a">drush_set_engine</a>($engine_type, $instance);</div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;  }</div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;    $instance = <a class="code" href="engines_8inc.html#af360562cce71af9828bbbb7326b1d7a8">drush_load_engine</a>($engine_type, $selected_engine, NULL, NULL, $config);</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;      $command[<span class="stringliteral">&#39;bootstrap_errors&#39;</span>][<span class="stringliteral">&quot;FOO&quot;</span>] = <span class="stringliteral">&quot;BAR&quot;</span>;</div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;    <span class="keywordflow">if</span> ($instance == FALSE) {</div>
<div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;      <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;    }</div>
<div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;    <a class="code" href="context_8inc.html#af983acfe90e7d7bbdbd67c57f93708ba">drush_set_context</a>($context, $instance);</div>
<div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;  }</div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;  <span class="keywordflow">return</span> $instance;</div>
<div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;}</div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;<span class="comment"> * Add command structure info from each engine type back into the command.</span></div>
<div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00173"></a><span class="lineno"><a class="code" href="engines_8inc.html#a04ee0e7019029ef27bc4e8f14341b2b4">  173</a></span>&#160;<span class="keyword">function</span> <a class="code" href="engines_8inc.html#a04ee0e7019029ef27bc4e8f14341b2b4">drush_merge_engine_data</a>(&amp;$command) {</div>
<div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;  <span class="comment">// First remap engine data from the shortcut location</span></div>
<div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;  <span class="comment">// ($command[&#39;engine_type&#39;]) to the standard location</span></div>
<div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;  <span class="comment">// ($command[&#39;engines&#39;][&#39;engine_type&#39;])</span></div>
<div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;  $info = <a class="code" href="engines_8inc.html#a50374de188af3d1cb754476607b9c375">drush_get_engine_types_info</a>();</div>
<div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;  <span class="keywordflow">foreach</span> ($info as $engine_type =&gt; $info) {</div>
<div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;    <span class="keywordflow">if</span> (isset($command[$engine_type])) {</div>
<div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;      $config = $command[$engine_type];</div>
<div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;      <span class="keywordflow">foreach</span> ($info[<span class="stringliteral">&#39;config-aliases&#39;</span>] as $engine_option_alias_name =&gt; $engine_option_standard_name) {</div>
<div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;        <span class="keywordflow">if</span> (array_key_exists($engine_option_alias_name, $config)) {</div>
<div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;          $config[$engine_option_standard_name] = $config[$engine_option_alias_name];</div>
<div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;          unset($config[$engine_option_alias_name]);</div>
<div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;        }</div>
<div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;      }</div>
<div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;      <span class="comment">// Convert single string values of &#39;require-engine-capability&#39; to an array.</span></div>
<div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;      <span class="keywordflow">if</span> (isset($config[<span class="stringliteral">&#39;require-engine-capability&#39;</span>]) &amp;&amp; is_string($config[<span class="stringliteral">&#39;require-engine-capability&#39;</span>])) {</div>
<div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;        $config[<span class="stringliteral">&#39;require-engine-capability&#39;</span>] = array($config[<span class="stringliteral">&#39;require-engine-capability&#39;</span>]);</div>
<div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;      }</div>
<div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;      $command[<span class="stringliteral">&#39;engines&#39;</span>][$engine_type] = $config;</div>
<div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;    }</div>
<div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;  }</div>
<div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;</div>
<div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;  <span class="keywordflow">foreach</span> ($command[<span class="stringliteral">&#39;engines&#39;</span>] as $engine_type =&gt; $config) {</div>
<div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;    <span class="comment">// Normalize engines structure.</span></div>
<div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;    <span class="keywordflow">if</span> (!is_array($config)) {</div>
<div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;      unset($command[<span class="stringliteral">&#39;engines&#39;</span>][$engine_type]);</div>
<div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;      $command[<span class="stringliteral">&#39;engines&#39;</span>][$config] = array();</div>
<div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;      $engine_type = $config;</div>
<div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;    }</div>
<div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;</div>
<div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;    <span class="comment">// Get all implementations for this engine type.</span></div>
<div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;    $engine_info = <a class="code" href="engines_8inc.html#ae94a82d80d5e90cb126de1f16a7f8fe4">drush_get_engines</a>($engine_type);</div>
<div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;    <span class="keywordflow">if</span> ($engine_info === FALSE) {</div>
<div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;      <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160;    }</div>
<div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;</div>
<div class="line"><a name="l00209"></a><span class="lineno">  209</span>&#160;    <span class="comment">// Complete command-declared engine type with default info.</span></div>
<div class="line"><a name="l00210"></a><span class="lineno">  210</span>&#160;    $command[<span class="stringliteral">&#39;engines&#39;</span>][$engine_type] += $engine_info[<span class="stringliteral">&#39;info&#39;</span>];</div>
<div class="line"><a name="l00211"></a><span class="lineno">  211</span>&#160;    $config = $command[<span class="stringliteral">&#39;engines&#39;</span>][$engine_type];</div>
<div class="line"><a name="l00212"></a><span class="lineno">  212</span>&#160;</div>
<div class="line"><a name="l00213"></a><span class="lineno">  213</span>&#160;    $engine_data = array();</div>
<div class="line"><a name="l00214"></a><span class="lineno">  214</span>&#160;</div>
<div class="line"><a name="l00215"></a><span class="lineno">  215</span>&#160;    <span class="comment">// If there&#39;s a single implementation for this engine type, it will be</span></div>
<div class="line"><a name="l00216"></a><span class="lineno">  216</span>&#160;    <span class="comment">// loaded by default, and makes no sense to provide a command line option</span></div>
<div class="line"><a name="l00217"></a><span class="lineno">  217</span>&#160;    <span class="comment">// to select the only flavor (ie. --release_info=updatexml), so we won&#39;t</span></div>
<div class="line"><a name="l00218"></a><span class="lineno">  218</span>&#160;    <span class="comment">// add an option in this case.</span></div>
<div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;    <span class="comment">// Additionally, depending on the command, it may be convenient to extend</span></div>
<div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;    <span class="comment">// the command with the engine options.</span></div>
<div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;    <span class="keywordflow">if</span> (count($engine_info[<span class="stringliteral">&#39;engines&#39;</span>]) == 1) {</div>
<div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;      <span class="keywordflow">if</span> ($config[<span class="stringliteral">&#39;add-options-to-command&#39;</span>] !== FALSE) {</div>
<div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;        <span class="comment">// Add options and suboptions of the engine type and</span></div>
<div class="line"><a name="l00224"></a><span class="lineno">  224</span>&#160;        <span class="comment">// the sole implementation.</span></div>
<div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160;        $engine = key($engine_info[<span class="stringliteral">&#39;engines&#39;</span>]);</div>
<div class="line"><a name="l00226"></a><span class="lineno">  226</span>&#160;        $data = $engine_info[<span class="stringliteral">&#39;engines&#39;</span>][$engine];</div>
<div class="line"><a name="l00227"></a><span class="lineno">  227</span>&#160;        $engine_data += array(</div>
<div class="line"><a name="l00228"></a><span class="lineno">  228</span>&#160;          <span class="stringliteral">&#39;options&#39;</span> =&gt; $config[<span class="stringliteral">&#39;options&#39;</span>] + $data[<span class="stringliteral">&#39;options&#39;</span>],</div>
<div class="line"><a name="l00229"></a><span class="lineno">  229</span>&#160;          <span class="stringliteral">&#39;sub-options&#39;</span> =&gt; $config[<span class="stringliteral">&#39;sub-options&#39;</span>] + $data[<span class="stringliteral">&#39;sub-options&#39;</span>],</div>
<div class="line"><a name="l00230"></a><span class="lineno">  230</span>&#160;        );</div>
<div class="line"><a name="l00231"></a><span class="lineno">  231</span>&#160;      }</div>
<div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160;    }</div>
<div class="line"><a name="l00233"></a><span class="lineno">  233</span>&#160;    <span class="comment">// Otherwise, provide a command option to choose between engines and add</span></div>
<div class="line"><a name="l00234"></a><span class="lineno">  234</span>&#160;    <span class="comment">// the engine options and sub-options.</span></div>
<div class="line"><a name="l00235"></a><span class="lineno">  235</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00236"></a><span class="lineno">  236</span>&#160;      <span class="comment">// Add engine type global options and suboptions.</span></div>
<div class="line"><a name="l00237"></a><span class="lineno">  237</span>&#160;      $engine_data += array(</div>
<div class="line"><a name="l00238"></a><span class="lineno">  238</span>&#160;        <span class="stringliteral">&#39;options&#39;</span> =&gt; $config[<span class="stringliteral">&#39;options&#39;</span>],</div>
<div class="line"><a name="l00239"></a><span class="lineno">  239</span>&#160;        <span class="stringliteral">&#39;sub-options&#39;</span> =&gt; $config[<span class="stringliteral">&#39;sub-options&#39;</span>],</div>
<div class="line"><a name="l00240"></a><span class="lineno">  240</span>&#160;      );</div>
<div class="line"><a name="l00241"></a><span class="lineno">  241</span>&#160;</div>
<div class="line"><a name="l00242"></a><span class="lineno">  242</span>&#160;      <span class="comment">// If the &#39;combine-help&#39; flag is set in the engine config,</span></div>
<div class="line"><a name="l00243"></a><span class="lineno">  243</span>&#160;      <span class="comment">// then we will combine all of the help items into the help</span></div>
<div class="line"><a name="l00244"></a><span class="lineno">  244</span>&#160;      <span class="comment">// text for $config[&#39;option&#39;].</span></div>
<div class="line"><a name="l00245"></a><span class="lineno">  245</span>&#160;      $combine_help = $config[<span class="stringliteral">&#39;combine-help&#39;</span>];</div>
<div class="line"><a name="l00246"></a><span class="lineno">  246</span>&#160;      $combine_help_data = array();</div>
<div class="line"><a name="l00247"></a><span class="lineno">  247</span>&#160;</div>
<div class="line"><a name="l00248"></a><span class="lineno">  248</span>&#160;      <span class="comment">// Process engines in order. First the default engine, the rest alphabetically.</span></div>
<div class="line"><a name="l00249"></a><span class="lineno">  249</span>&#160;      $default = <a class="code" href="engines_8inc.html#ac18b04b38c84979a32603cd5cef78c69">drush_find_engine_to_use</a>($config, $engine_info);</div>
<div class="line"><a name="l00250"></a><span class="lineno">  250</span>&#160;      $engines = array_keys($engine_info[<span class="stringliteral">&#39;engines&#39;</span>]);</div>
<div class="line"><a name="l00251"></a><span class="lineno">  251</span>&#160;      asort($engines);</div>
<div class="line"><a name="l00252"></a><span class="lineno">  252</span>&#160;      array_unshift($engines, $default);</div>
<div class="line"><a name="l00253"></a><span class="lineno">  253</span>&#160;      $engines = array_unique($engines);</div>
<div class="line"><a name="l00254"></a><span class="lineno">  254</span>&#160;      <span class="keywordflow">foreach</span> ($engines as $engine) {</div>
<div class="line"><a name="l00255"></a><span class="lineno">  255</span>&#160;        $data = $engine_info[<span class="stringliteral">&#39;engines&#39;</span>][$engine];</div>
<div class="line"><a name="l00256"></a><span class="lineno">  256</span>&#160;        <span class="comment">// Check to see if the command requires any particular</span></div>
<div class="line"><a name="l00257"></a><span class="lineno">  257</span>&#160;        <span class="comment">// capabilities.  If no capabilities are required, then</span></div>
<div class="line"><a name="l00258"></a><span class="lineno">  258</span>&#160;        <span class="comment">// all engines are acceptable.</span></div>
<div class="line"><a name="l00259"></a><span class="lineno">  259</span>&#160;        $engine_is_usable = TRUE;</div>
<div class="line"><a name="l00260"></a><span class="lineno">  260</span>&#160;        <span class="keywordflow">if</span> (array_key_exists(<span class="stringliteral">&#39;require-engine-capability&#39;</span>, $config)) {</div>
<div class="line"><a name="l00261"></a><span class="lineno">  261</span>&#160;          <span class="comment">// See if the engine declares that it provides any</span></div>
<div class="line"><a name="l00262"></a><span class="lineno">  262</span>&#160;          <span class="comment">// capabilities.  If no capabilities are listed, then</span></div>
<div class="line"><a name="l00263"></a><span class="lineno">  263</span>&#160;          <span class="comment">// it is assumed that the engine can satisfy all requirements.</span></div>
<div class="line"><a name="l00264"></a><span class="lineno">  264</span>&#160;          <span class="keywordflow">if</span> (array_key_exists(<span class="stringliteral">&#39;engine-capabilities&#39;</span>, $data)) {</div>
<div class="line"><a name="l00265"></a><span class="lineno">  265</span>&#160;            $engine_is_usable = FALSE;</div>
<div class="line"><a name="l00266"></a><span class="lineno">  266</span>&#160;            <span class="comment">// If &#39;require-engine-capability&#39; is TRUE instead of an array,</span></div>
<div class="line"><a name="l00267"></a><span class="lineno">  267</span>&#160;            <span class="comment">// then only engines that are universal (do not declare any</span></div>
<div class="line"><a name="l00268"></a><span class="lineno">  268</span>&#160;            <span class="comment">// particular capabilities) are usable.</span></div>
<div class="line"><a name="l00269"></a><span class="lineno">  269</span>&#160;            <span class="keywordflow">if</span> (is_array($config[<span class="stringliteral">&#39;require-engine-capability&#39;</span>])) {</div>
<div class="line"><a name="l00270"></a><span class="lineno">  270</span>&#160;              <span class="keywordflow">foreach</span> ($config[<span class="stringliteral">&#39;require-engine-capability&#39;</span>] as $required) {</div>
<div class="line"><a name="l00271"></a><span class="lineno">  271</span>&#160;                <span class="comment">// We need an engine that provides any one of the requirements.</span></div>
<div class="line"><a name="l00272"></a><span class="lineno">  272</span>&#160;                <span class="keywordflow">if</span> (in_array($required, $data[<span class="stringliteral">&#39;engine-capabilities&#39;</span>])) {</div>
<div class="line"><a name="l00273"></a><span class="lineno">  273</span>&#160;                  $engine_is_usable = TRUE;</div>
<div class="line"><a name="l00274"></a><span class="lineno">  274</span>&#160;                }</div>
<div class="line"><a name="l00275"></a><span class="lineno">  275</span>&#160;              }</div>
<div class="line"><a name="l00276"></a><span class="lineno">  276</span>&#160;            }</div>
<div class="line"><a name="l00277"></a><span class="lineno">  277</span>&#160;          }</div>
<div class="line"><a name="l00278"></a><span class="lineno">  278</span>&#160;        }</div>
<div class="line"><a name="l00279"></a><span class="lineno">  279</span>&#160;        <span class="keywordflow">if</span> ($engine_is_usable) {</div>
<div class="line"><a name="l00280"></a><span class="lineno">  280</span>&#160;          $command[<span class="stringliteral">&#39;engines&#39;</span>][$engine_type][<span class="stringliteral">&#39;usable&#39;</span>][] = $engine;</div>
<div class="line"><a name="l00281"></a><span class="lineno">  281</span>&#160;          <span class="keywordflow">if</span> (!isset($data[<span class="stringliteral">&#39;hidden&#39;</span>])) {</div>
<div class="line"><a name="l00282"></a><span class="lineno">  282</span>&#160;            $option = $config[<span class="stringliteral">&#39;option&#39;</span>] . <span class="charliteral">&#39;=&#39;</span> . $engine;</div>
<div class="line"><a name="l00283"></a><span class="lineno">  283</span>&#160;            $engine_data[<span class="stringliteral">&#39;options&#39;</span>][$option][<span class="stringliteral">&#39;description&#39;</span>] = array_key_exists(<span class="stringliteral">&#39;description&#39;</span>, $data) ? $data[<span class="stringliteral">&#39;description&#39;</span>] : NULL;</div>
<div class="line"><a name="l00284"></a><span class="lineno">  284</span>&#160;            <span class="keywordflow">if</span> ($combine_help) {</div>
<div class="line"><a name="l00285"></a><span class="lineno">  285</span>&#160;              $engine_data[<span class="stringliteral">&#39;options&#39;</span>][$option][<span class="stringliteral">&#39;hidden&#39;</span>] = TRUE;</div>
<div class="line"><a name="l00286"></a><span class="lineno">  286</span>&#160;              <span class="keywordflow">if</span> (<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_VERBOSE&#39;</span>) || ($default == $engine) || !isset($data[<span class="stringliteral">&#39;verbose-only&#39;</span>])) {</div>
<div class="line"><a name="l00287"></a><span class="lineno">  287</span>&#160;                $combine_help_data[$engine] = $engine . <span class="stringliteral">&#39;: &#39;</span> . $data[<span class="stringliteral">&#39;description&#39;</span>];</div>
<div class="line"><a name="l00288"></a><span class="lineno">  288</span>&#160;              }</div>
<div class="line"><a name="l00289"></a><span class="lineno">  289</span>&#160;            }</div>
<div class="line"><a name="l00290"></a><span class="lineno">  290</span>&#160;            <span class="keywordflow">if</span> (isset($data[<span class="stringliteral">&#39;options&#39;</span>])) {</div>
<div class="line"><a name="l00291"></a><span class="lineno">  291</span>&#160;              $engine_data[<span class="stringliteral">&#39;sub-options&#39;</span>][$option] = $data[<span class="stringliteral">&#39;options&#39;</span>];</div>
<div class="line"><a name="l00292"></a><span class="lineno">  292</span>&#160;            }</div>
<div class="line"><a name="l00293"></a><span class="lineno">  293</span>&#160;            <span class="keywordflow">if</span> (isset($data[<span class="stringliteral">&#39;sub-options&#39;</span>])) {</div>
<div class="line"><a name="l00294"></a><span class="lineno">  294</span>&#160;              $engine_data[<span class="stringliteral">&#39;sub-options&#39;</span>] += $data[<span class="stringliteral">&#39;sub-options&#39;</span>];</div>
<div class="line"><a name="l00295"></a><span class="lineno">  295</span>&#160;            }</div>
<div class="line"><a name="l00296"></a><span class="lineno">  296</span>&#160;          }</div>
<div class="line"><a name="l00297"></a><span class="lineno">  297</span>&#160;        }</div>
<div class="line"><a name="l00298"></a><span class="lineno">  298</span>&#160;      }</div>
<div class="line"><a name="l00299"></a><span class="lineno">  299</span>&#160;      <span class="keywordflow">if</span> (!empty($combine_help_data)) {</div>
<div class="line"><a name="l00300"></a><span class="lineno">  300</span>&#160;        $engine_selection_option = $config[<span class="stringliteral">&#39;option&#39;</span>];</div>
<div class="line"><a name="l00301"></a><span class="lineno">  301</span>&#160;        <span class="keywordflow">if</span> (!is_array($engine_data[<span class="stringliteral">&#39;options&#39;</span>][$engine_selection_option])) {</div>
<div class="line"><a name="l00302"></a><span class="lineno">  302</span>&#160;          $engine_data[<span class="stringliteral">&#39;options&#39;</span>][$engine_selection_option] = array(<span class="stringliteral">&#39;description&#39;</span> =&gt; $config[<span class="stringliteral">&#39;options&#39;</span>][$engine_selection_option]);</div>
<div class="line"><a name="l00303"></a><span class="lineno">  303</span>&#160;        }</div>
<div class="line"><a name="l00304"></a><span class="lineno">  304</span>&#160;        <span class="keywordflow">if</span> (<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_VERBOSE&#39;</span>)) {</div>
<div class="line"><a name="l00305"></a><span class="lineno">  305</span>&#160;          $engine_data[<span class="stringliteral">&#39;options&#39;</span>][$engine_selection_option][<span class="stringliteral">&#39;description&#39;</span>] .= <span class="stringliteral">&quot;\n&quot;</span> . <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&quot;All available values are:&quot;</span>) . <span class="stringliteral">&quot;\n - &quot;</span> . implode(<span class="stringliteral">&quot;\n - &quot;</span>, $combine_help_data) . <span class="stringliteral">&quot;\n&quot;</span>;</div>
<div class="line"><a name="l00306"></a><span class="lineno">  306</span>&#160;        }</div>
<div class="line"><a name="l00307"></a><span class="lineno">  307</span>&#160;        <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00308"></a><span class="lineno">  308</span>&#160;          $engine_data[<span class="stringliteral">&#39;options&#39;</span>][$engine_selection_option][<span class="stringliteral">&#39;description&#39;</span>] .= <span class="stringliteral">&quot; &quot;</span> . <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&quot;Available: &quot;</span>) . implode(<span class="stringliteral">&#39;, &#39;</span>, array_keys($combine_help_data)) . <span class="stringliteral">&quot;. &quot;</span>;</div>
<div class="line"><a name="l00309"></a><span class="lineno">  309</span>&#160;        }</div>
<div class="line"><a name="l00310"></a><span class="lineno">  310</span>&#160;        $engine_data[<span class="stringliteral">&#39;options&#39;</span>][$engine_selection_option][<span class="stringliteral">&#39;description&#39;</span>] .= <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&quot;Default is !default.&quot;</span>, array(<span class="stringliteral">&#39;!default&#39;</span> =&gt; $default));</div>
<div class="line"><a name="l00311"></a><span class="lineno">  311</span>&#160;      }</div>
<div class="line"><a name="l00312"></a><span class="lineno">  312</span>&#160;      <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00313"></a><span class="lineno">  313</span>&#160;        <span class="comment">// If the help options are not combined, then extend the</span></div>
<div class="line"><a name="l00314"></a><span class="lineno">  314</span>&#160;        <span class="comment">// default engine description.</span></div>
<div class="line"><a name="l00315"></a><span class="lineno">  315</span>&#160;        $desc = $engine_info[<span class="stringliteral">&#39;engines&#39;</span>][$default][<span class="stringliteral">&#39;description&#39;</span>];</div>
<div class="line"><a name="l00316"></a><span class="lineno">  316</span>&#160;        $engine_info[<span class="stringliteral">&#39;engines&#39;</span>][$default][<span class="stringliteral">&#39;description&#39;</span>] = <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Default !type engine.&#39;</span>, array(<span class="stringliteral">&#39;!type&#39;</span> =&gt; $engine_type)) . <span class="charliteral">&#39; &#39;</span> . $desc;</div>
<div class="line"><a name="l00317"></a><span class="lineno">  317</span>&#160;      }</div>
<div class="line"><a name="l00318"></a><span class="lineno">  318</span>&#160;    }</div>
<div class="line"><a name="l00319"></a><span class="lineno">  319</span>&#160;    $command = array_merge_recursive($command, $engine_data);</div>
<div class="line"><a name="l00320"></a><span class="lineno">  320</span>&#160;  }</div>
<div class="line"><a name="l00321"></a><span class="lineno">  321</span>&#160;}</div>
<div class="line"><a name="l00322"></a><span class="lineno">  322</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00323"></a><span class="lineno">  323</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00324"></a><span class="lineno">  324</span>&#160;<span class="comment"> * Implementation of command hook for docs-output-formats</span></div>
<div class="line"><a name="l00325"></a><span class="lineno">  325</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00326"></a><span class="lineno"><a class="code" href="engines_8inc.html#a434593aa5eee4a2a9e6e51cdca8ccab5">  326</a></span>&#160;<span class="keyword">function</span> <a class="code" href="engines_8inc.html#a434593aa5eee4a2a9e6e51cdca8ccab5">drush_engine_topic_command</a>($engine) {</div>
<div class="line"><a name="l00327"></a><span class="lineno">  327</span>&#160;  $engine_instances = <a class="code" href="engines_8inc.html#ae94a82d80d5e90cb126de1f16a7f8fe4">drush_get_engines</a>($engine);</div>
<div class="line"><a name="l00328"></a><span class="lineno">  328</span>&#160;  $option = $engine_instances[<span class="stringliteral">&#39;info&#39;</span>][<span class="stringliteral">&#39;option&#39;</span>];</div>
<div class="line"><a name="l00329"></a><span class="lineno">  329</span>&#160;</div>
<div class="line"><a name="l00330"></a><span class="lineno">  330</span>&#160;  <span class="keywordflow">if</span> (isset($engine_instances[<span class="stringliteral">&#39;info&#39;</span>][<span class="stringliteral">&#39;topic-file&#39;</span>])) {</div>
<div class="line"><a name="l00331"></a><span class="lineno">  331</span>&#160;    <span class="comment">// To do: put this file next to the commandfile that defines the</span></div>
<div class="line"><a name="l00332"></a><span class="lineno">  332</span>&#160;    <span class="comment">// engine type, not in the core docs directory.</span></div>
<div class="line"><a name="l00333"></a><span class="lineno">  333</span>&#160;    $docs_dir = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DOC_PREFIX&#39;</span>, DRUSH_BASE_PATH);</div>
<div class="line"><a name="l00334"></a><span class="lineno">  334</span>&#160;    $path = $engine_instances[<span class="stringliteral">&#39;info&#39;</span>][<span class="stringliteral">&#39;topic-file&#39;</span>];</div>
<div class="line"><a name="l00335"></a><span class="lineno">  335</span>&#160;    $docs_file = (<a class="code" href="group__filesystemfunctions.html#gafa80199035259ddf98fa300d6f646aa2">drush_is_absolute_path</a>($path) ? <span class="stringliteral">&#39;&#39;</span> : $docs_dir . <span class="charliteral">&#39;/&#39;</span>) . $path;</div>
<div class="line"><a name="l00336"></a><span class="lineno">  336</span>&#160;    $doc_text = <a class="code" href="group__outputfunctions.html#gaf5119cf7ab3248aac5314f1dcb3d4c75">drush_html_to_text</a>(file_get_contents($docs_file));</div>
<div class="line"><a name="l00337"></a><span class="lineno">  337</span>&#160;  }</div>
<div class="line"><a name="l00338"></a><span class="lineno">  338</span>&#160;  elseif (isset($engine_instances[<span class="stringliteral">&#39;info&#39;</span>][<span class="stringliteral">&#39;topic-text&#39;</span>])) {</div>
<div class="line"><a name="l00339"></a><span class="lineno">  339</span>&#160;    $doc_text = $engine_instances[<span class="stringliteral">&#39;info&#39;</span>][<span class="stringliteral">&#39;topic-text&#39;</span>];</div>
<div class="line"><a name="l00340"></a><span class="lineno">  340</span>&#160;  }</div>
<div class="line"><a name="l00341"></a><span class="lineno">  341</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00342"></a><span class="lineno">  342</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_BAD_ENGINE_TOPIC&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&quot;The engine !engine did not define its topic command correctly.&quot;</span>, array(<span class="stringliteral">&#39;!engine&#39;</span> =&gt; $engine)));</div>
<div class="line"><a name="l00343"></a><span class="lineno">  343</span>&#160;  }</div>
<div class="line"><a name="l00344"></a><span class="lineno">  344</span>&#160;</div>
<div class="line"><a name="l00345"></a><span class="lineno">  345</span>&#160;  <span class="comment">// Look at each instance of the engine; if it has an html</span></div>
<div class="line"><a name="l00346"></a><span class="lineno">  346</span>&#160;  <span class="comment">// file in the the &#39;topics&#39; folder named after itself, then</span></div>
<div class="line"><a name="l00347"></a><span class="lineno">  347</span>&#160;  <span class="comment">// include the file contents in the engine topic text.</span></div>
<div class="line"><a name="l00348"></a><span class="lineno">  348</span>&#160;  $instances = $engine_instances[<span class="stringliteral">&#39;engines&#39;</span>];</div>
<div class="line"><a name="l00349"></a><span class="lineno">  349</span>&#160;  ksort($instances);</div>
<div class="line"><a name="l00350"></a><span class="lineno">  350</span>&#160;  <span class="keywordflow">foreach</span> ($instances as $instance =&gt; $config) {</div>
<div class="line"><a name="l00351"></a><span class="lineno">  351</span>&#160;    <span class="keywordflow">if</span> (isset($config[<span class="stringliteral">&#39;description&#39;</span>])) {</div>
<div class="line"><a name="l00352"></a><span class="lineno">  352</span>&#160;      $doc_text .= <span class="stringliteral">&quot;\n\n::: --$option=$instance :::\n&quot;</span> . $config[<span class="stringliteral">&#39;description&#39;</span>];</div>
<div class="line"><a name="l00353"></a><span class="lineno">  353</span>&#160;      $path = $config[<span class="stringliteral">&#39;path&#39;</span>] . <span class="stringliteral">&#39;/topics/&#39;</span> . $instance . <span class="stringliteral">&#39;.html&#39;</span>;</div>
<div class="line"><a name="l00354"></a><span class="lineno">  354</span>&#160;      <span class="keywordflow">if</span> (file_exists($path)) {</div>
<div class="line"><a name="l00355"></a><span class="lineno">  355</span>&#160;        $doc_text .= <span class="stringliteral">&quot;\n&quot;</span> . <a class="code" href="group__outputfunctions.html#gaf5119cf7ab3248aac5314f1dcb3d4c75">drush_html_to_text</a>(file_get_contents($path));</div>
<div class="line"><a name="l00356"></a><span class="lineno">  356</span>&#160;      }</div>
<div class="line"><a name="l00357"></a><span class="lineno">  357</span>&#160;      $additional_topic_text = <a class="code" href="includes_2command_8inc.html#a19eba9666aba673a64fbd78a2c5ef4f9">drush_command_invoke_all</a>(<span class="stringliteral">&#39;drush_engine_topic_additional_text&#39;</span>, $engine, $instance, $config);</div>
<div class="line"><a name="l00358"></a><span class="lineno">  358</span>&#160;      <span class="keywordflow">if</span> (!empty($additional_topic_text)) {</div>
<div class="line"><a name="l00359"></a><span class="lineno">  359</span>&#160;        $doc_text .= <span class="stringliteral">&quot;\n\n&quot;</span> . implode(<span class="stringliteral">&quot;\n\n&quot;</span>, $additional_topic_text);</div>
<div class="line"><a name="l00360"></a><span class="lineno">  360</span>&#160;      }</div>
<div class="line"><a name="l00361"></a><span class="lineno">  361</span>&#160;    }</div>
<div class="line"><a name="l00362"></a><span class="lineno">  362</span>&#160;  }</div>
<div class="line"><a name="l00363"></a><span class="lineno">  363</span>&#160;</div>
<div class="line"><a name="l00364"></a><span class="lineno">  364</span>&#160;  <span class="comment">// Write the topic text to a file so that is can be paged</span></div>
<div class="line"><a name="l00365"></a><span class="lineno">  365</span>&#160;  $file = <a class="code" href="group__filesystemfunctions.html#gadb66635fa63012fb084f8e96a392776d">drush_save_data_to_temp_file</a>($doc_text);</div>
<div class="line"><a name="l00366"></a><span class="lineno">  366</span>&#160;  <a class="code" href="group__outputfunctions.html#ga8059aaf93da4ec3f4c5d3821928a9002">drush_print_file</a>($file);</div>
<div class="line"><a name="l00367"></a><span class="lineno">  367</span>&#160;}</div>
<div class="line"><a name="l00368"></a><span class="lineno">  368</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00369"></a><span class="lineno">  369</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00370"></a><span class="lineno">  370</span>&#160;<span class="comment"> * Obtains the engine to use.</span></div>
<div class="line"><a name="l00371"></a><span class="lineno">  371</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00372"></a><span class="lineno">  372</span>&#160;<span class="comment"> * Precedence:</span></div>
<div class="line"><a name="l00373"></a><span class="lineno">  373</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00374"></a><span class="lineno">  374</span>&#160;<span class="comment"> *  - user supplied engine via cli.</span></div>
<div class="line"><a name="l00375"></a><span class="lineno">  375</span>&#160;<span class="comment"> *  - default engine configured for the command.</span></div>
<div class="line"><a name="l00376"></a><span class="lineno">  376</span>&#160;<span class="comment"> *  - the first engine of all available.</span></div>
<div class="line"><a name="l00377"></a><span class="lineno">  377</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00378"></a><span class="lineno">  378</span>&#160;<span class="comment"> *  @see drush_find_engine_to_use().</span></div>
<div class="line"><a name="l00379"></a><span class="lineno">  379</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00380"></a><span class="lineno">  380</span>&#160;<span class="comment"> *  #TODO# clarify naming of functions and entrance point.</span></div>
<div class="line"><a name="l00381"></a><span class="lineno">  381</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00382"></a><span class="lineno"><a class="code" href="engines_8inc.html#afc75f35fe69601eee5e1c11a303dbbd0">  382</a></span>&#160;<span class="keyword">function</span> <a class="code" href="engines_8inc.html#afc75f35fe69601eee5e1c11a303dbbd0">drush_get_user_selected_engine</a>(&amp;$config, $engine_info) {</div>
<div class="line"><a name="l00383"></a><span class="lineno">  383</span>&#160;  $engines = array_keys($engine_info[<span class="stringliteral">&#39;engines&#39;</span>]);</div>
<div class="line"><a name="l00384"></a><span class="lineno">  384</span>&#160;  $default = isset($config[<span class="stringliteral">&#39;default&#39;</span>]) ? $config[<span class="stringliteral">&#39;default&#39;</span>] : current($engines);</div>
<div class="line"><a name="l00385"></a><span class="lineno">  385</span>&#160;  <span class="keywordflow">if</span> (!empty($config[<span class="stringliteral">&#39;option&#39;</span>])) {</div>
<div class="line"><a name="l00386"></a><span class="lineno">  386</span>&#160;    $selected_engine = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>($config[<span class="stringliteral">&#39;option&#39;</span>], $default);</div>
<div class="line"><a name="l00387"></a><span class="lineno">  387</span>&#160;  }</div>
<div class="line"><a name="l00388"></a><span class="lineno">  388</span>&#160;  <span class="comment">// Otherwise the default engine is the only option.</span></div>
<div class="line"><a name="l00389"></a><span class="lineno">  389</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00390"></a><span class="lineno">  390</span>&#160;    $selected_engine = $default;</div>
<div class="line"><a name="l00391"></a><span class="lineno">  391</span>&#160;  }</div>
<div class="line"><a name="l00392"></a><span class="lineno">  392</span>&#160;  <span class="keywordflow">return</span> $selected_engine;</div>
<div class="line"><a name="l00393"></a><span class="lineno">  393</span>&#160;}</div>
<div class="line"><a name="l00394"></a><span class="lineno">  394</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00395"></a><span class="lineno">  395</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00396"></a><span class="lineno">  396</span>&#160;<span class="comment"> * Returns a valid engine to use.</span></div>
<div class="line"><a name="l00397"></a><span class="lineno">  397</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00398"></a><span class="lineno">  398</span>&#160;<span class="comment"> * If no preference is passed in $selected_engine, it will pick the</span></div>
<div class="line"><a name="l00399"></a><span class="lineno">  399</span>&#160;<span class="comment"> * &#39;default&#39; engine provided within the command config.</span></div>
<div class="line"><a name="l00400"></a><span class="lineno">  400</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00401"></a><span class="lineno">  401</span>&#160;<span class="comment"> * $config is altered to add the engine info to $config[&#39;engine-info&#39;].</span></div>
<div class="line"><a name="l00402"></a><span class="lineno">  402</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00403"></a><span class="lineno">  403</span>&#160;<span class="comment"> *  @see drush_get_user_selected_engine().</span></div>
<div class="line"><a name="l00404"></a><span class="lineno">  404</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00405"></a><span class="lineno">  405</span>&#160;<span class="comment"> *  #TODO# clarify naming of functions and entrance point.</span></div>
<div class="line"><a name="l00406"></a><span class="lineno">  406</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00407"></a><span class="lineno"><a class="code" href="engines_8inc.html#ac18b04b38c84979a32603cd5cef78c69">  407</a></span>&#160;<span class="keyword">function</span> <a class="code" href="engines_8inc.html#ac18b04b38c84979a32603cd5cef78c69">drush_find_engine_to_use</a>(&amp;$config, $engine_info, $selected_engine = NULL) {</div>
<div class="line"><a name="l00408"></a><span class="lineno">  408</span>&#160;  <span class="keywordflow">if</span> (!isset($selected_engine)) {</div>
<div class="line"><a name="l00409"></a><span class="lineno">  409</span>&#160;    $selected_engine = $config[<span class="stringliteral">&#39;default&#39;</span>];</div>
<div class="line"><a name="l00410"></a><span class="lineno">  410</span>&#160;  }</div>
<div class="line"><a name="l00411"></a><span class="lineno">  411</span>&#160;  <span class="keywordflow">if</span> (array_key_exists($selected_engine, $engine_info[<span class="stringliteral">&#39;engines&#39;</span>])) {</div>
<div class="line"><a name="l00412"></a><span class="lineno">  412</span>&#160;    $config[<span class="stringliteral">&#39;engine-info&#39;</span>] = $engine_info[<span class="stringliteral">&#39;engines&#39;</span>][$selected_engine];</div>
<div class="line"><a name="l00413"></a><span class="lineno">  413</span>&#160;  }</div>
<div class="line"><a name="l00414"></a><span class="lineno">  414</span>&#160;  <span class="keywordflow">return</span> $selected_engine;</div>
<div class="line"><a name="l00415"></a><span class="lineno">  415</span>&#160;}</div>
<div class="line"><a name="l00416"></a><span class="lineno">  416</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00417"></a><span class="lineno">  417</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00418"></a><span class="lineno">  418</span>&#160;<span class="comment"> * Loads and validate an engine of the given type.</span></div>
<div class="line"><a name="l00419"></a><span class="lineno">  419</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00420"></a><span class="lineno"><a class="code" href="engines_8inc.html#af360562cce71af9828bbbb7326b1d7a8">  420</a></span>&#160;<span class="keyword">function</span> <a class="code" href="engines_8inc.html#af360562cce71af9828bbbb7326b1d7a8">drush_load_engine</a>($type, $engine, $version = NULL, $path = NULL, $engine_config = NULL) {</div>
<div class="line"><a name="l00421"></a><span class="lineno">  421</span>&#160;  $engine_info = <a class="code" href="engines_8inc.html#ae94a82d80d5e90cb126de1f16a7f8fe4">drush_get_engines</a>($type);</div>
<div class="line"><a name="l00422"></a><span class="lineno">  422</span>&#160;  $selected_engine = <a class="code" href="engines_8inc.html#ac18b04b38c84979a32603cd5cef78c69">drush_find_engine_to_use</a>($engine_config, $engine_info, $engine);</div>
<div class="line"><a name="l00423"></a><span class="lineno">  423</span>&#160;  <span class="keywordflow">if</span> (!array_key_exists($selected_engine, $engine_info[<span class="stringliteral">&#39;engines&#39;</span>])) {</div>
<div class="line"><a name="l00424"></a><span class="lineno">  424</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_UNKNOWN_ENGINE_TYPE&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Unknown !engine_type engine !engine&#39;</span>, array(<span class="stringliteral">&#39;!engine&#39;</span> =&gt; $selected_engine, <span class="stringliteral">&#39;!engine_type&#39;</span> =&gt; $type)));</div>
<div class="line"><a name="l00425"></a><span class="lineno">  425</span>&#160;  }</div>
<div class="line"><a name="l00426"></a><span class="lineno">  426</span>&#160;  <span class="comment">// Check engine dependency on drupal modules before include.</span></div>
<div class="line"><a name="l00427"></a><span class="lineno">  427</span>&#160;  <span class="keywordflow">foreach</span> ($engine_config[<span class="stringliteral">&#39;engine-info&#39;</span>][<span class="stringliteral">&#39;drupal dependencies&#39;</span>] as $dependency) {</div>
<div class="line"><a name="l00428"></a><span class="lineno">  428</span>&#160;    <span class="keywordflow">if</span> (!<a class="code" href="commands_2core_2drupal_2environment_8inc.html#a643d851fd8dc63ea2ce8cf67aa33098c">drush_module_exists</a>($dependency)) {</div>
<div class="line"><a name="l00429"></a><span class="lineno">  429</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_ENGINE_DEPENDENCY_ERROR&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;!engine_type: !engine engine needs the following modules installed/enabled to run: !dependencies.&#39;</span>, array(<span class="stringliteral">&#39;!engine_type&#39;</span> =&gt; $type, <span class="stringliteral">&#39;!engine&#39;</span> =&gt; $selected_engine, <span class="stringliteral">&#39;!dependencies&#39;</span> =&gt; implode(<span class="stringliteral">&#39;, &#39;</span>, $engine_config[<span class="stringliteral">&#39;engine-info&#39;</span>][<span class="stringliteral">&#39;drupal dependencies&#39;</span>]))));</div>
<div class="line"><a name="l00430"></a><span class="lineno">  430</span>&#160;    }</div>
<div class="line"><a name="l00431"></a><span class="lineno">  431</span>&#160;  }</div>
<div class="line"><a name="l00432"></a><span class="lineno">  432</span>&#160;  $result = <a class="code" href="engines_8inc.html#a91df31f18b0a1d05540ccaf85e6d9a88">drush_include_engine</a>($type, $selected_engine, $version, $path, $engine_config);</div>
<div class="line"><a name="l00433"></a><span class="lineno">  433</span>&#160;  <span class="keywordflow">if</span> (is_object($result)) {</div>
<div class="line"><a name="l00434"></a><span class="lineno">  434</span>&#160;    $valid = method_exists($result, <span class="stringliteral">&#39;validate&#39;</span>) ? $result-&gt;validate() : TRUE;</div>
<div class="line"><a name="l00435"></a><span class="lineno">  435</span>&#160;    <span class="keywordflow">if</span> ($valid) {</div>
<div class="line"><a name="l00436"></a><span class="lineno">  436</span>&#160;      <a class="code" href="engines_8inc.html#a1eb2ea4e50529f3c7953f419956ce51a">drush_set_engine</a>($type, $result);</div>
<div class="line"><a name="l00437"></a><span class="lineno">  437</span>&#160;    }</div>
<div class="line"><a name="l00438"></a><span class="lineno">  438</span>&#160;  }</div>
<div class="line"><a name="l00439"></a><span class="lineno">  439</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00440"></a><span class="lineno">  440</span>&#160;    $function = strtr($type, <span class="charliteral">&#39;-&#39;</span>, <span class="charliteral">&#39;_&#39;</span>) . <span class="stringliteral">&#39;_validate&#39;</span>;</div>
<div class="line"><a name="l00441"></a><span class="lineno">  441</span>&#160;    $valid = function_exists($function) ? call_user_func($function) : TRUE;</div>
<div class="line"><a name="l00442"></a><span class="lineno">  442</span>&#160;  }</div>
<div class="line"><a name="l00443"></a><span class="lineno">  443</span>&#160;  <span class="keywordflow">if</span> (!$valid) {</div>
<div class="line"><a name="l00444"></a><span class="lineno">  444</span>&#160;    <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l00445"></a><span class="lineno">  445</span>&#160;  }</div>
<div class="line"><a name="l00446"></a><span class="lineno">  446</span>&#160;  <span class="keywordflow">return</span> $result;</div>
<div class="line"><a name="l00447"></a><span class="lineno">  447</span>&#160;}</div>
<div class="line"><a name="l00448"></a><span class="lineno">  448</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00449"></a><span class="lineno">  449</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00450"></a><span class="lineno">  450</span>&#160;<span class="comment"> * Include the engine code for a specific named engine of a certain type.</span></div>
<div class="line"><a name="l00451"></a><span class="lineno">  451</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00452"></a><span class="lineno">  452</span>&#160;<span class="comment"> * If the engine type has implemented hook_drush_engine_$type the path to the</span></div>
<div class="line"><a name="l00453"></a><span class="lineno">  453</span>&#160;<span class="comment"> * engine specified in the array will be used.</span></div>
<div class="line"><a name="l00454"></a><span class="lineno">  454</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00455"></a><span class="lineno">  455</span>&#160;<span class="comment"> * If a class named in the form drush_$type_$engine exists, it will be an</span></div>
<div class="line"><a name="l00456"></a><span class="lineno">  456</span>&#160;<span class="comment"> * object of that class will be created and returned.</span></div>
<div class="line"><a name="l00457"></a><span class="lineno">  457</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00458"></a><span class="lineno">  458</span>&#160;<span class="comment"> * If you don&#39;t need to present any user options for selecting the engine</span></div>
<div class="line"><a name="l00459"></a><span class="lineno">  459</span>&#160;<span class="comment"> * (which is common if the selection is implied by the running environment)</span></div>
<div class="line"><a name="l00460"></a><span class="lineno">  460</span>&#160;<span class="comment"> * and you don&#39;t need to allow other modules to define their own engines you can</span></div>
<div class="line"><a name="l00461"></a><span class="lineno">  461</span>&#160;<span class="comment"> * simply pass the $path to the directory where the engines are, and the</span></div>
<div class="line"><a name="l00462"></a><span class="lineno">  462</span>&#160;<span class="comment"> * appropriate one will be included.</span></div>
<div class="line"><a name="l00463"></a><span class="lineno">  463</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00464"></a><span class="lineno">  464</span>&#160;<span class="comment"> * Unlike drush_include this function will set errors if the requested engine</span></div>
<div class="line"><a name="l00465"></a><span class="lineno">  465</span>&#160;<span class="comment"> * cannot be found.</span></div>
<div class="line"><a name="l00466"></a><span class="lineno">  466</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00467"></a><span class="lineno">  467</span>&#160;<span class="comment"> * @param $type</span></div>
<div class="line"><a name="l00468"></a><span class="lineno">  468</span>&#160;<span class="comment"> *   The type of engine.</span></div>
<div class="line"><a name="l00469"></a><span class="lineno">  469</span>&#160;<span class="comment"> * @param $engine</span></div>
<div class="line"><a name="l00470"></a><span class="lineno">  470</span>&#160;<span class="comment"> *   The key for the engine to be included.</span></div>
<div class="line"><a name="l00471"></a><span class="lineno">  471</span>&#160;<span class="comment"> * @param $version</span></div>
<div class="line"><a name="l00472"></a><span class="lineno">  472</span>&#160;<span class="comment"> *   The version of the engine to be included - defaults to the current Drupal core</span></div>
<div class="line"><a name="l00473"></a><span class="lineno">  473</span>&#160;<span class="comment"> *   major version.</span></div>
<div class="line"><a name="l00474"></a><span class="lineno">  474</span>&#160;<span class="comment"> * @param $path</span></div>
<div class="line"><a name="l00475"></a><span class="lineno">  475</span>&#160;<span class="comment"> *   A path to include from, if the engine has no corresponding</span></div>
<div class="line"><a name="l00476"></a><span class="lineno">  476</span>&#160;<span class="comment"> *   hook_drush_engine_$type item path.</span></div>
<div class="line"><a name="l00477"></a><span class="lineno">  477</span>&#160;<span class="comment"> * @return TRUE or instanced object of available class on success. FALSE on fail.</span></div>
<div class="line"><a name="l00478"></a><span class="lineno">  478</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00479"></a><span class="lineno"><a class="code" href="engines_8inc.html#a91df31f18b0a1d05540ccaf85e6d9a88">  479</a></span>&#160;<span class="keyword">function</span> <a class="code" href="engines_8inc.html#a91df31f18b0a1d05540ccaf85e6d9a88">drush_include_engine</a>($type, $selected_engine, $version = NULL, $path = NULL, $engine_config = NULL) {</div>
<div class="line"><a name="l00480"></a><span class="lineno">  480</span>&#160;  $engine_info = <a class="code" href="engines_8inc.html#ae94a82d80d5e90cb126de1f16a7f8fe4">drush_get_engines</a>($type);</div>
<div class="line"><a name="l00481"></a><span class="lineno">  481</span>&#160;  $engine = isset($engine_info[<span class="stringliteral">&#39;engines&#39;</span>][$selected_engine][<span class="stringliteral">&#39;engine-class&#39;</span>]) ? $engine_info[<span class="stringliteral">&#39;engines&#39;</span>][$selected_engine][<span class="stringliteral">&#39;engine-class&#39;</span>] : $selected_engine;</div>
<div class="line"><a name="l00482"></a><span class="lineno">  482</span>&#160;  <span class="keywordflow">if</span> (!$path &amp;&amp; isset($engine_info[<span class="stringliteral">&#39;engines&#39;</span>][$engine])) {</div>
<div class="line"><a name="l00483"></a><span class="lineno">  483</span>&#160;    $path = $engine_info[<span class="stringliteral">&#39;engines&#39;</span>][$engine][<span class="stringliteral">&#39;path&#39;</span>];</div>
<div class="line"><a name="l00484"></a><span class="lineno">  484</span>&#160;  }</div>
<div class="line"><a name="l00485"></a><span class="lineno">  485</span>&#160;  <span class="keywordflow">if</span> (!$path) {</div>
<div class="line"><a name="l00486"></a><span class="lineno">  486</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_ENGINE_INCLUDE_NO_PATH&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;No path was set for including the !type engine !engine.&#39;</span>, array(<span class="stringliteral">&#39;!type&#39;</span> =&gt; $type, <span class="stringliteral">&#39;!engine&#39;</span> =&gt; $engine)));</div>
<div class="line"><a name="l00487"></a><span class="lineno">  487</span>&#160;  }</div>
<div class="line"><a name="l00488"></a><span class="lineno">  488</span>&#160;  <span class="keywordflow">if</span> (<a class="code" href="drush_8inc.html#a80ce43b30f833522f72180811dab5a3e">drush_include</a>($path, $engine, $version)) {</div>
<div class="line"><a name="l00489"></a><span class="lineno">  489</span>&#160;    $class = <span class="stringliteral">&#39;drush_&#39;</span> . $type . <span class="charliteral">&#39;_&#39;</span> . str_replace(<span class="charliteral">&#39;-&#39;</span>, <span class="charliteral">&#39;_&#39;</span>, $engine);</div>
<div class="line"><a name="l00490"></a><span class="lineno">  490</span>&#160;    <span class="keywordflow">if</span> (class_exists($class)) {</div>
<div class="line"><a name="l00491"></a><span class="lineno">  491</span>&#160;      $instance = <span class="keyword">new</span> $class($engine_config);</div>
<div class="line"><a name="l00492"></a><span class="lineno">  492</span>&#160;      $instance-&gt;engine_type = $type;</div>
<div class="line"><a name="l00493"></a><span class="lineno">  493</span>&#160;      $instance-&gt;engine = $engine;</div>
<div class="line"><a name="l00494"></a><span class="lineno">  494</span>&#160;      $instance-&gt;selected_engine = $selected_engine;</div>
<div class="line"><a name="l00495"></a><span class="lineno">  495</span>&#160;      <span class="keywordflow">return</span> $instance;</div>
<div class="line"><a name="l00496"></a><span class="lineno">  496</span>&#160;    }</div>
<div class="line"><a name="l00497"></a><span class="lineno">  497</span>&#160;    <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l00498"></a><span class="lineno">  498</span>&#160;  }</div>
<div class="line"><a name="l00499"></a><span class="lineno">  499</span>&#160;  <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_ENGINE_INCLUDE_FAILED&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Unable to include the !type engine !engine from !path.&#39;</span> , array(<span class="stringliteral">&#39;!path&#39;</span> =&gt; $path, <span class="stringliteral">&#39;!type&#39;</span> =&gt; $type, <span class="stringliteral">&#39;!engine&#39;</span> =&gt; $engine)));</div>
<div class="line"><a name="l00500"></a><span class="lineno">  500</span>&#160;}</div>
<div class="line"><a name="l00501"></a><span class="lineno">  501</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00502"></a><span class="lineno">  502</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00503"></a><span class="lineno">  503</span>&#160;<span class="comment"> * Return the engine of the specified type that was loaded</span></div>
<div class="line"><a name="l00504"></a><span class="lineno">  504</span>&#160;<span class="comment"> * by the Drush command.</span></div>
<div class="line"><a name="l00505"></a><span class="lineno">  505</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00506"></a><span class="lineno"><a class="code" href="engines_8inc.html#a34ff5c6bb43688e04d0647eddf48d553">  506</a></span>&#160;<span class="keyword">function</span> <a class="code" href="engines_8inc.html#a34ff5c6bb43688e04d0647eddf48d553">drush_get_engine</a>($type) {</div>
<div class="line"><a name="l00507"></a><span class="lineno">  507</span>&#160;  <span class="keywordflow">return</span> <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>($type . <span class="stringliteral">&#39;_engine&#39;</span>, FALSE);</div>
<div class="line"><a name="l00508"></a><span class="lineno">  508</span>&#160;}</div>
<div class="line"><a name="l00509"></a><span class="lineno">  509</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00510"></a><span class="lineno">  510</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00511"></a><span class="lineno">  511</span>&#160;<span class="comment"> * Called by the Drush command (@see _drush_load_command_engines())</span></div>
<div class="line"><a name="l00512"></a><span class="lineno">  512</span>&#160;<span class="comment"> * to cache the active engine instance.</span></div>
<div class="line"><a name="l00513"></a><span class="lineno">  513</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00514"></a><span class="lineno"><a class="code" href="engines_8inc.html#a1eb2ea4e50529f3c7953f419956ce51a">  514</a></span>&#160;<span class="keyword">function</span> <a class="code" href="engines_8inc.html#a1eb2ea4e50529f3c7953f419956ce51a">drush_set_engine</a>($type, $instance) {</div>
<div class="line"><a name="l00515"></a><span class="lineno">  515</span>&#160;  <a class="code" href="context_8inc.html#af983acfe90e7d7bbdbd67c57f93708ba">drush_set_context</a>($type . <span class="stringliteral">&#39;_engine&#39;</span>, $instance);</div>
<div class="line"><a name="l00516"></a><span class="lineno">  516</span>&#160;}</div>
<div class="line"><a name="l00517"></a><span class="lineno">  517</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00518"></a><span class="lineno">  518</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00519"></a><span class="lineno">  519</span>&#160;<span class="comment"> * Add engine topics to the command topics, if any.</span></div>
<div class="line"><a name="l00520"></a><span class="lineno">  520</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00521"></a><span class="lineno"><a class="code" href="engines_8inc.html#a4f5313a2d79cd6fbcde3d30b361e306e">  521</a></span>&#160;<span class="keyword">function</span> <a class="code" href="engines_8inc.html#a4f5313a2d79cd6fbcde3d30b361e306e">drush_engine_add_help_topics</a>(&amp;$command) {</div>
<div class="line"><a name="l00522"></a><span class="lineno">  522</span>&#160;  $engine_types = <a class="code" href="engines_8inc.html#a50374de188af3d1cb754476607b9c375">drush_get_engine_types_info</a>();</div>
<div class="line"><a name="l00523"></a><span class="lineno">  523</span>&#160;  <span class="keywordflow">foreach</span> ($command[<span class="stringliteral">&#39;engines&#39;</span>] as $engine_type =&gt; $config) {</div>
<div class="line"><a name="l00524"></a><span class="lineno">  524</span>&#160;    $info = $engine_types[$engine_type];</div>
<div class="line"><a name="l00525"></a><span class="lineno">  525</span>&#160;    <span class="keywordflow">if</span> (isset($info[<span class="stringliteral">&#39;topics&#39;</span>])) {</div>
<div class="line"><a name="l00526"></a><span class="lineno">  526</span>&#160;      $command[<span class="stringliteral">&#39;topics&#39;</span>] = array_merge($command[<span class="stringliteral">&#39;topics&#39;</span>], $info[<span class="stringliteral">&#39;topics&#39;</span>]);</div>
<div class="line"><a name="l00527"></a><span class="lineno">  527</span>&#160;    }</div>
<div class="line"><a name="l00528"></a><span class="lineno">  528</span>&#160;    <span class="keywordflow">if</span> (isset($info[<span class="stringliteral">&#39;topic&#39;</span>])) {</div>
<div class="line"><a name="l00529"></a><span class="lineno">  529</span>&#160;      $command[<span class="stringliteral">&#39;topics&#39;</span>][] = $info[<span class="stringliteral">&#39;topic&#39;</span>];</div>
<div class="line"><a name="l00530"></a><span class="lineno">  530</span>&#160;    }</div>
<div class="line"><a name="l00531"></a><span class="lineno">  531</span>&#160;  }</div>
<div class="line"><a name="l00532"></a><span class="lineno">  532</span>&#160;}</div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Wed Oct 8 2014 09:04:54 for Drush by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.1.2
</small></address>
</body>
</html>