You are here

public function Vars::offsetGet in Variable API 7.2

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

Implements ArrayAccess::offsetGet().

3 calls to Vars::offsetGet()
Vars::forceMenuRebuild in ./vars.classes.inc
Forces the menu rebuilding.
Vars::offsetExists in ./vars.classes.inc
Implements ArrayAccess::offsetExists().
Vars::siteIsOffline in ./vars.classes.inc
Checks if the site is offline.

File

./vars.classes.inc, line 268
Classes implemented by the Variable API module.

Class

Vars
@file Classes implemented by the Variable API module.

Code

public function offsetGet($offset) {
  global $conf;
  if (isset($conf[$offset])) {
    return $conf[$offset];
  }
  $value = $this
    ->defaultValue($offset);
  if (isset($value)) {
    return $value;
  }
  $defaults =& $this
    ->staticValue('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 (:offset LIKE CONCAT(name, '\\_%')) AND flags > 0)", 0, 1, array(
    ':name' => $offset,
    ':offset' => $offset,
  ))
    ->fetchField();
  if (!$module) {
    return NULL;
  }
  $vars = self::loadDefaults("module:{$module}", db_and()
    ->condition('vd.module', $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;
        }
      }
    }
  }
}