Drush: includes/context.inc Source File

  1. 7.x doxygen/html/context_8inc_source.html
  2. master doxygen/html/context_8inc_source.html
Go to the documentation of this file.
1 <?php
2 /**
3  * @file
4  * The Drush context API implementation.
5  *
6  * This API acts as a storage mechanism for all options, arguments and
7  * configuration settings that are loaded into drush.
8  *
9  * This API also acts as an IPC mechanism between the different drush commands,
10  * and provides protection from accidentally overriding settings that are
11  * needed by other parts of the system.
12  *
13  * It also avoids the necessity to pass references through the command chain
14  * and allows the scripts to keep track of whether any settings have changed
15  * since the previous execution.
16  *
17  * This API defines several contexts that are used by default.
18  *
19  * Argument contexts :
20  * These contexts are used by Drush to store information on the command.
21  * They have their own access functions in the forms of
24  *
25  * command : The drush command being executed.
26  * arguments : Any additional arguments that were specified.
27  *
28  * Setting contexts :
29  * These contexts store options that have been passed to the drush.php
30  * script, either through the use of any of the config files, directly from
31  * the command line through --option='value' or through a JSON encoded string
32  * passed through the STDIN pipe.
33  *
34  * These contexts are accessible through the drush_get_option() and
35  * drush_set_option() functions. See drush_context_names() for a description
36  * of all of the contexts.
37  *
38  * Drush commands may also choose to save settings for a specific context to
39  * the matching configuration file through the drush_save_config() function.
40  */
41 
42 
43 /**
44  * Return a list of the valid drush context names.
45  *
46  * These context names are carefully ordered from
47  * highest to lowest priority.
48  *
49  * These contexts are evaluated in a certain order, and the highest priority value
50  * is returned by default from drush_get_option. This allows scripts to check whether
51  * an option was different before the current execution.
52  *
53  * Specified by the script itself :
54  * process : Generated in the current process.
55  * cli : Passed as --option=value to the command line.
56  * stdin : Passed as a JSON encoded string through stdin.
57  * specific : Defined in a command-specific option record, and
58  * set in the command context whenever that command is used.
59  * alias : Defined in an alias record, and set in the
60  * alias context whenever that alias is used.
61  *
62  * Specified by config files :
63  * custom : Loaded from the config file specified by --config or -c
64  * site : Loaded from the drushrc.php file in the Drupal site directory.
65  * drupal : Loaded from the drushrc.php file in the Drupal root directory.
66  * user : Loaded from the drushrc.php file in the user's home directory.
67  * home.drush Loaded from the drushrc.php file in the $HOME/.drush directory.
68  * system : Loaded from the drushrc.php file in the system's $PREFIX/etc/drush directory.
69  * drush : Loaded from the drushrc.php file in the same directory as drush.php.
70  *
71  * Specified by the script, but has the lowest priority :
72  * default : The script might provide some sensible defaults during init.
73  */
74 function drush_context_names() {
75  static $contexts = array(
76  'process', 'cli', 'stdin', 'specific', 'alias',
77  'custom', 'site', 'drupal', 'user', 'home.drush', 'system',
78  'drush', 'default');
79 
80  return $contexts;
81 }
82 
83 /**
84  * Return a list of possible drushrc file locations.
85  *
86  * @context
87  * A valid drush context from drush_context_names().
88  * @prefix
89  * Optional. Specify a prefix to prepend to ".drushrc.php" when looking
90  * for config files. Most likely used by contrib commands.
91  * @return
92  * An associative array containing possible config files to load
93  * The keys are the 'context' of the files, the values are the file
94  * system locations.
95  */
96 function _drush_config_file($context, $prefix = NULL, $version = '') {
97  $configs = array();
98  $base_name = 'drush' . $version . 'rc.php';
99  $config_file = $prefix ? $prefix . '.' . $base_name : $base_name;
100 
101  // Did the user explicitly specify a config file?
102  if ($config_list = (array)drush_get_context('DRUSH_CONFIG')) {
103  foreach ($config_list as $config) {
104  if (is_dir($config)) {
105  $config = $config . '/' . $config_file;
106  }
107  $configs['custom'][] = $config;
108  }
109  }
110 
111  if ($drupal_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT')) {
112  $configs['drupal'] = array(
113  $drupal_root . '/sites/all/drush/' . $config_file,
114  $drupal_root . '/drush/' . $config_file,
115  );
116 
117  if ($conf_path = drush_get_context('DRUSH_SELECTED_DRUPAL_SITE_CONF_PATH')) {
118  $site_path = $drupal_root . '/' . $conf_path;
119  $configs['site'] = $site_path . "/" . $config_file;
120  }
121  }
122 
123  // in the user home directory
124  $server_home = drush_server_home();
125  if (isset($server_home)) {
126  $configs['user'] = $server_home . '/.' . $config_file;
127  }
128 
129  // in $HOME/.drush directory
130  $per_user_config_dir = drush_get_context('DRUSH_PER_USER_CONFIGURATION');
131  if (!empty($per_user_config_dir)) {
132  $configs['home.drush'] = $per_user_config_dir . '/' . $config_file;
133  }
134 
135  // In the system wide configuration folder.
136  $configs['system'] = drush_get_context('DRUSH_SITE_WIDE_CONFIGURATION') . '/' . $config_file;
137 
138  // in the drush installation folder
139  $configs['drush'] = dirname(__FILE__) . '/../' . $config_file;
140 
141  return empty($configs[$context]) ? '' : $configs[$context];
142 }
143 
144 
145 /**
146  * Load drushrc files (if available) from several possible locations.
147  */
148 function drush_load_config($context) {
149  drush_load_config_file($context, _drush_config_file($context));
150  drush_load_config_file($context, _drush_config_file($context, '', DRUSH_MAJOR_VERSION));
151 }
152 
153 function drush_load_config_file($context, $config_list) {
154  foreach ((array)$config_list as $config) {
155  if (file_exists($config)) {
156  $options = $aliases = $command_specific = $override = array();
157  drush_log(dt('Loading drushrc "!config" into "!context" scope.', array('!config' => realpath($config), '!context' => $context)), 'bootstrap');
158  $ret = @include_once($config);
159  if ($ret === FALSE) {
160  drush_log(dt('Cannot open drushrc "!config", ignoring.', array('!config' => realpath($config))), 'warning');
161  return FALSE;
162  }
163  if (!empty($options) || !empty($aliases) || !empty($command_specific) || !empty($override)) {
164  $options = array_merge(drush_get_context($context), $options);
165  $options['config-file'] = realpath($config);
166 
167  unset($options['site-aliases']);
168  $options['command-specific'] = array_merge(isset($command_specific) ? $command_specific : array(), isset($options['command-specific']) ? $options['command-specific'] : array());
169 
170  drush_set_config_options($context, $options, $override);
171  }
172  }
173  }
174 }
175 
176 function drush_set_config_options($context, $options, $override = array()) {
177  // Copy 'config-file' into 'context-path', converting to an array to hold multiple values if necessary
178  if (isset($options['config-file'])) {
179  if (isset($options['context-path'])) {
180  $options['context-path'] = array_merge(array($options['config-file']), is_array($options['context-path']) ? $options['context-path'] : array($options['context-path']));
181  }
182  else {
183  $options['context-path'] = $options['config-file'];
184  }
185  }
186 
187  // Take out $aliases and $command_specific options
189 
190  drush_set_context($context, $options);
191 }
192 
193 /**
194  * For all global options with a short form, convert all options in the option
195  * array that use the short form into the long form.
196  */
197 function drush_expand_short_form_options(&$options) {
198  foreach (drush_get_global_options() as $name => $info) {
199  if (is_array($info)) {
200  // For any option with a short form, check to see if the short form was set in the
201  // options. If it was, then rename it to its long form.
202  if (array_key_exists('short-form', $info) && array_key_exists($info['short-form'], $options)) {
203  if (!array_key_exists($name, $options) || !array_key_exists('merge-pathlist', $info)) {
204  $options[$name] = $options[$info['short-form']];
205  }
206  else {
207  $options[$name] = array_merge((array)$options[$name], (array)$options[$info['short-form']]);
208  }
209  unset($options[$info['short-form']]);
210  }
211  }
212  }
213 }
214 
215 /**
216  * There are certain options such as 'site-aliases' and 'command-specific'
217  * that must be merged together if defined in multiple drush configuration
218  * files. If we did not do this merge, then the last configuration file
219  * that defined any of these properties would overwrite all of the options
220  * that came before in previously-loaded configuration files. We place
221  * all of them into their own context so that this does not happen.
222  */
224  if (isset($options) && is_array($options)) {
225  $has_command_specific = array_key_exists('command-specific', $options);
226  // Change the keys of the site aliases from 'alias' to '@alias'
227  if (array_key_exists('site-aliases', $options)) {
228  $user_aliases = $options['site-aliases'];
229  $options['site-aliases'] = array();
230  foreach ($user_aliases as $alias_name => $alias_value) {
231  if (substr($alias_name,0,1) != '@') {
232  $alias_name = "@$alias_name";
233  }
234  $options['site-aliases'][$alias_name] = $alias_value;
235  }
236  }
237  // Expand -s into --simulate, etc.
239 
240  foreach (drush_get_global_options() as $name => $info) {
241  if (is_array($info)) {
242  // For any global option with the 'merge-pathlist' or 'merge-associative' flag, set its
243  // value in the specified context. The option is 'merged' because we
244  // load $options with the value from the context prior to including the
245  // configuration file. If the configuration file sets $option['special'][] = 'value',
246  // then the configuration will be merged. $option['special'] = array(...), on the
247  // other hand, will replace rather than merge the values together.
248  if ((array_key_exists($name, $options)) && (array_key_exists('merge', $info) || (array_key_exists('merge-pathlist', $info) || array_key_exists('merge-associative', $info)))) {
249  $context = array_key_exists('context', $info) ? $info['context'] : $name;
250  $cache =& drush_get_context($context);
251  $value = $options[$name];
252  if (!is_array($value) && array_key_exists('merge-pathlist', $info)) {
253  $value = explode(PATH_SEPARATOR, $value);
254  }
255  if (array_key_exists('merge-associative', $info)) {
256  foreach ($value as $subkey => $subvalue) {
257  $cache[$subkey] = array_merge(isset($cache[$subkey]) ? $cache[$subkey] : array(), $subvalue);
258  }
259  }
260  else {
261  $cache = array_unique(array_merge($cache, $value));
262  }
263  // Once we have moved the option to its special context, we
264  // can remove it from its option context -- unless 'propagate-cli-value'
265  // is set, in which case we need to let it stick around in options
266  // in case it is needed in backend invoke.
267  if (!array_key_exists('propagate-cli-value', $info)) {
268  unset($options[$name]);
269  }
270  }
271  }
272  }
273 
274  // If command-specific options were set and if we already have
275  // a command, then apply the command-specific options immediately.
276  if ($has_command_specific) {
278  }
279  }
280 }
281 
282 /**
283  * Set a specific context.
284  *
285  * @param context
286  * Any of the default defined contexts.
287  * @param value
288  * The value to store in the context
289  *
290  * @return
291  * An associative array of the settings specified in the request context.
292  */
293 function drush_set_context($context, $value) {
294  $cache =& drush_get_context($context);
295  $cache = $value;
296  return $value;
297 }
298 
299 
300 /**
301  * Return a specific context, or the whole context cache
302  *
303  * This function provides a storage mechanism for any information
304  * the currently running process might need to communicate.
305  *
306  * This avoids the use of globals, and constants.
307  *
308  * Functions that operate on the context cache, can retrieve a reference
309  * to the context cache using :
310  * $cache = &drush_get_context($context);
311  *
312  * This is a private function, because it is meant as an internal
313  * generalized API for writing static cache functions, not as a general
314  * purpose function to be used inside commands.
315  *
316  * Code that modifies the reference directly might have unexpected consequences,
317  * such as modifying the arguments after they have already been parsed and dispatched
318  * to the callbacks.
319  *
320  * @param context
321  * Optional. Any of the default defined contexts.
322  *
323  * @return
324  * If context is not supplied, the entire context cache will be returned.
325  * Otherwise only the requested context will be returned.
326  * If the context does not exist yet, it will be initialized to an empty array.
327  */
328 function &drush_get_context($context = NULL, $default = NULL) {
329  static $cache = array();
330  if (isset($context)) {
331  if (!isset($cache[$context])) {
332  $default = !isset($default) ? array() : $default;
333  $cache[$context] = $default;
334  }
335  return $cache[$context];
336  }
337  return $cache;
338 }
339 
340 /**
341  * Set the arguments passed to the drush.php script.
342  *
343  * This function will set the 'arguments' context of the current running script.
344  *
345  * When initially called by drush_parse_args, the entire list of arguments will
346  * be populated. Once the command is dispatched, this will be set to only the remaining
347  * arguments to the command (i.e. the command name is removed).
348  *
349  * @param arguments
350  * Command line arguments, as an array.
351  */
352 function drush_set_arguments($arguments) {
353  drush_set_context('arguments', $arguments);
354 }
355 
356 /**
357  * Gets the command line arguments passed to Drush.
358  *
359  * @return array
360  * An indexed array of arguments. Until Drush has dispatched the command, the
361  * array will include the command name as the first element. After that point
362  * the array will not include the command name.
363  *
364  * @see drush_set_arguments()
365  */
367  return drush_get_context('arguments');
368 }
369 
370 /**
371  * Set the command being executed.
372  *
373  * Drush_dispatch will set the correct command based on it's
374  * matching of the script arguments retrieved from drush_get_arguments
375  * to the implemented commands specified by drush_get_commands.
376  *
377  * @param
378  * A numerically indexed array of command components.
379  */
380 function drush_set_command($command) {
381  drush_set_context('command', $command);
382 }
383 
384 /**
385  * Return the command being executed.
386  */
387 function drush_get_command() {
388  return drush_get_context('command');
389 }
390 
391 /**
392  * Get the value for an option.
393  *
394  * If the first argument is an array, then it checks whether one of the options
395  * exists and return the value of the first one found. Useful for allowing both
396  * -h and --host-name
397  *
398  * @param option
399  * The name of the option to get
400  * @param default
401  * Optional. The value to return if the option has not been set
402  * @param context
403  * Optional. The context to check for the option. If this is set, only this context will be searched.
404  */
405 function drush_get_option($option, $default = NULL, $context = NULL) {
406  $value = NULL;
407 
408  if ($context) {
409  // We have a definite context to check for the presence of an option.
410  $value = _drush_get_option($option, drush_get_context($context));
411  }
412  else {
413  // We are not checking a specific context, so check them in a predefined order of precedence.
414  $contexts = drush_context_names();
415 
416  foreach ($contexts as $context) {
417  $value = _drush_get_option($option, drush_get_context($context));
418 
419  if ($value !== NULL) {
420  return $value;
421  }
422  }
423  }
424 
425  if ($value !== NULL) {
426  return $value;
427  }
428 
429  return $default;
430 }
431 
432 /**
433  * Get the value for an option and return it as a list. If the
434  * option in question is passed on the command line, its value should
435  * be a comma-separated list (e.g. --flag=1,2,3). If the option
436  * was set in a drushrc.php file, then its value may be either a
437  * comma-separated list or an array of values (e.g. $option['flag'] = array('1', '2', '3')).
438  *
439  * @param option
440  * The name of the option to get
441  * @param default
442  * Optional. The value to return if the option has not been set
443  * @param context
444  * Optional. The context to check for the option. If this is set, only this context will be searched.
445  */
446 function drush_get_option_list($option, $default = array(), $context = NULL) {
447  $result = drush_get_option($option, $default, $context);
448 
449  if (!is_array($result)) {
450  $result = array_map('trim', array_filter(explode(',', $result)));
451  }
452 
453  return $result;
454 }
455 
456 /**
457  * Get the value for an option, but first checks the provided option overrides.
458  *
459  * The feature of drush_get_option that allows a list of option names
460  * to be passed in an array is NOT supported.
461  *
462  * @param option_overrides
463  * An array to check for values before calling drush_get_option.
464  * @param option
465  * The name of the option to get.
466  * @param default
467  * Optional. The value to return if the option has not been set.
468  * @param context
469  * Optional. The context to check for the option. If this is set, only this context will be searched.
470  *
471  */
472 function drush_get_option_override($option_overrides, $option, $default = NULL, $context = NULL) {
473  return drush_sitealias_get_option($option_overrides, $option, $default, '', $context);
474 }
475 
476 /**
477  * Get an option out of the specified alias. If it has not been
478  * set in the alias, then get it via drush_get_option.
479  *
480  * @param site_alias_record
481  * An array of options for an alias record.
482  * @param option
483  * The name of the option to get.
484  * @param default
485  * Optional. The value to return if the option does not exist in the site record and has not been set in a context.
486  * @param context
487  * Optional. The context to check for the option. If this is set, only this context will be searched.
488  */
489 function drush_sitealias_get_option($site_alias_record, $option, $default = NULL, $prefix = '', $context = NULL) {
490  if (is_array($site_alias_record) && array_key_exists($option, $site_alias_record)) {
491  return $site_alias_record[$option];
492  }
493  else {
494  return drush_get_option($prefix . $option, $default, $context);
495  }
496 }
497 
498 /**
499  * Get all of the values for an option in every context.
500  *
501  * @param option
502  * The name of the option to get
503  * @return
504  * An array whose key is the context name and value is
505  * the specific value for the option in that context.
506  */
507 function drush_get_context_options($option, $flatten = FALSE) {
508  $result = array();
509 
510  $contexts = drush_context_names();
511  foreach ($contexts as $context) {
512  $value = _drush_get_option($option, drush_get_context($context));
513 
514  if ($value !== NULL) {
515  if ($flatten && is_array($value)) {
516  $result = array_merge($value, $result);
517  }
518  else {
519  $result[$context] = $value;
520  }
521  }
522  }
523 
524  return $result;
525 }
526 
527 /**
528  * Retrieves a collapsed list of all options.
529  */
531  $contexts = drush_context_names();
532  $cache = drush_get_context();
533  $result = array();
534  foreach (array_reverse($contexts) as $context) {
535  if (array_key_exists($context, $cache)) {
536  $result = array_merge($result, $cache[$context]);
537  }
538  }
539 
540  return $result;
541 }
542 
543 /**
544  * Retrieves a collapsed list of all options
545  * with a specified prefix.
546  */
548  $merged_options = drush_get_merged_options();
549  $result = array();
550  foreach ($merged_options as $key => $value) {
551  if ($prefix == substr($key, 0, strlen($prefix))) {
552  $result[substr($key, strlen($prefix))] = $value;
553  }
554  }
555 
556  return $result;
557 }
558 
559 /**
560  * Helper function to recurse through possible option names
561  */
562 function _drush_get_option($option, $context) {
563  if (is_array($option)) {
564  foreach ($option as $current) {
565  if (array_key_exists($current, $context)) {
566  return $context[$current];
567  }
568  }
569  }
570  elseif (array_key_exists($option, $context)) {
571  return $context[$option];
572  }
573 
574  return NULL;
575 }
576 
577 /**
578  * Set an option in one of the option contexts.
579  *
580  * @param option
581  * The option to set.
582  * @param value
583  * The value to set it to.
584  * @param context
585  * Optional. Which context to set it in.
586  * @return
587  * The value parameter. This allows for neater code such as
588  * $myvalue = drush_set_option('http_host', $_SERVER['HTTP_HOST']);
589  * Without having to constantly type out the value parameter.
590  */
591 function drush_set_option($option, $value, $context = 'process') {
592  $cache =& drush_get_context($context);
593  $cache[$option] = $value;
594  return $value;
595 }
596 
597 /**
598  * A small helper function to set the value in the default context
599  */
600 function drush_set_default($option, $value) {
601  return drush_set_option($option, $value, 'default');
602 }
603 
604 /**
605  * Remove a setting from a specific context.
606  *
607  * @param
608  * Option to be unset
609  * @param
610  * Context in which to unset the value in.
611  */
612 function drush_unset_option($option, $context = NULL) {
613  if ($context != NULL) {
614  $cache =& drush_get_context($context);
615  if (array_key_exists($option, $cache)) {
616  unset($cache[$option]);
617  }
618  }
619  else {
620  $contexts = drush_context_names();
621 
622  foreach ($contexts as $context) {
623  drush_unset_option($option, $context);
624  }
625  }
626 }
627 
628 /**
629  * Save the settings in a specific context to the applicable configuration file
630  * This is useful is you want certain settings to be available automatically the next time a command is executed.
631  *
632  * @param $context
633  * The context to save
634  */
635 function drush_save_config($context) {
636  $filename = _drush_config_file($context);
637  if (is_array($filename)) {
638  $filename = $filename[0];
639  }
640 
641  if ($filename) {
642  $cache = drush_get_context($context);
643 
644  $fp = fopen($filename, "w+");
645  if (!$fp) {
646  return drush_set_error('DRUSH_PERM_ERROR', dt('Drushrc (!filename) could not be written', array('!filename' => $filename)));
647  }
648  else {
649  fwrite($fp, "<?php\n");
650  foreach ($cache as $key => $value) {
651  $line = "\n\$options['$key'] = ". var_export($value, TRUE) .';';
652  fwrite($fp, $line);
653  }
654  fwrite($fp, "\n");
655  fclose($fp);
656  drush_log(dt('Drushrc file (!filename) was written successfully', array('!filename' => $filename)));
657  return TRUE;
658  }
659 
660  }
661  return FALSE;
662 }

File

doxygen/html/context_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/context.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">context.inc</div>  </div>
</div><!--header-->
<div class="contents">
<a href="context_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<span class="comment"></span></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"> * @file</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * The Drush context API implementation.</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> * This API acts as a storage mechanism for all options, arguments and</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> * configuration settings that are loaded into drush.</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"> * This API also acts as an IPC mechanism between the different drush commands,</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"> * and provides protection from accidentally overriding settings that are</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment"> * needed by other parts of the system.</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">   13</span>&#160;<span class="comment"> * It also avoids the necessity to pass references through the command chain</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment"> * and allows the scripts to keep track of whether any settings have changed</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment"> * since the previous execution.</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="comment"> * This API defines several contexts that are used by default.</span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="comment"> * Argument contexts :</span></div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="comment"> *   These contexts are used by Drush to store information on the command.</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="comment"> *   They have their own access functions in the forms of</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="comment"> *   drush_set_arguments(), drush_get_arguments(), drush_set_command(),</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="comment"> *   drush_get_command().</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="comment"> *     command : The drush command being executed.</span></div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="comment"> *     arguments : Any additional arguments that were specified.</span></div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;<span class="comment"> * Setting contexts :</span></div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;<span class="comment"> *   These contexts store options that have been passed to the drush.php</span></div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;<span class="comment"> *   script, either through the use of any of the config files, directly from</span></div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;<span class="comment"> *   the command line through --option=&#39;value&#39; or through a JSON encoded string</span></div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;<span class="comment"> *   passed through the STDIN pipe.</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"> *   These contexts are accessible through the drush_get_option() and</span></div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;<span class="comment"> *   drush_set_option() functions.  See drush_context_names() for a description</span></div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;<span class="comment"> *   of all of the contexts.</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"> *   Drush commands may also choose to save settings for a specific context to</span></div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;<span class="comment"> *   the matching configuration file through the drush_save_config() function.</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;</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;<span class="comment"> * Return a list of the valid drush context names.</span></div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;<span class="comment"> * These context names are carefully ordered from</span></div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;<span class="comment"> * highest to lowest priority.</span></div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;<span class="comment"> * These contexts are evaluated in a certain order, and the highest priority value</span></div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;<span class="comment"> * is returned by default from drush_get_option. This allows scripts to check whether</span></div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;<span class="comment"> * an option was different before the current execution.</span></div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;<span class="comment"> *   Specified by the script itself :</span></div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;<span class="comment"> *     process  : Generated in the current process.</span></div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;<span class="comment"> *     cli      : Passed as --option=value to the command line.</span></div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;<span class="comment"> *     stdin    : Passed as a JSON encoded string through stdin.</span></div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;<span class="comment"> *     specific : Defined in a command-specific option record, and</span></div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;<span class="comment"> *                set in the command context whenever that command is used.</span></div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;<span class="comment"> *     alias    : Defined in an alias record, and set in the</span></div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;<span class="comment"> *                alias context whenever that alias is used.</span></div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;<span class="comment"> *   Specified by config files :</span></div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;<span class="comment"> *     custom   : Loaded from the config file specified by --config or -c</span></div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;<span class="comment"> *     site     : Loaded from the drushrc.php file in the Drupal site directory.</span></div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;<span class="comment"> *     drupal   : Loaded from the drushrc.php file in the Drupal root directory.</span></div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;<span class="comment"> *     user     : Loaded from the drushrc.php file in the user&#39;s home directory.</span></div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;<span class="comment"> *     home.drush Loaded from the drushrc.php file in the $HOME/.drush directory.</span></div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;<span class="comment"> *     system   : Loaded from the drushrc.php file in the system&#39;s $PREFIX/etc/drush directory.</span></div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;<span class="comment"> *     drush    : Loaded from the drushrc.php file in the same directory as drush.php.</span></div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;<span class="comment"> *   Specified by the script, but has the lowest priority :</span></div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;<span class="comment"> *     default  : The script might provide some sensible defaults during init.</span></div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00074"></a><span class="lineno"><a class="code" href="context_8inc.html#a9f6272c1a68141ce873c07aae3a316ac">   74</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#a9f6272c1a68141ce873c07aae3a316ac">drush_context_names</a>() {</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;  <span class="keyword">static</span> $contexts = array(</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;    <span class="stringliteral">&#39;process&#39;</span>, <span class="stringliteral">&#39;cli&#39;</span>, <span class="stringliteral">&#39;stdin&#39;</span>, <span class="stringliteral">&#39;specific&#39;</span>, <span class="stringliteral">&#39;alias&#39;</span>,</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;    <span class="stringliteral">&#39;custom&#39;</span>, <span class="stringliteral">&#39;site&#39;</span>, <span class="stringliteral">&#39;drupal&#39;</span>, <span class="stringliteral">&#39;user&#39;</span>, <span class="stringliteral">&#39;home.drush&#39;</span>, <span class="stringliteral">&#39;system&#39;</span>,</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;    <span class="stringliteral">&#39;drush&#39;</span>, <span class="stringliteral">&#39;default&#39;</span>);</div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;  <span class="keywordflow">return</span> $contexts;</div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;}</div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;<span class="comment"> * Return a list of possible drushrc file locations.</span></div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;<span class="comment"> * @context</span></div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;<span class="comment"> *   A valid drush context from drush_context_names().</span></div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;<span class="comment"> * @prefix</span></div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;<span class="comment"> *   Optional. Specify a prefix to prepend to &quot;.drushrc.php&quot; when looking</span></div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;<span class="comment"> *   for config files. Most likely used by contrib commands.</span></div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;<span class="comment"> *   An associative array containing possible config files to load</span></div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;<span class="comment"> *   The keys are the &#39;context&#39; of the files, the values are the file</span></div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;<span class="comment"> *   system locations.</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="context_8inc.html#a4eb577b3ff1b1c25213a74cb5813b42f">   96</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#a4eb577b3ff1b1c25213a74cb5813b42f">_drush_config_file</a>($context, $prefix = NULL, $version = <span class="stringliteral">&#39;&#39;</span>) {</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;  $configs = array();</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;  $base_name = <span class="stringliteral">&#39;drush&#39;</span> . $version . <span class="stringliteral">&#39;rc.php&#39;</span>;</div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;  $config_file = $prefix ? $prefix . <span class="charliteral">&#39;.&#39;</span> . $base_name : $base_name;</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;  <span class="comment">// Did the user explicitly specify a config file?</span></div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;  <span class="keywordflow">if</span> ($config_list = (array)<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_CONFIG&#39;</span>)) {</div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;    <span class="keywordflow">foreach</span> ($config_list as $config) {</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;      <span class="keywordflow">if</span> (is_dir($config)) {</div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;        $config = $config . <span class="charliteral">&#39;/&#39;</span> . $config_file;</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;      }</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;      $configs[<span class="stringliteral">&#39;custom&#39;</span>][] = $config;</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">if</span> ($drupal_root = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_SELECTED_DRUPAL_ROOT&#39;</span>)) {</div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;    $configs[<span class="stringliteral">&#39;drupal&#39;</span>] = array(</div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;      $drupal_root . <span class="stringliteral">&#39;/sites/all/drush/&#39;</span> . $config_file,</div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;      $drupal_root . <span class="stringliteral">&#39;/drush/&#39;</span> . $config_file,</div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;    );</div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;</div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;    <span class="keywordflow">if</span> ($conf_path = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_SELECTED_DRUPAL_SITE_CONF_PATH&#39;</span>)) {</div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;      $site_path = $drupal_root . <span class="charliteral">&#39;/&#39;</span> . $conf_path;</div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;      $configs[<span class="stringliteral">&#39;site&#39;</span>] = $site_path . <span class="stringliteral">&quot;/&quot;</span> . $config_file;</div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;    }</div>
<div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;  }</div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;</div>
<div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;  <span class="comment">// in the user home directory</span></div>
<div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;  $server_home = <a class="code" href="includes_2environment_8inc.html#afae6d4a5a12623e5502ca262346c799b">drush_server_home</a>();</div>
<div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;  <span class="keywordflow">if</span> (isset($server_home)) {</div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;    $configs[<span class="stringliteral">&#39;user&#39;</span>] = $server_home . <span class="stringliteral">&#39;/.&#39;</span> . $config_file;</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;</div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;  <span class="comment">// in $HOME/.drush directory</span></div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;  $per_user_config_dir = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_PER_USER_CONFIGURATION&#39;</span>);</div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;  <span class="keywordflow">if</span> (!empty($per_user_config_dir)) {</div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;    $configs[<span class="stringliteral">&#39;home.drush&#39;</span>] = $per_user_config_dir . <span class="charliteral">&#39;/&#39;</span> . $config_file;</div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;  }</div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;</div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;  <span class="comment">// In the system wide configuration folder.</span></div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;  $configs[<span class="stringliteral">&#39;system&#39;</span>] = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_SITE_WIDE_CONFIGURATION&#39;</span>) . <span class="charliteral">&#39;/&#39;</span> . $config_file;</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="comment">// in the drush installation folder</span></div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;  $configs[<span class="stringliteral">&#39;drush&#39;</span>] = dirname(__FILE__) . <span class="stringliteral">&#39;/../&#39;</span> . $config_file;</div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;</div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;  <span class="keywordflow">return</span> empty($configs[$context]) ? <span class="stringliteral">&#39;&#39;</span> : $configs[$context];</div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;}</div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;</div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;<span class="comment"></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">  146</span>&#160;<span class="comment"> * Load drushrc files (if available) from several possible locations.</span></div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00148"></a><span class="lineno"><a class="code" href="context_8inc.html#a0cc90f947ca5cfe0ee524a4e76298bac">  148</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#a0cc90f947ca5cfe0ee524a4e76298bac">drush_load_config</a>($context) {</div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;  drush_load_config_file($context, <a class="code" href="context_8inc.html#a4eb577b3ff1b1c25213a74cb5813b42f">_drush_config_file</a>($context));</div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;  drush_load_config_file($context, <a class="code" href="context_8inc.html#a4eb577b3ff1b1c25213a74cb5813b42f">_drush_config_file</a>($context, <span class="stringliteral">&#39;&#39;</span>, DRUSH_MAJOR_VERSION));</div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;}</div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;</div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;<span class="keyword">function</span> drush_load_config_file($context, $config_list) {</div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;  <span class="keywordflow">foreach</span> ((array)$config_list as $config) {</div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;    <span class="keywordflow">if</span> (file_exists($config)) {</div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;      $options = $aliases = $command_specific = $override = array();</div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</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">&#39;Loading drushrc &quot;!config&quot; into &quot;!context&quot; scope.&#39;</span>, array(<span class="stringliteral">&#39;!config&#39;</span> =&gt; realpath($config), <span class="stringliteral">&#39;!context&#39;</span> =&gt; $context)), <span class="stringliteral">&#39;bootstrap&#39;</span>);</div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;      $ret = @include_once($config);</div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;      <span class="keywordflow">if</span> ($ret === FALSE) {</div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</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">&#39;Cannot open drushrc &quot;!config&quot;, ignoring.&#39;</span>, array(<span class="stringliteral">&#39;!config&#39;</span> =&gt; realpath($config))), <span class="stringliteral">&#39;warning&#39;</span>);</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;        <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;      }</div>
<div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;      <span class="keywordflow">if</span> (!empty($options) || !empty($aliases) || !empty($command_specific) || !empty($override)) {</div>
<div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;        $options = array_merge(<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>($context), $options);</div>
<div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;        $options[<span class="stringliteral">&#39;config-file&#39;</span>] = realpath($config);</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;        unset($options[<span class="stringliteral">&#39;site-aliases&#39;</span>]);</div>
<div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;        $options[<span class="stringliteral">&#39;command-specific&#39;</span>] = array_merge(isset($command_specific) ? $command_specific : array(), isset($options[<span class="stringliteral">&#39;command-specific&#39;</span>]) ? $options[<span class="stringliteral">&#39;command-specific&#39;</span>] : array());</div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;</div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;        drush_set_config_options($context, $options, $override);</div>
<div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;      }</div>
<div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;    }</div>
<div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;  }</div>
<div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;}</div>
<div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;</div>
<div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;<span class="keyword">function</span> drush_set_config_options($context, $options, $override = array()) {</div>
<div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;  <span class="comment">// Copy &#39;config-file&#39; into &#39;context-path&#39;, converting to an array to hold multiple values if necessary</span></div>
<div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;  <span class="keywordflow">if</span> (isset($options[<span class="stringliteral">&#39;config-file&#39;</span>])) {</div>
<div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;    <span class="keywordflow">if</span> (isset($options[<span class="stringliteral">&#39;context-path&#39;</span>])) {</div>
<div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;      $options[<span class="stringliteral">&#39;context-path&#39;</span>] = array_merge(array($options[<span class="stringliteral">&#39;config-file&#39;</span>]), is_array($options[<span class="stringliteral">&#39;context-path&#39;</span>]) ? $options[<span class="stringliteral">&#39;context-path&#39;</span>] : array($options[<span class="stringliteral">&#39;context-path&#39;</span>]));</div>
<div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;    }</div>
<div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;      $options[<span class="stringliteral">&#39;context-path&#39;</span>] = $options[<span class="stringliteral">&#39;config-file&#39;</span>];</div>
<div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;    }</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">// Take out $aliases and $command_specific options</span></div>
<div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;  <a class="code" href="context_8inc.html#a16a51c5b09d64e968c3bd7ec414b8846">drush_set_config_special_contexts</a>($options);</div>
<div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;</div>
<div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;  <a class="code" href="context_8inc.html#af983acfe90e7d7bbdbd67c57f93708ba">drush_set_context</a>($context, $options);</div>
<div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;}</div>
<div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;<span class="comment"> * For all global options with a short form, convert all options in the option</span></div>
<div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;<span class="comment"> * array that use the short form into the long form.</span></div>
<div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00197"></a><span class="lineno"><a class="code" href="context_8inc.html#a2082bda0c615dc7163f69851ddd8edaf">  197</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#a2082bda0c615dc7163f69851ddd8edaf">drush_expand_short_form_options</a>(&amp;$options) {</div>
<div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;  <span class="keywordflow">foreach</span> (<a class="code" href="drush_8inc.html#acb0a26e79bcbdd1152d59a6916a35aae">drush_get_global_options</a>() as $name =&gt; $info) {</div>
<div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;    <span class="keywordflow">if</span> (is_array($info)) {</div>
<div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;      <span class="comment">// For any option with a short form, check to see if the short form was set in the</span></div>
<div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;      <span class="comment">// options.  If it was, then rename it to its long form.</span></div>
<div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;      <span class="keywordflow">if</span> (array_key_exists(<span class="stringliteral">&#39;short-form&#39;</span>, $info) &amp;&amp; array_key_exists($info[<span class="stringliteral">&#39;short-form&#39;</span>], $options)) {</div>
<div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;        <span class="keywordflow">if</span> (!array_key_exists($name, $options) || !array_key_exists(<span class="stringliteral">&#39;merge-pathlist&#39;</span>, $info)) {</div>
<div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;          $options[$name] = $options[$info[<span class="stringliteral">&#39;short-form&#39;</span>]];</div>
<div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;        }</div>
<div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;        <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160;          $options[$name] = array_merge((array)$options[$name], (array)$options[$info[<span class="stringliteral">&#39;short-form&#39;</span>]]);</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;        unset($options[$info[<span class="stringliteral">&#39;short-form&#39;</span>]]);</div>
<div class="line"><a name="l00210"></a><span class="lineno">  210</span>&#160;      }</div>
<div class="line"><a name="l00211"></a><span class="lineno">  211</span>&#160;    }</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;}</div>
<div class="line"><a name="l00214"></a><span class="lineno">  214</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00215"></a><span class="lineno">  215</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00216"></a><span class="lineno">  216</span>&#160;<span class="comment"> * There are certain options such as &#39;site-aliases&#39; and &#39;command-specific&#39;</span></div>
<div class="line"><a name="l00217"></a><span class="lineno">  217</span>&#160;<span class="comment"> * that must be merged together if defined in multiple drush configuration</span></div>
<div class="line"><a name="l00218"></a><span class="lineno">  218</span>&#160;<span class="comment"> * files.  If we did not do this merge, then the last configuration file</span></div>
<div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;<span class="comment"> * that defined any of these properties would overwrite all of the options</span></div>
<div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;<span class="comment"> * that came before in previously-loaded configuration files.  We place</span></div>
<div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;<span class="comment"> * all of them into their own context so that this does not happen.</span></div>
<div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00223"></a><span class="lineno"><a class="code" href="context_8inc.html#a16a51c5b09d64e968c3bd7ec414b8846">  223</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#a16a51c5b09d64e968c3bd7ec414b8846">drush_set_config_special_contexts</a>(&amp;$options) {</div>
<div class="line"><a name="l00224"></a><span class="lineno">  224</span>&#160;  <span class="keywordflow">if</span> (isset($options) &amp;&amp; is_array($options)) {</div>
<div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160;    $has_command_specific = array_key_exists(<span class="stringliteral">&#39;command-specific&#39;</span>, $options);</div>
<div class="line"><a name="l00226"></a><span class="lineno">  226</span>&#160;    <span class="comment">// Change the keys of the site aliases from &#39;alias&#39; to &#39;@alias&#39;</span></div>
<div class="line"><a name="l00227"></a><span class="lineno">  227</span>&#160;    <span class="keywordflow">if</span> (array_key_exists(<span class="stringliteral">&#39;site-aliases&#39;</span>, $options)) {</div>
<div class="line"><a name="l00228"></a><span class="lineno">  228</span>&#160;      $user_aliases = $options[<span class="stringliteral">&#39;site-aliases&#39;</span>];</div>
<div class="line"><a name="l00229"></a><span class="lineno">  229</span>&#160;      $options[<span class="stringliteral">&#39;site-aliases&#39;</span>] = array();</div>
<div class="line"><a name="l00230"></a><span class="lineno">  230</span>&#160;      <span class="keywordflow">foreach</span> ($user_aliases as $alias_name =&gt; $alias_value) {</div>
<div class="line"><a name="l00231"></a><span class="lineno">  231</span>&#160;        <span class="keywordflow">if</span> (substr($alias_name,0,1) != <span class="charliteral">&#39;@&#39;</span>) {</div>
<div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160;          $alias_name = <span class="stringliteral">&quot;@$alias_name&quot;</span>;</div>
<div class="line"><a name="l00233"></a><span class="lineno">  233</span>&#160;        }</div>
<div class="line"><a name="l00234"></a><span class="lineno">  234</span>&#160;        $options[<span class="stringliteral">&#39;site-aliases&#39;</span>][$alias_name] = $alias_value;</div>
<div class="line"><a name="l00235"></a><span class="lineno">  235</span>&#160;      }</div>
<div class="line"><a name="l00236"></a><span class="lineno">  236</span>&#160;    }</div>
<div class="line"><a name="l00237"></a><span class="lineno">  237</span>&#160;    <span class="comment">// Expand -s into --simulate, etc.</span></div>
<div class="line"><a name="l00238"></a><span class="lineno">  238</span>&#160;    <a class="code" href="context_8inc.html#a2082bda0c615dc7163f69851ddd8edaf">drush_expand_short_form_options</a>($options);</div>
<div class="line"><a name="l00239"></a><span class="lineno">  239</span>&#160;</div>
<div class="line"><a name="l00240"></a><span class="lineno">  240</span>&#160;    <span class="keywordflow">foreach</span> (<a class="code" href="drush_8inc.html#acb0a26e79bcbdd1152d59a6916a35aae">drush_get_global_options</a>() as $name =&gt; $info) {</div>
<div class="line"><a name="l00241"></a><span class="lineno">  241</span>&#160;      <span class="keywordflow">if</span> (is_array($info)) {</div>
<div class="line"><a name="l00242"></a><span class="lineno">  242</span>&#160;        <span class="comment">// For any global option with the &#39;merge-pathlist&#39; or &#39;merge-associative&#39; flag, set its</span></div>
<div class="line"><a name="l00243"></a><span class="lineno">  243</span>&#160;        <span class="comment">// value in the specified context.  The option is &#39;merged&#39; because we</span></div>
<div class="line"><a name="l00244"></a><span class="lineno">  244</span>&#160;        <span class="comment">// load $options with the value from the context prior to including the</span></div>
<div class="line"><a name="l00245"></a><span class="lineno">  245</span>&#160;        <span class="comment">// configuration file.  If the configuration file sets $option[&#39;special&#39;][] = &#39;value&#39;,</span></div>
<div class="line"><a name="l00246"></a><span class="lineno">  246</span>&#160;        <span class="comment">// then the configuration will be merged.  $option[&#39;special&#39;] = array(...), on the</span></div>
<div class="line"><a name="l00247"></a><span class="lineno">  247</span>&#160;        <span class="comment">// other hand, will replace rather than merge the values together.</span></div>
<div class="line"><a name="l00248"></a><span class="lineno">  248</span>&#160;        <span class="keywordflow">if</span> ((array_key_exists($name, $options)) &amp;&amp; (array_key_exists(<span class="stringliteral">&#39;merge&#39;</span>, $info) || (array_key_exists(<span class="stringliteral">&#39;merge-pathlist&#39;</span>, $info) || array_key_exists(<span class="stringliteral">&#39;merge-associative&#39;</span>, $info)))) {</div>
<div class="line"><a name="l00249"></a><span class="lineno">  249</span>&#160;          $context = array_key_exists(<span class="stringliteral">&#39;context&#39;</span>, $info) ? $info[<span class="stringliteral">&#39;context&#39;</span>] : $name;</div>
<div class="line"><a name="l00250"></a><span class="lineno">  250</span>&#160;          $cache =&amp; <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>($context);</div>
<div class="line"><a name="l00251"></a><span class="lineno">  251</span>&#160;          $value = $options[$name];</div>
<div class="line"><a name="l00252"></a><span class="lineno">  252</span>&#160;          <span class="keywordflow">if</span> (!is_array($value) &amp;&amp; array_key_exists(<span class="stringliteral">&#39;merge-pathlist&#39;</span>, $info)) {</div>
<div class="line"><a name="l00253"></a><span class="lineno">  253</span>&#160;            $value = explode(PATH_SEPARATOR, $value);</div>
<div class="line"><a name="l00254"></a><span class="lineno">  254</span>&#160;          }</div>
<div class="line"><a name="l00255"></a><span class="lineno">  255</span>&#160;          <span class="keywordflow">if</span> (array_key_exists(<span class="stringliteral">&#39;merge-associative&#39;</span>, $info)) {</div>
<div class="line"><a name="l00256"></a><span class="lineno">  256</span>&#160;            <span class="keywordflow">foreach</span> ($value as $subkey =&gt; $subvalue) {</div>
<div class="line"><a name="l00257"></a><span class="lineno">  257</span>&#160;              $cache[$subkey] = array_merge(isset($cache[$subkey]) ? $cache[$subkey] : array(), $subvalue);</div>
<div class="line"><a name="l00258"></a><span class="lineno">  258</span>&#160;            }</div>
<div class="line"><a name="l00259"></a><span class="lineno">  259</span>&#160;          }</div>
<div class="line"><a name="l00260"></a><span class="lineno">  260</span>&#160;          <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00261"></a><span class="lineno">  261</span>&#160;            $cache = array_unique(array_merge($cache, $value));</div>
<div class="line"><a name="l00262"></a><span class="lineno">  262</span>&#160;          }</div>
<div class="line"><a name="l00263"></a><span class="lineno">  263</span>&#160;          <span class="comment">// Once we have moved the option to its special context, we</span></div>
<div class="line"><a name="l00264"></a><span class="lineno">  264</span>&#160;          <span class="comment">// can remove it from its option context -- unless &#39;propagate-cli-value&#39;</span></div>
<div class="line"><a name="l00265"></a><span class="lineno">  265</span>&#160;          <span class="comment">// is set, in which case we need to let it stick around in options</span></div>
<div class="line"><a name="l00266"></a><span class="lineno">  266</span>&#160;          <span class="comment">// in case it is needed in backend invoke.</span></div>
<div class="line"><a name="l00267"></a><span class="lineno">  267</span>&#160;          <span class="keywordflow">if</span> (!array_key_exists(<span class="stringliteral">&#39;propagate-cli-value&#39;</span>, $info)) {</div>
<div class="line"><a name="l00268"></a><span class="lineno">  268</span>&#160;            unset($options[$name]);</div>
<div class="line"><a name="l00269"></a><span class="lineno">  269</span>&#160;          }</div>
<div class="line"><a name="l00270"></a><span class="lineno">  270</span>&#160;        }</div>
<div class="line"><a name="l00271"></a><span class="lineno">  271</span>&#160;      }</div>
<div class="line"><a name="l00272"></a><span class="lineno">  272</span>&#160;    }</div>
<div class="line"><a name="l00273"></a><span class="lineno">  273</span>&#160;</div>
<div class="line"><a name="l00274"></a><span class="lineno">  274</span>&#160;    <span class="comment">// If command-specific options were set and if we already have</span></div>
<div class="line"><a name="l00275"></a><span class="lineno">  275</span>&#160;    <span class="comment">// a command, then apply the command-specific options immediately.</span></div>
<div class="line"><a name="l00276"></a><span class="lineno">  276</span>&#160;    <span class="keywordflow">if</span> ($has_command_specific) {</div>
<div class="line"><a name="l00277"></a><span class="lineno">  277</span>&#160;      <a class="code" href="includes_2command_8inc.html#ad5dd93fad069d6ba73b3546d26855071">drush_command_default_options</a>();</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;  }</div>
<div class="line"><a name="l00280"></a><span class="lineno">  280</span>&#160;}</div>
<div class="line"><a name="l00281"></a><span class="lineno">  281</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00282"></a><span class="lineno">  282</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00283"></a><span class="lineno">  283</span>&#160;<span class="comment"> * Set a specific context.</span></div>
<div class="line"><a name="l00284"></a><span class="lineno">  284</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00285"></a><span class="lineno">  285</span>&#160;<span class="comment"> * @param context</span></div>
<div class="line"><a name="l00286"></a><span class="lineno">  286</span>&#160;<span class="comment"> *   Any of the default defined contexts.</span></div>
<div class="line"><a name="l00287"></a><span class="lineno">  287</span>&#160;<span class="comment"> * @param value</span></div>
<div class="line"><a name="l00288"></a><span class="lineno">  288</span>&#160;<span class="comment"> *   The value to store in the context</span></div>
<div class="line"><a name="l00289"></a><span class="lineno">  289</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00290"></a><span class="lineno">  290</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l00291"></a><span class="lineno">  291</span>&#160;<span class="comment"> *   An associative array of the settings specified in the request context.</span></div>
<div class="line"><a name="l00292"></a><span class="lineno">  292</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00293"></a><span class="lineno"><a class="code" href="context_8inc.html#af983acfe90e7d7bbdbd67c57f93708ba">  293</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#af983acfe90e7d7bbdbd67c57f93708ba">drush_set_context</a>($context, $value) {</div>
<div class="line"><a name="l00294"></a><span class="lineno">  294</span>&#160;  $cache =&amp; <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>($context);</div>
<div class="line"><a name="l00295"></a><span class="lineno">  295</span>&#160;  $cache = $value;</div>
<div class="line"><a name="l00296"></a><span class="lineno">  296</span>&#160;  <span class="keywordflow">return</span> $value;</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="comment"></span></div>
<div class="line"><a name="l00300"></a><span class="lineno">  300</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00301"></a><span class="lineno">  301</span>&#160;<span class="comment"> * Return a specific context, or the whole context cache</span></div>
<div class="line"><a name="l00302"></a><span class="lineno">  302</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00303"></a><span class="lineno">  303</span>&#160;<span class="comment"> * This function provides a storage mechanism for any information</span></div>
<div class="line"><a name="l00304"></a><span class="lineno">  304</span>&#160;<span class="comment"> * the currently running process might need to communicate.</span></div>
<div class="line"><a name="l00305"></a><span class="lineno">  305</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00306"></a><span class="lineno">  306</span>&#160;<span class="comment"> * This avoids the use of globals, and constants.</span></div>
<div class="line"><a name="l00307"></a><span class="lineno">  307</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00308"></a><span class="lineno">  308</span>&#160;<span class="comment"> * Functions that operate on the context cache, can retrieve a reference</span></div>
<div class="line"><a name="l00309"></a><span class="lineno">  309</span>&#160;<span class="comment"> * to the context cache using :</span></div>
<div class="line"><a name="l00310"></a><span class="lineno">  310</span>&#160;<span class="comment"> *     $cache = &amp;drush_get_context($context);</span></div>
<div class="line"><a name="l00311"></a><span class="lineno">  311</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00312"></a><span class="lineno">  312</span>&#160;<span class="comment"> * This is a private function, because it is meant as an internal</span></div>
<div class="line"><a name="l00313"></a><span class="lineno">  313</span>&#160;<span class="comment"> * generalized API for writing static cache functions, not as a general</span></div>
<div class="line"><a name="l00314"></a><span class="lineno">  314</span>&#160;<span class="comment"> * purpose function to be used inside commands.</span></div>
<div class="line"><a name="l00315"></a><span class="lineno">  315</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00316"></a><span class="lineno">  316</span>&#160;<span class="comment"> * Code that modifies the reference directly might have unexpected consequences,</span></div>
<div class="line"><a name="l00317"></a><span class="lineno">  317</span>&#160;<span class="comment"> * such as modifying the arguments after they have already been parsed and dispatched</span></div>
<div class="line"><a name="l00318"></a><span class="lineno">  318</span>&#160;<span class="comment"> * to the callbacks.</span></div>
<div class="line"><a name="l00319"></a><span class="lineno">  319</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00320"></a><span class="lineno">  320</span>&#160;<span class="comment"> * @param context</span></div>
<div class="line"><a name="l00321"></a><span class="lineno">  321</span>&#160;<span class="comment"> *   Optional. Any of the default defined contexts.</span></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"> * @return</span></div>
<div class="line"><a name="l00324"></a><span class="lineno">  324</span>&#160;<span class="comment"> *   If context is not supplied, the entire context cache will be returned.</span></div>
<div class="line"><a name="l00325"></a><span class="lineno">  325</span>&#160;<span class="comment"> *   Otherwise only the requested context will be returned.</span></div>
<div class="line"><a name="l00326"></a><span class="lineno">  326</span>&#160;<span class="comment"> *   If the context does not exist yet, it will be initialized to an empty array.</span></div>
<div class="line"><a name="l00327"></a><span class="lineno">  327</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00328"></a><span class="lineno"><a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">  328</a></span>&#160;<span class="keyword">function</span> &amp;<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>($context = NULL, $default = NULL) {</div>
<div class="line"><a name="l00329"></a><span class="lineno">  329</span>&#160;  <span class="keyword">static</span> $cache = array();</div>
<div class="line"><a name="l00330"></a><span class="lineno">  330</span>&#160;  <span class="keywordflow">if</span> (isset($context)) {</div>
<div class="line"><a name="l00331"></a><span class="lineno">  331</span>&#160;    <span class="keywordflow">if</span> (!isset($cache[$context])) {</div>
<div class="line"><a name="l00332"></a><span class="lineno">  332</span>&#160;      $default = !isset($default) ? array() : $default;</div>
<div class="line"><a name="l00333"></a><span class="lineno">  333</span>&#160;      $cache[$context] = $default;</div>
<div class="line"><a name="l00334"></a><span class="lineno">  334</span>&#160;    }</div>
<div class="line"><a name="l00335"></a><span class="lineno">  335</span>&#160;    <span class="keywordflow">return</span> $cache[$context];</div>
<div class="line"><a name="l00336"></a><span class="lineno">  336</span>&#160;  }</div>
<div class="line"><a name="l00337"></a><span class="lineno">  337</span>&#160;  <span class="keywordflow">return</span> $cache;</div>
<div class="line"><a name="l00338"></a><span class="lineno">  338</span>&#160;}</div>
<div class="line"><a name="l00339"></a><span class="lineno">  339</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00340"></a><span class="lineno">  340</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00341"></a><span class="lineno">  341</span>&#160;<span class="comment"> * Set the arguments passed to the drush.php script.</span></div>
<div class="line"><a name="l00342"></a><span class="lineno">  342</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00343"></a><span class="lineno">  343</span>&#160;<span class="comment"> * This function will set the &#39;arguments&#39; context of the current running script.</span></div>
<div class="line"><a name="l00344"></a><span class="lineno">  344</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00345"></a><span class="lineno">  345</span>&#160;<span class="comment"> * When initially called by drush_parse_args, the entire list of arguments will</span></div>
<div class="line"><a name="l00346"></a><span class="lineno">  346</span>&#160;<span class="comment"> * be populated. Once the command is dispatched, this will be set to only the remaining</span></div>
<div class="line"><a name="l00347"></a><span class="lineno">  347</span>&#160;<span class="comment"> * arguments to the command (i.e. the command name is removed).</span></div>
<div class="line"><a name="l00348"></a><span class="lineno">  348</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00349"></a><span class="lineno">  349</span>&#160;<span class="comment"> * @param arguments</span></div>
<div class="line"><a name="l00350"></a><span class="lineno">  350</span>&#160;<span class="comment"> *   Command line arguments, as an array.</span></div>
<div class="line"><a name="l00351"></a><span class="lineno">  351</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00352"></a><span class="lineno"><a class="code" href="context_8inc.html#ade90fc1aa9c39a740a20c2bf1cb97c25">  352</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#ade90fc1aa9c39a740a20c2bf1cb97c25">drush_set_arguments</a>($arguments) {</div>
<div class="line"><a name="l00353"></a><span class="lineno">  353</span>&#160;  <a class="code" href="context_8inc.html#af983acfe90e7d7bbdbd67c57f93708ba">drush_set_context</a>(<span class="stringliteral">&#39;arguments&#39;</span>, $arguments);</div>
<div class="line"><a name="l00354"></a><span class="lineno">  354</span>&#160;}</div>
<div class="line"><a name="l00355"></a><span class="lineno">  355</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00356"></a><span class="lineno">  356</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00357"></a><span class="lineno">  357</span>&#160;<span class="comment"> * Gets the command line arguments passed to Drush.</span></div>
<div class="line"><a name="l00358"></a><span class="lineno">  358</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00359"></a><span class="lineno">  359</span>&#160;<span class="comment"> * @return array</span></div>
<div class="line"><a name="l00360"></a><span class="lineno">  360</span>&#160;<span class="comment"> *   An indexed array of arguments. Until Drush has dispatched the command, the</span></div>
<div class="line"><a name="l00361"></a><span class="lineno">  361</span>&#160;<span class="comment"> *   array will include the command name as the first element. After that point</span></div>
<div class="line"><a name="l00362"></a><span class="lineno">  362</span>&#160;<span class="comment"> *   the array will not include the command name.</span></div>
<div class="line"><a name="l00363"></a><span class="lineno">  363</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00364"></a><span class="lineno">  364</span>&#160;<span class="comment"> * @see drush_set_arguments()</span></div>
<div class="line"><a name="l00365"></a><span class="lineno">  365</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00366"></a><span class="lineno"><a class="code" href="context_8inc.html#afaf9361f1297f29d10402b075985985a">  366</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#afaf9361f1297f29d10402b075985985a">drush_get_arguments</a>() {</div>
<div class="line"><a name="l00367"></a><span class="lineno">  367</span>&#160;  <span class="keywordflow">return</span> <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;arguments&#39;</span>);</div>
<div class="line"><a name="l00368"></a><span class="lineno">  368</span>&#160;}</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">/**</span></div>
<div class="line"><a name="l00371"></a><span class="lineno">  371</span>&#160;<span class="comment"> * Set the command being executed.</span></div>
<div class="line"><a name="l00372"></a><span class="lineno">  372</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00373"></a><span class="lineno">  373</span>&#160;<span class="comment"> * Drush_dispatch will set the correct command based on it&#39;s</span></div>
<div class="line"><a name="l00374"></a><span class="lineno">  374</span>&#160;<span class="comment"> * matching of the script arguments retrieved from drush_get_arguments</span></div>
<div class="line"><a name="l00375"></a><span class="lineno">  375</span>&#160;<span class="comment"> * to the implemented commands specified by drush_get_commands.</span></div>
<div class="line"><a name="l00376"></a><span class="lineno">  376</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00377"></a><span class="lineno">  377</span>&#160;<span class="comment"> * @param</span></div>
<div class="line"><a name="l00378"></a><span class="lineno">  378</span>&#160;<span class="comment"> *   A numerically indexed array of command components.</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"><a class="code" href="context_8inc.html#af37b8df12a8fc3bf25b173d420a11203">  380</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#af37b8df12a8fc3bf25b173d420a11203">drush_set_command</a>($command) {</div>
<div class="line"><a name="l00381"></a><span class="lineno">  381</span>&#160;  <a class="code" href="context_8inc.html#af983acfe90e7d7bbdbd67c57f93708ba">drush_set_context</a>(<span class="stringliteral">&#39;command&#39;</span>, $command);</div>
<div class="line"><a name="l00382"></a><span class="lineno">  382</span>&#160;}</div>
<div class="line"><a name="l00383"></a><span class="lineno">  383</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00384"></a><span class="lineno">  384</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00385"></a><span class="lineno">  385</span>&#160;<span class="comment"> * Return the command being executed.</span></div>
<div class="line"><a name="l00386"></a><span class="lineno">  386</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00387"></a><span class="lineno"><a class="code" href="context_8inc.html#a8fc57227375a540fea5314b154576354">  387</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#a8fc57227375a540fea5314b154576354">drush_get_command</a>() {</div>
<div class="line"><a name="l00388"></a><span class="lineno">  388</span>&#160;  <span class="keywordflow">return</span> <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;command&#39;</span>);</div>
<div class="line"><a name="l00389"></a><span class="lineno">  389</span>&#160;}</div>
<div class="line"><a name="l00390"></a><span class="lineno">  390</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00391"></a><span class="lineno">  391</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00392"></a><span class="lineno">  392</span>&#160;<span class="comment"> * Get the value for an option.</span></div>
<div class="line"><a name="l00393"></a><span class="lineno">  393</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00394"></a><span class="lineno">  394</span>&#160;<span class="comment"> * If the first argument is an array, then it checks whether one of the options</span></div>
<div class="line"><a name="l00395"></a><span class="lineno">  395</span>&#160;<span class="comment"> * exists and return the value of the first one found. Useful for allowing both</span></div>
<div class="line"><a name="l00396"></a><span class="lineno">  396</span>&#160;<span class="comment"> * -h and --host-name</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"> * @param option</span></div>
<div class="line"><a name="l00399"></a><span class="lineno">  399</span>&#160;<span class="comment"> *   The name of the option to get</span></div>
<div class="line"><a name="l00400"></a><span class="lineno">  400</span>&#160;<span class="comment"> * @param default</span></div>
<div class="line"><a name="l00401"></a><span class="lineno">  401</span>&#160;<span class="comment"> *   Optional. The value to return if the option has not been set</span></div>
<div class="line"><a name="l00402"></a><span class="lineno">  402</span>&#160;<span class="comment"> * @param context</span></div>
<div class="line"><a name="l00403"></a><span class="lineno">  403</span>&#160;<span class="comment"> *   Optional. The context to check for the option. If this is set, only this context will be searched.</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"><a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">  405</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>($option, $default = NULL, $context = NULL) {</div>
<div class="line"><a name="l00406"></a><span class="lineno">  406</span>&#160;  $value = NULL;</div>
<div class="line"><a name="l00407"></a><span class="lineno">  407</span>&#160;</div>
<div class="line"><a name="l00408"></a><span class="lineno">  408</span>&#160;  <span class="keywordflow">if</span> ($context) {</div>
<div class="line"><a name="l00409"></a><span class="lineno">  409</span>&#160;    <span class="comment">// We have a definite context to check for the presence of an option.</span></div>
<div class="line"><a name="l00410"></a><span class="lineno">  410</span>&#160;    $value = <a class="code" href="context_8inc.html#aee5781894bf828bfa508d9052553f809">_drush_get_option</a>($option, <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>($context));</div>
<div class="line"><a name="l00411"></a><span class="lineno">  411</span>&#160;  }</div>
<div class="line"><a name="l00412"></a><span class="lineno">  412</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00413"></a><span class="lineno">  413</span>&#160;    <span class="comment">// We are not checking a specific context, so check them in a predefined order of precedence.</span></div>
<div class="line"><a name="l00414"></a><span class="lineno">  414</span>&#160;    $contexts = <a class="code" href="context_8inc.html#a9f6272c1a68141ce873c07aae3a316ac">drush_context_names</a>();</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="keywordflow">foreach</span> ($contexts as $context) {</div>
<div class="line"><a name="l00417"></a><span class="lineno">  417</span>&#160;      $value = <a class="code" href="context_8inc.html#aee5781894bf828bfa508d9052553f809">_drush_get_option</a>($option, <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>($context));</div>
<div class="line"><a name="l00418"></a><span class="lineno">  418</span>&#160;</div>
<div class="line"><a name="l00419"></a><span class="lineno">  419</span>&#160;      <span class="keywordflow">if</span> ($value !== NULL) {</div>
<div class="line"><a name="l00420"></a><span class="lineno">  420</span>&#160;        <span class="keywordflow">return</span> $value;</div>
<div class="line"><a name="l00421"></a><span class="lineno">  421</span>&#160;      }</div>
<div class="line"><a name="l00422"></a><span class="lineno">  422</span>&#160;    }</div>
<div class="line"><a name="l00423"></a><span class="lineno">  423</span>&#160;  }</div>
<div class="line"><a name="l00424"></a><span class="lineno">  424</span>&#160;</div>
<div class="line"><a name="l00425"></a><span class="lineno">  425</span>&#160;  <span class="keywordflow">if</span> ($value !== NULL) {</div>
<div class="line"><a name="l00426"></a><span class="lineno">  426</span>&#160;    <span class="keywordflow">return</span> $value;</div>
<div class="line"><a name="l00427"></a><span class="lineno">  427</span>&#160;  }</div>
<div class="line"><a name="l00428"></a><span class="lineno">  428</span>&#160;</div>
<div class="line"><a name="l00429"></a><span class="lineno">  429</span>&#160;  <span class="keywordflow">return</span> $default;</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;<span class="comment"></span></div>
<div class="line"><a name="l00432"></a><span class="lineno">  432</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00433"></a><span class="lineno">  433</span>&#160;<span class="comment"> * Get the value for an option and return it as a list.  If the</span></div>
<div class="line"><a name="l00434"></a><span class="lineno">  434</span>&#160;<span class="comment"> * option in question is passed on the command line, its value should</span></div>
<div class="line"><a name="l00435"></a><span class="lineno">  435</span>&#160;<span class="comment"> * be a comma-separated list (e.g. --flag=1,2,3).  If the option</span></div>
<div class="line"><a name="l00436"></a><span class="lineno">  436</span>&#160;<span class="comment"> * was set in a drushrc.php file, then its value may be either a</span></div>
<div class="line"><a name="l00437"></a><span class="lineno">  437</span>&#160;<span class="comment"> * comma-separated list or an array of values (e.g. $option[&#39;flag&#39;] = array(&#39;1&#39;, &#39;2&#39;, &#39;3&#39;)).</span></div>
<div class="line"><a name="l00438"></a><span class="lineno">  438</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00439"></a><span class="lineno">  439</span>&#160;<span class="comment"> * @param option</span></div>
<div class="line"><a name="l00440"></a><span class="lineno">  440</span>&#160;<span class="comment"> *   The name of the option to get</span></div>
<div class="line"><a name="l00441"></a><span class="lineno">  441</span>&#160;<span class="comment"> * @param default</span></div>
<div class="line"><a name="l00442"></a><span class="lineno">  442</span>&#160;<span class="comment"> *   Optional. The value to return if the option has not been set</span></div>
<div class="line"><a name="l00443"></a><span class="lineno">  443</span>&#160;<span class="comment"> * @param context</span></div>
<div class="line"><a name="l00444"></a><span class="lineno">  444</span>&#160;<span class="comment"> *   Optional. The context to check for the option. If this is set, only this context will be searched.</span></div>
<div class="line"><a name="l00445"></a><span class="lineno">  445</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00446"></a><span class="lineno"><a class="code" href="context_8inc.html#ade60e65f76863ed34db22f5e7f83a150">  446</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#ade60e65f76863ed34db22f5e7f83a150">drush_get_option_list</a>($option, $default = array(), $context = NULL) {</div>
<div class="line"><a name="l00447"></a><span class="lineno">  447</span>&#160;  $result = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>($option, $default, $context);</div>
<div class="line"><a name="l00448"></a><span class="lineno">  448</span>&#160;</div>
<div class="line"><a name="l00449"></a><span class="lineno">  449</span>&#160;  <span class="keywordflow">if</span> (!is_array($result)) {</div>
<div class="line"><a name="l00450"></a><span class="lineno">  450</span>&#160;    $result = array_map(<span class="stringliteral">&#39;trim&#39;</span>, array_filter(explode(<span class="charliteral">&#39;,&#39;</span>, $result)));</div>
<div class="line"><a name="l00451"></a><span class="lineno">  451</span>&#160;  }</div>
<div class="line"><a name="l00452"></a><span class="lineno">  452</span>&#160;</div>
<div class="line"><a name="l00453"></a><span class="lineno">  453</span>&#160;  <span class="keywordflow">return</span> $result;</div>
<div class="line"><a name="l00454"></a><span class="lineno">  454</span>&#160;}</div>
<div class="line"><a name="l00455"></a><span class="lineno">  455</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00456"></a><span class="lineno">  456</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00457"></a><span class="lineno">  457</span>&#160;<span class="comment"> * Get the value for an option, but first checks the provided option overrides.</span></div>
<div class="line"><a name="l00458"></a><span class="lineno">  458</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00459"></a><span class="lineno">  459</span>&#160;<span class="comment"> * The feature of drush_get_option that allows a list of option names</span></div>
<div class="line"><a name="l00460"></a><span class="lineno">  460</span>&#160;<span class="comment"> * to be passed in an array is NOT supported.</span></div>
<div class="line"><a name="l00461"></a><span class="lineno">  461</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00462"></a><span class="lineno">  462</span>&#160;<span class="comment"> * @param option_overrides</span></div>
<div class="line"><a name="l00463"></a><span class="lineno">  463</span>&#160;<span class="comment"> *   An array to check for values before calling drush_get_option.</span></div>
<div class="line"><a name="l00464"></a><span class="lineno">  464</span>&#160;<span class="comment"> * @param option</span></div>
<div class="line"><a name="l00465"></a><span class="lineno">  465</span>&#160;<span class="comment"> *   The name of the option to get.</span></div>
<div class="line"><a name="l00466"></a><span class="lineno">  466</span>&#160;<span class="comment"> * @param default</span></div>
<div class="line"><a name="l00467"></a><span class="lineno">  467</span>&#160;<span class="comment"> *   Optional. The value to return if the option has not been set.</span></div>
<div class="line"><a name="l00468"></a><span class="lineno">  468</span>&#160;<span class="comment"> * @param context</span></div>
<div class="line"><a name="l00469"></a><span class="lineno">  469</span>&#160;<span class="comment"> *   Optional. The context to check for the option. If this is set, only this context will be searched.</span></div>
<div class="line"><a name="l00470"></a><span class="lineno">  470</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00471"></a><span class="lineno">  471</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00472"></a><span class="lineno"><a class="code" href="context_8inc.html#a559008f6decb23108b83e704208e415e">  472</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#a559008f6decb23108b83e704208e415e">drush_get_option_override</a>($option_overrides, $option, $default = NULL, $context = NULL) {</div>
<div class="line"><a name="l00473"></a><span class="lineno">  473</span>&#160;  <span class="keywordflow">return</span> <a class="code" href="context_8inc.html#add3af7aa09b1ccf49718577a8d7aa61d">drush_sitealias_get_option</a>($option_overrides, $option, $default, <span class="stringliteral">&#39;&#39;</span>, $context);</div>
<div class="line"><a name="l00474"></a><span class="lineno">  474</span>&#160;}</div>
<div class="line"><a name="l00475"></a><span class="lineno">  475</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00476"></a><span class="lineno">  476</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00477"></a><span class="lineno">  477</span>&#160;<span class="comment"> * Get an option out of the specified alias.  If it has not been</span></div>
<div class="line"><a name="l00478"></a><span class="lineno">  478</span>&#160;<span class="comment"> * set in the alias, then get it via drush_get_option.</span></div>
<div class="line"><a name="l00479"></a><span class="lineno">  479</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00480"></a><span class="lineno">  480</span>&#160;<span class="comment"> * @param site_alias_record</span></div>
<div class="line"><a name="l00481"></a><span class="lineno">  481</span>&#160;<span class="comment"> *   An array of options for an alias record.</span></div>
<div class="line"><a name="l00482"></a><span class="lineno">  482</span>&#160;<span class="comment"> * @param option</span></div>
<div class="line"><a name="l00483"></a><span class="lineno">  483</span>&#160;<span class="comment"> *   The name of the option to get.</span></div>
<div class="line"><a name="l00484"></a><span class="lineno">  484</span>&#160;<span class="comment"> * @param default</span></div>
<div class="line"><a name="l00485"></a><span class="lineno">  485</span>&#160;<span class="comment"> *   Optional. The value to return if the option does not exist in the site record and has not been set in a context.</span></div>
<div class="line"><a name="l00486"></a><span class="lineno">  486</span>&#160;<span class="comment"> * @param context</span></div>
<div class="line"><a name="l00487"></a><span class="lineno">  487</span>&#160;<span class="comment"> *   Optional. The context to check for the option. If this is set, only this context will be searched.</span></div>
<div class="line"><a name="l00488"></a><span class="lineno">  488</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00489"></a><span class="lineno"><a class="code" href="context_8inc.html#add3af7aa09b1ccf49718577a8d7aa61d">  489</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#add3af7aa09b1ccf49718577a8d7aa61d">drush_sitealias_get_option</a>($site_alias_record, $option, $default = NULL, $prefix = <span class="stringliteral">&#39;&#39;</span>, $context = NULL) {</div>
<div class="line"><a name="l00490"></a><span class="lineno">  490</span>&#160;  <span class="keywordflow">if</span> (is_array($site_alias_record) &amp;&amp; array_key_exists($option, $site_alias_record)) {</div>
<div class="line"><a name="l00491"></a><span class="lineno">  491</span>&#160;    <span class="keywordflow">return</span> $site_alias_record[$option];</div>
<div class="line"><a name="l00492"></a><span class="lineno">  492</span>&#160;  }</div>
<div class="line"><a name="l00493"></a><span class="lineno">  493</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00494"></a><span class="lineno">  494</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>($prefix . $option, $default, $context);</div>
<div class="line"><a name="l00495"></a><span class="lineno">  495</span>&#160;  }</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="comment"></span></div>
<div class="line"><a name="l00498"></a><span class="lineno">  498</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00499"></a><span class="lineno">  499</span>&#160;<span class="comment"> * Get all of the values for an option in every context.</span></div>
<div class="line"><a name="l00500"></a><span class="lineno">  500</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00501"></a><span class="lineno">  501</span>&#160;<span class="comment"> * @param option</span></div>
<div class="line"><a name="l00502"></a><span class="lineno">  502</span>&#160;<span class="comment"> *   The name of the option to get</span></div>
<div class="line"><a name="l00503"></a><span class="lineno">  503</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l00504"></a><span class="lineno">  504</span>&#160;<span class="comment"> *   An array whose key is the context name and value is</span></div>
<div class="line"><a name="l00505"></a><span class="lineno">  505</span>&#160;<span class="comment"> *   the specific value for the option in that context.</span></div>
<div class="line"><a name="l00506"></a><span class="lineno">  506</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00507"></a><span class="lineno"><a class="code" href="context_8inc.html#ae7691e4635dc346aae09eb3f0bbd6092">  507</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#ae7691e4635dc346aae09eb3f0bbd6092">drush_get_context_options</a>($option, $flatten = FALSE) {</div>
<div class="line"><a name="l00508"></a><span class="lineno">  508</span>&#160;  $result = array();</div>
<div class="line"><a name="l00509"></a><span class="lineno">  509</span>&#160;</div>
<div class="line"><a name="l00510"></a><span class="lineno">  510</span>&#160;  $contexts = <a class="code" href="context_8inc.html#a9f6272c1a68141ce873c07aae3a316ac">drush_context_names</a>();</div>
<div class="line"><a name="l00511"></a><span class="lineno">  511</span>&#160;  <span class="keywordflow">foreach</span> ($contexts as $context) {</div>
<div class="line"><a name="l00512"></a><span class="lineno">  512</span>&#160;    $value = <a class="code" href="context_8inc.html#aee5781894bf828bfa508d9052553f809">_drush_get_option</a>($option, <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>($context));</div>
<div class="line"><a name="l00513"></a><span class="lineno">  513</span>&#160;</div>
<div class="line"><a name="l00514"></a><span class="lineno">  514</span>&#160;    <span class="keywordflow">if</span> ($value !== NULL) {</div>
<div class="line"><a name="l00515"></a><span class="lineno">  515</span>&#160;      <span class="keywordflow">if</span> ($flatten &amp;&amp; is_array($value)) {</div>
<div class="line"><a name="l00516"></a><span class="lineno">  516</span>&#160;        $result = array_merge($value, $result);</div>
<div class="line"><a name="l00517"></a><span class="lineno">  517</span>&#160;      }</div>
<div class="line"><a name="l00518"></a><span class="lineno">  518</span>&#160;      <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00519"></a><span class="lineno">  519</span>&#160;        $result[$context] = $value;</div>
<div class="line"><a name="l00520"></a><span class="lineno">  520</span>&#160;      }</div>
<div class="line"><a name="l00521"></a><span class="lineno">  521</span>&#160;    }</div>
<div class="line"><a name="l00522"></a><span class="lineno">  522</span>&#160;  }</div>
<div class="line"><a name="l00523"></a><span class="lineno">  523</span>&#160;</div>
<div class="line"><a name="l00524"></a><span class="lineno">  524</span>&#160;  <span class="keywordflow">return</span> $result;</div>
<div class="line"><a name="l00525"></a><span class="lineno">  525</span>&#160;}</div>
<div class="line"><a name="l00526"></a><span class="lineno">  526</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00527"></a><span class="lineno">  527</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00528"></a><span class="lineno">  528</span>&#160;<span class="comment"> * Retrieves a collapsed list of all options.</span></div>
<div class="line"><a name="l00529"></a><span class="lineno">  529</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00530"></a><span class="lineno"><a class="code" href="context_8inc.html#a72dfb89d6a4ba0bb143e3256f997d2b8">  530</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#a72dfb89d6a4ba0bb143e3256f997d2b8">drush_get_merged_options</a>() {</div>
<div class="line"><a name="l00531"></a><span class="lineno">  531</span>&#160;  $contexts = <a class="code" href="context_8inc.html#a9f6272c1a68141ce873c07aae3a316ac">drush_context_names</a>();</div>
<div class="line"><a name="l00532"></a><span class="lineno">  532</span>&#160;  $cache = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>();</div>
<div class="line"><a name="l00533"></a><span class="lineno">  533</span>&#160;  $result = array();</div>
<div class="line"><a name="l00534"></a><span class="lineno">  534</span>&#160;  <span class="keywordflow">foreach</span> (array_reverse($contexts) as $context) {</div>
<div class="line"><a name="l00535"></a><span class="lineno">  535</span>&#160;    <span class="keywordflow">if</span> (array_key_exists($context, $cache)) {</div>
<div class="line"><a name="l00536"></a><span class="lineno">  536</span>&#160;      $result = array_merge($result, $cache[$context]);</div>
<div class="line"><a name="l00537"></a><span class="lineno">  537</span>&#160;    }</div>
<div class="line"><a name="l00538"></a><span class="lineno">  538</span>&#160;  }</div>
<div class="line"><a name="l00539"></a><span class="lineno">  539</span>&#160;</div>
<div class="line"><a name="l00540"></a><span class="lineno">  540</span>&#160;  <span class="keywordflow">return</span> $result;</div>
<div class="line"><a name="l00541"></a><span class="lineno">  541</span>&#160;}</div>
<div class="line"><a name="l00542"></a><span class="lineno">  542</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00543"></a><span class="lineno">  543</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00544"></a><span class="lineno">  544</span>&#160;<span class="comment"> * Retrieves a collapsed list of all options</span></div>
<div class="line"><a name="l00545"></a><span class="lineno">  545</span>&#160;<span class="comment"> * with a specified prefix.</span></div>
<div class="line"><a name="l00546"></a><span class="lineno">  546</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00547"></a><span class="lineno"><a class="code" href="context_8inc.html#ae6fa58943e3805a7da54f0bf63ea178e">  547</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#ae6fa58943e3805a7da54f0bf63ea178e">drush_get_merged_prefixed_options</a>($prefix) {</div>
<div class="line"><a name="l00548"></a><span class="lineno">  548</span>&#160;  $merged_options = <a class="code" href="context_8inc.html#a72dfb89d6a4ba0bb143e3256f997d2b8">drush_get_merged_options</a>();</div>
<div class="line"><a name="l00549"></a><span class="lineno">  549</span>&#160;  $result = array();</div>
<div class="line"><a name="l00550"></a><span class="lineno">  550</span>&#160;  <span class="keywordflow">foreach</span> ($merged_options as $key =&gt; $value) {</div>
<div class="line"><a name="l00551"></a><span class="lineno">  551</span>&#160;    <span class="keywordflow">if</span> ($prefix == substr($key, 0, strlen($prefix))) {</div>
<div class="line"><a name="l00552"></a><span class="lineno">  552</span>&#160;      $result[substr($key, strlen($prefix))] = $value;</div>
<div class="line"><a name="l00553"></a><span class="lineno">  553</span>&#160;    }</div>
<div class="line"><a name="l00554"></a><span class="lineno">  554</span>&#160;  }</div>
<div class="line"><a name="l00555"></a><span class="lineno">  555</span>&#160;</div>
<div class="line"><a name="l00556"></a><span class="lineno">  556</span>&#160;  <span class="keywordflow">return</span> $result;</div>
<div class="line"><a name="l00557"></a><span class="lineno">  557</span>&#160;}</div>
<div class="line"><a name="l00558"></a><span class="lineno">  558</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00559"></a><span class="lineno">  559</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00560"></a><span class="lineno">  560</span>&#160;<span class="comment"> * Helper function to recurse through possible option names</span></div>
<div class="line"><a name="l00561"></a><span class="lineno">  561</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00562"></a><span class="lineno"><a class="code" href="context_8inc.html#aee5781894bf828bfa508d9052553f809">  562</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#aee5781894bf828bfa508d9052553f809">_drush_get_option</a>($option, $context) {</div>
<div class="line"><a name="l00563"></a><span class="lineno">  563</span>&#160;  <span class="keywordflow">if</span> (is_array($option)) {</div>
<div class="line"><a name="l00564"></a><span class="lineno">  564</span>&#160;    <span class="keywordflow">foreach</span> ($option as $current) {</div>
<div class="line"><a name="l00565"></a><span class="lineno">  565</span>&#160;      <span class="keywordflow">if</span> (array_key_exists($current, $context)) {</div>
<div class="line"><a name="l00566"></a><span class="lineno">  566</span>&#160;        <span class="keywordflow">return</span> $context[$current];</div>
<div class="line"><a name="l00567"></a><span class="lineno">  567</span>&#160;      }</div>
<div class="line"><a name="l00568"></a><span class="lineno">  568</span>&#160;    }</div>
<div class="line"><a name="l00569"></a><span class="lineno">  569</span>&#160;  }</div>
<div class="line"><a name="l00570"></a><span class="lineno">  570</span>&#160;  elseif (array_key_exists($option, $context)) {</div>
<div class="line"><a name="l00571"></a><span class="lineno">  571</span>&#160;    <span class="keywordflow">return</span> $context[$option];</div>
<div class="line"><a name="l00572"></a><span class="lineno">  572</span>&#160;  }</div>
<div class="line"><a name="l00573"></a><span class="lineno">  573</span>&#160;</div>
<div class="line"><a name="l00574"></a><span class="lineno">  574</span>&#160;  <span class="keywordflow">return</span> NULL;</div>
<div class="line"><a name="l00575"></a><span class="lineno">  575</span>&#160;}</div>
<div class="line"><a name="l00576"></a><span class="lineno">  576</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00577"></a><span class="lineno">  577</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00578"></a><span class="lineno">  578</span>&#160;<span class="comment"> * Set an option in one of the option contexts.</span></div>
<div class="line"><a name="l00579"></a><span class="lineno">  579</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00580"></a><span class="lineno">  580</span>&#160;<span class="comment"> * @param option</span></div>
<div class="line"><a name="l00581"></a><span class="lineno">  581</span>&#160;<span class="comment"> *   The option to set.</span></div>
<div class="line"><a name="l00582"></a><span class="lineno">  582</span>&#160;<span class="comment"> * @param value</span></div>
<div class="line"><a name="l00583"></a><span class="lineno">  583</span>&#160;<span class="comment"> *   The value to set it to.</span></div>
<div class="line"><a name="l00584"></a><span class="lineno">  584</span>&#160;<span class="comment"> * @param context</span></div>
<div class="line"><a name="l00585"></a><span class="lineno">  585</span>&#160;<span class="comment"> *   Optional. Which context to set it in.</span></div>
<div class="line"><a name="l00586"></a><span class="lineno">  586</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l00587"></a><span class="lineno">  587</span>&#160;<span class="comment"> *   The value parameter. This allows for neater code such as</span></div>
<div class="line"><a name="l00588"></a><span class="lineno">  588</span>&#160;<span class="comment"> *     $myvalue = drush_set_option(&#39;http_host&#39;, $_SERVER[&#39;HTTP_HOST&#39;]);</span></div>
<div class="line"><a name="l00589"></a><span class="lineno">  589</span>&#160;<span class="comment"> *   Without having to constantly type out the value parameter.</span></div>
<div class="line"><a name="l00590"></a><span class="lineno">  590</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00591"></a><span class="lineno"><a class="code" href="context_8inc.html#aa4b55e2f6174c8b6efaa8f23a0f9e0af">  591</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#aa4b55e2f6174c8b6efaa8f23a0f9e0af">drush_set_option</a>($option, $value, $context = <span class="stringliteral">&#39;process&#39;</span>) {</div>
<div class="line"><a name="l00592"></a><span class="lineno">  592</span>&#160;  $cache =&amp; <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>($context);</div>
<div class="line"><a name="l00593"></a><span class="lineno">  593</span>&#160;  $cache[$option] = $value;</div>
<div class="line"><a name="l00594"></a><span class="lineno">  594</span>&#160;  <span class="keywordflow">return</span> $value;</div>
<div class="line"><a name="l00595"></a><span class="lineno">  595</span>&#160;}</div>
<div class="line"><a name="l00596"></a><span class="lineno">  596</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00597"></a><span class="lineno">  597</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00598"></a><span class="lineno">  598</span>&#160;<span class="comment"> * A small helper function to set the value in the default context</span></div>
<div class="line"><a name="l00599"></a><span class="lineno">  599</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00600"></a><span class="lineno"><a class="code" href="context_8inc.html#ad552fe78011c544abadf05b2dfbe4e7f">  600</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#ad552fe78011c544abadf05b2dfbe4e7f">drush_set_default</a>($option, $value) {</div>
<div class="line"><a name="l00601"></a><span class="lineno">  601</span>&#160;  <span class="keywordflow">return</span> <a class="code" href="context_8inc.html#aa4b55e2f6174c8b6efaa8f23a0f9e0af">drush_set_option</a>($option, $value, <span class="stringliteral">&#39;default&#39;</span>);</div>
<div class="line"><a name="l00602"></a><span class="lineno">  602</span>&#160;}</div>
<div class="line"><a name="l00603"></a><span class="lineno">  603</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00604"></a><span class="lineno">  604</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00605"></a><span class="lineno">  605</span>&#160;<span class="comment"> * Remove a setting from a specific context.</span></div>
<div class="line"><a name="l00606"></a><span class="lineno">  606</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00607"></a><span class="lineno">  607</span>&#160;<span class="comment"> * @param</span></div>
<div class="line"><a name="l00608"></a><span class="lineno">  608</span>&#160;<span class="comment"> *   Option to be unset</span></div>
<div class="line"><a name="l00609"></a><span class="lineno">  609</span>&#160;<span class="comment"> * @param</span></div>
<div class="line"><a name="l00610"></a><span class="lineno">  610</span>&#160;<span class="comment"> *   Context in which to unset the value in.</span></div>
<div class="line"><a name="l00611"></a><span class="lineno">  611</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00612"></a><span class="lineno"><a class="code" href="context_8inc.html#a2d9c3fdcab304aaf56293d3881e98a9a">  612</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#a2d9c3fdcab304aaf56293d3881e98a9a">drush_unset_option</a>($option, $context = NULL) {</div>
<div class="line"><a name="l00613"></a><span class="lineno">  613</span>&#160;  <span class="keywordflow">if</span> ($context != NULL) {</div>
<div class="line"><a name="l00614"></a><span class="lineno">  614</span>&#160;    $cache =&amp; <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>($context);</div>
<div class="line"><a name="l00615"></a><span class="lineno">  615</span>&#160;    <span class="keywordflow">if</span> (array_key_exists($option, $cache)) {</div>
<div class="line"><a name="l00616"></a><span class="lineno">  616</span>&#160;      unset($cache[$option]);</div>
<div class="line"><a name="l00617"></a><span class="lineno">  617</span>&#160;    }</div>
<div class="line"><a name="l00618"></a><span class="lineno">  618</span>&#160;  }</div>
<div class="line"><a name="l00619"></a><span class="lineno">  619</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00620"></a><span class="lineno">  620</span>&#160;    $contexts = <a class="code" href="context_8inc.html#a9f6272c1a68141ce873c07aae3a316ac">drush_context_names</a>();</div>
<div class="line"><a name="l00621"></a><span class="lineno">  621</span>&#160;</div>
<div class="line"><a name="l00622"></a><span class="lineno">  622</span>&#160;    <span class="keywordflow">foreach</span> ($contexts as $context) {</div>
<div class="line"><a name="l00623"></a><span class="lineno">  623</span>&#160;      <a class="code" href="context_8inc.html#a2d9c3fdcab304aaf56293d3881e98a9a">drush_unset_option</a>($option, $context);</div>
<div class="line"><a name="l00624"></a><span class="lineno">  624</span>&#160;    }</div>
<div class="line"><a name="l00625"></a><span class="lineno">  625</span>&#160;  }</div>
<div class="line"><a name="l00626"></a><span class="lineno">  626</span>&#160;}</div>
<div class="line"><a name="l00627"></a><span class="lineno">  627</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00628"></a><span class="lineno">  628</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00629"></a><span class="lineno">  629</span>&#160;<span class="comment"> * Save the settings in a specific context to the applicable configuration file</span></div>
<div class="line"><a name="l00630"></a><span class="lineno">  630</span>&#160;<span class="comment"> * This is useful is you want certain settings to be available automatically the next time a command is executed.</span></div>
<div class="line"><a name="l00631"></a><span class="lineno">  631</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00632"></a><span class="lineno">  632</span>&#160;<span class="comment"> * @param $context</span></div>
<div class="line"><a name="l00633"></a><span class="lineno">  633</span>&#160;<span class="comment"> *   The context to save</span></div>
<div class="line"><a name="l00634"></a><span class="lineno">  634</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00635"></a><span class="lineno"><a class="code" href="context_8inc.html#aa29a91479997d413029f14ac5fbd7e94">  635</a></span>&#160;<span class="keyword">function</span> <a class="code" href="context_8inc.html#aa29a91479997d413029f14ac5fbd7e94">drush_save_config</a>($context) {</div>
<div class="line"><a name="l00636"></a><span class="lineno">  636</span>&#160;  $filename = <a class="code" href="context_8inc.html#a4eb577b3ff1b1c25213a74cb5813b42f">_drush_config_file</a>($context);</div>
<div class="line"><a name="l00637"></a><span class="lineno">  637</span>&#160;  <span class="keywordflow">if</span> (is_array($filename)) {</div>
<div class="line"><a name="l00638"></a><span class="lineno">  638</span>&#160;    $filename = $filename[0];</div>
<div class="line"><a name="l00639"></a><span class="lineno">  639</span>&#160;  }</div>
<div class="line"><a name="l00640"></a><span class="lineno">  640</span>&#160;</div>
<div class="line"><a name="l00641"></a><span class="lineno">  641</span>&#160;  <span class="keywordflow">if</span> ($filename) {</div>
<div class="line"><a name="l00642"></a><span class="lineno">  642</span>&#160;    $cache = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>($context);</div>
<div class="line"><a name="l00643"></a><span class="lineno">  643</span>&#160;</div>
<div class="line"><a name="l00644"></a><span class="lineno">  644</span>&#160;    $fp = fopen($filename, <span class="stringliteral">&quot;w+&quot;</span>);</div>
<div class="line"><a name="l00645"></a><span class="lineno">  645</span>&#160;    <span class="keywordflow">if</span> (!$fp) {</div>
<div class="line"><a name="l00646"></a><span class="lineno">  646</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_PERM_ERROR&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Drushrc (!filename) could not be written&#39;</span>, array(<span class="stringliteral">&#39;!filename&#39;</span> =&gt; $filename)));</div>
<div class="line"><a name="l00647"></a><span class="lineno">  647</span>&#160;    }</div>
<div class="line"><a name="l00648"></a><span class="lineno">  648</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00649"></a><span class="lineno">  649</span>&#160;      fwrite($fp, <span class="stringliteral">&quot;&lt;?php\n&quot;</span>);</div>
<div class="line"><a name="l00650"></a><span class="lineno">  650</span>&#160;      <span class="keywordflow">foreach</span> ($cache as $key =&gt; $value) {</div>
<div class="line"><a name="l00651"></a><span class="lineno">  651</span>&#160;        $line = <span class="stringliteral">&quot;\n\$options[&#39;$key&#39;] = &quot;</span>. var_export($value, TRUE) .<span class="charliteral">&#39;;&#39;</span>;</div>
<div class="line"><a name="l00652"></a><span class="lineno">  652</span>&#160;        fwrite($fp, $line);</div>
<div class="line"><a name="l00653"></a><span class="lineno">  653</span>&#160;      }</div>
<div class="line"><a name="l00654"></a><span class="lineno">  654</span>&#160;      fwrite($fp, <span class="stringliteral">&quot;\n&quot;</span>);</div>
<div class="line"><a name="l00655"></a><span class="lineno">  655</span>&#160;      fclose($fp);</div>
<div class="line"><a name="l00656"></a><span class="lineno">  656</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">&#39;Drushrc file (!filename) was written successfully&#39;</span>, array(<span class="stringliteral">&#39;!filename&#39;</span> =&gt; $filename)));</div>
<div class="line"><a name="l00657"></a><span class="lineno">  657</span>&#160;      <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l00658"></a><span class="lineno">  658</span>&#160;    }</div>
<div class="line"><a name="l00659"></a><span class="lineno">  659</span>&#160;</div>
<div class="line"><a name="l00660"></a><span class="lineno">  660</span>&#160;  }</div>
<div class="line"><a name="l00661"></a><span class="lineno">  661</span>&#160;  <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l00662"></a><span class="lineno">  662</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>