You are here

abstract class crumbs_Container_AbstractLazyData in Crumbs, the Breadcrumbs suite 7.2

Container for lazy-initialized data.

Hierarchy

Expanded class hierarchy of crumbs_Container_AbstractLazyData

File

lib/Container/AbstractLazyData.php, line 6

View source
abstract class crumbs_Container_AbstractLazyData {

  /**
   * @var mixed[]
   */
  private $data = array();

  /**
   * @param string $key
   * @return mixed
   */
  function __get($key) {
    if (!array_key_exists($key, $this->data)) {
      $this->data[$key] = $this
        ->{$key}();
    }
    return $this->data[$key];
  }

  /**
   * @param string $key
   * @param mixed $value
   *
   * @throws Exception
   */
  function __set($key, $value) {
    if (array_key_exists($key, $this->data)) {
      throw new Exception("Value at '{$key}' already initialized.");
    }
    $this->data[$key] = $value;
  }

}

Members