You are here

public function Vars::offsetGet in Variable API 6

Same name and namespace in other branches
  1. 6.2 vars.module \Vars::offsetGet()
  2. 7.2 vars.classes.inc \Vars::offsetGet()
  3. 7 vars.module \Vars::offsetGet()

Implements ArrayAccess::offsetGet().

1 call to Vars::offsetGet()
Vars::offsetExists in ./vars.module
Implements ArrayAccess::offsetExists().

File

./vars.module, line 154
Implement an API to handle persistent variables.

Class

Vars
@file Implement an API to handle persistent variables.

Code

public function offsetGet($offset) {
  global $conf;
  if (isset($conf[$offset])) {
    return $conf[$offset];
  }
  $value = $this
    ->defaultValue($offset);
  if (isset($value)) {
    return $value;
  }
  $defaults =& self::staticValue('vars_default_values', array());
  if (isset($defaults['static'][$offset])) {
    return $defaults['static'][$offset];
  }
  if (isset($defaults['dynamic'])) {
    foreach ($defaults['dynamic'] as $var => $value) {
      if (strpos($offset, $var . '_') === 0) {
        $defaults['static'][$offset] = $value;
        return $value;
      }
    }
  }
  $module = db_result(db_query_range("SELECT module FROM {variable_default} WHERE name = '%s' OR ('%s' LIKE CONCAT(name, '\\_%') AND flags > 0)", $offset, $offset, 0, 1));
  if (!$module) {
    return NULL;
  }
  $vars = self::loadDefaults('module:' . $module, "module = '%s'", $module);
  if (!empty($vars)) {
    $defaults['static'] = array_merge(isset($defaults['static']) ? $defaults['static'] : array(), isset($vars['static']) ? $vars['static'] : array());
    $defaults['dynamic'] = array_merge(isset($defaults['dynamic']) ? $defaults['dynamic'] : array(), isset($vars['dynamic']) ? $vars['dynamic'] : array());
    if (isset($defaults['static'][$offset])) {
      return $defaults['static'][$offset];
    }
    if (isset($defaults['dynamic'])) {
      foreach ($defaults['dynamic'] as $var => $value) {
        if (strpos($offset, $var) === 0) {
          $defaults['static'][$offset] = $value;
          return $value;
        }
      }
    }
  }
}