You are here

function background_process_static in Background Process 6

Backport of Drupal 7 drupal_static().

4 calls to background_process_static()
background_process_ass_get_server_status in background_process_ass/background_process_ass.module
Get apache extended server status.
background_process_ass_service_group_idle in background_process_ass/background_process_ass.module
Determine host with most idle workers and claim it.
_background_process_cleanup_locks in ./background_process.module
Shutdown handler for removing locks
_background_process_ensure_cleanup in ./background_process.module
Ensure lock is removed at end of request

File

./background_process.module, line 1501

Code

function &background_process_static($name, $default_value = NULL, $reset = FALSE) {
  static $data = array(), $default = array();

  // First check if dealing with a previously defined static variable.
  if (isset($data[$name]) || array_key_exists($name, $data)) {

    // Non-NULL $name and both $data[$name] and $default[$name] statics exist.
    if ($reset) {

      // Reset pre-existing static variable to its default value.
      $data[$name] = $default[$name];
    }
    return $data[$name];
  }

  // Neither $data[$name] nor $default[$name] static variables exist.
  if (isset($name)) {
    if ($reset) {

      // Reset was called before a default is set and yet a variable must be
      // returned.
      return $data;
    }

    // First call with new non-NULL $name. Initialize a new static variable.
    $default[$name] = $data[$name] = $default_value;
    return $data[$name];
  }

  // Reset all: ($name == NULL). This needs to be done one at a time so that
  // references returned by earlier invocations of drupal_static() also get
  // reset.
  foreach ($default as $name => $value) {
    $data[$name] = $value;
  }

  // As the function returns a reference, the return should always be a
  // variable.
  return $data;
}