You are here

class DStatic in Little helpers 7

This class deals with request wide variables and flags. It's best to think of it like an object oriented version of drupal_static().

Hierarchy

  • class \Drupal\little_helpers\DStatic

Expanded class hierarchy of DStatic

File

src/DStatic.php, line 9

Namespace

Drupal\little_helpers
View source
class DStatic {
  protected static $data = array();

  /**
   * Set a value by value. This is mainly for convenience (default value) and
   * so that calls like:
   *  DStatic::setFlag('name', 'somevalue');
   * work without warings.
   *
   * @param string $name
   *   name of the value to set.
   * @param mixed $value
   *   value of any type to store.
   */
  public static function setFlag($name, $value = TRUE) {
    self::$data[$name] = $value;
  }

  /**
   * Set a value by reference.
   *
   * @param string $name
   *   name of the value to set.
   * @param mixed $value
   *   value of any type to store.
   */
  public static function set($name, &$value) {
    self::$data[$name] =& $value;
  }

  /**
   * Get a stored value.
   *
   * @param string $name
   *   name of the value to get.
   */
  public static function get($name) {
    return isset(self::$data[$name]) ? self::$data[$name] : NULL;
  }

  /**
   * Delete all static variables that have been accumulated in this request.
   */
  public static function reset() {
    self::$data = array();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DStatic::$data protected static property
DStatic::get public static function Get a stored value.
DStatic::reset public static function Delete all static variables that have been accumulated in this request.
DStatic::set public static function Set a value by reference.
DStatic::setFlag public static function Set a value by value. This is mainly for convenience (default value) and so that calls like: DStatic::setFlag('name', 'somevalue'); work without warings.