function drush_get_context

8.0.x &drush_get_context($context = NULL, $default = NULL)
6.x &drush_get_context($context = NULL, $default = NULL)
7.x &drush_get_context($context = NULL, $default = NULL)
3.x &drush_get_context($context = null, $default = null)
4.x &drush_get_context($context = NULL, $default = NULL)
5.x &drush_get_context($context = NULL, $default = NULL)
master &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.


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.

206 calls to drush_get_context()
BaseBoot::bootstrap_and_dispatch in lib/Drush/Boot/BaseBoot.php
Main entrypoint to bootstrap the selected CMS and execute the selected command.
BaseBoot::report_command_error in lib/Drush/Boot/BaseBoot.php
Called by Drush if a command is not found, or if the command was found, but did not meet requirements.
cli_drush_command in commands/core/
Implements hook_drush_command().
docs_drush_command in commands/core/
Implementation of hook_drush_command().
DrupalBoot6::bootstrap_drupal_full in lib/Drush/Boot/DrupalBoot6.php
Attempt to load the full Drupal system.

... See full list


includes/, line 331
The Drush context API implementation.


function &drush_get_context($context = NULL, $default = NULL) {
  static $cache = array();
  if (isset($context)) {
    if (!isset($cache[$context])) {
      $default = !isset($default) ? array() : $default;
      $cache[$context] = $default;
    return $cache[$context];
  return $cache;