function drush_get_context
| 6.x context.inc | &drush_get_context($context = NULL, $default = NULL) |
| 5.x context.inc | &drush_get_context($context = NULL, $default = NULL) |
| 3.x context.inc | &drush_get_context($context = null, $default = null) |
| 4.x context.inc | &drush_get_context($context = NULL, $default = NULL) |
Return a specific context, or the whole context cache
This function provides a storage mechanism for any information the currently running process might need to communicate.
This avoids the use of globals, and constants.
Functions that operate on the context cache, can retrieve a reference to the context cache using : $cache = &drush_get_context($context);
This is a private function, because it is meant as an internal generalized API for writing static cache functions, not as a general purpose function to be used inside commands.
Code that modifies the reference directly might have unexpected consequences, such as modifying the arguments after they have already been parsed and dispatched to the callbacks.
Parameters
context: Optional. Any of the default defined contexts.
Return value
If context is not supplied, the entire context cache will be returned. Otherwise only the requested context will be returned. If the context does not exist yet, it will be initialized to an empty array.
- docs_drush_command in commands/
core/ docs.drush.inc - Implementation of hook_drush_command().
- drush_archive_dump in commands/
core/ archive.drush.inc - Command callback. Generate site archive file.
- drush_backend_get_result in includes/
backend.inc - Retrieves the results from the last call to backend_invoke.
- drush_backend_output in includes/
backend.inc - Print the json-encoded output of this command, including the encoded log records, context information, etc.
- drush_backend_packet in includes/
backend.inc - Output a backend packet if we're running as backend.
File
- includes/
context.inc, line 324 - The Drush context API implementation.
Code
function &drush_get_context($context = NULL, $default = NULL) {
static $cache = array();
if (!is_null($context)) {
if (!isset($cache[$context])) {
$default = is_null($default) ? array() : $default;
$cache[$context] = $default;
}
return $cache[$context];
}
return $cache;
}