public function lookup($key, $closure = null)
{
// if a closure was provided and we missed, store it
if (!is_null($closure) && !isset($this->_registry[$key]) && !isset($this->_triggers[$key])) {
$this->_registry[$key] = $this->_memoize($closure($key));
}
// the registry stores closures
if (isset($this->_registry[$key])) {
$result = call_user_func($this->_registry[$key], $this);
$this->_registry[$key] = $this->_memoize($result);
return $result;
} else {
if (isset($this->_triggers[$key])) {
call_user_func($this->_triggers[$key], $this);
unset($this->_triggers[$key]);
return $this->lookup($key);
} else {
throw new RegistryException("No entry for key '{$key}'");
}
}
}