You are here

public function Vars::offsetGet in Variable API 7

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

Implements ArrayAccess::offsetGet().

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

File

./vars.module, line 153
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 =& drupal_static('vars_default_values', array());
  if (isset($defaults['static'][$offset])) {
    return $defaults['static'][$offset];
  }
  if (!empty($defaults['dynamic'])) {
    foreach ($defaults['dynamic'] as $var => $value) {
      if (strpos($offset, $var . '_') === 0) {
        $defaults['static'][$offset] = $value;
        return $value;
      }
    }
  }
  $module = db_query_range("SELECT module FROM {variable_default} WHERE name = :name OR (:name LIKE CONCAT(name, '\\_%') AND flags > 0)", 0, 1, array(
    ':name' => $offset,
  ))
    ->fetchField();
  if (!$module) {
    return NULL;
  }
  $vars = self::loadDefaults('module:' . $this->module, db_and()
    ->condition('vd.module', $this->module));
  if (!empty($vars)) {
    $defaults['static'] = array_merge(empty($defaults['static']) ? array() : $defaults['static'], empty($vars['static']) ? array() : $vars['static']);
    $defaults['dynamic'] = array_merge(empty($defaults['dynamic']) ? array() : $defaults['dynamic'], empty($vars['dynamic']) ? array() : $vars['dynamic']);
    if (isset($defaults['static'][$offset])) {
      return $defaults['static'][$offset];
    }
    if (!empty($defaults['dynamic'])) {
      foreach ($defaults['dynamic'] as $var => $value) {
        if (strpos($offset, $var) === 0) {
          $defaults['static'][$offset] = $value;
          return $value;
        }
      }
    }
  }
}