You are here

class VariableRealmDefaultController in Variable 7

Same name and namespace in other branches
  1. 7.2 variable_realm/variable_realm.class.inc \VariableRealmDefaultController

Base class, keeps static list of variables.

Hierarchy

Expanded class hierarchy of VariableRealmDefaultController

1 string reference to 'VariableRealmDefaultController'
_variable_realm_controller in variable_realm/variable_realm.module
Create realm controller object.

File

variable_realm/variable_realm.class.inc, line 72
Variable realm controller

View source
class VariableRealmDefaultController implements VariableRealmControllerInterface {
  public $realm;
  public $key;
  protected $variables;

  /**
   * Class constructor.
   */
  public function __construct($realm, $key, $variables = NULL) {
    $this->realm = $realm;
    $this->key = $key;
    $this->variables = $variables;
  }

  /**
   * Initialize variables.
   */
  public function variable_init() {
    if (!isset($this->variables)) {
      $this->variables = array();
    }
  }

  /**
   * Get single variable.
   *
   * @param $name
   *   Variable name
   * @param $default
   *   Default value
   */
  public function variable_get($name, $default = NULL) {
    $this
      ->variable_init();
    return isset($this->variables[$name]) ? $this->variables[$name] : $default;
  }

  /**
   * Set single variable.
   *
   * @param $name
   *   Variable name
   * @param $value
   *   Variable value
   */
  public function variable_set($name, $value) {
    $this
      ->variable_init();
    $this->variables[$name] = $value;
  }

  /**
   * Delete single variable.
   *
   * @param $name
   *   Variable name
   */
  public function variable_del($name) {
    $this
      ->variable_init();
    unset($this->variables[$name]);
  }

  /**
   * Implementation of VariableRealmControllerInterface::variable_add().
   */
  public function variable_add($name, $value) {
    $this
      ->variable_init();
    $this->variables[$name] = $value;
  }

  /**
   * List all current variable values.
   */
  public function variable_list() {
    $this
      ->variable_init();
    return $this->variables;
  }

}

Members