diff --git a/dibi/dibi.php b/dibi/dibi.php index 7116e3c5..3dc88500 100644 --- a/dibi/dibi.php +++ b/dibi/dibi.php @@ -107,6 +107,7 @@ class DibiVariable extends DateTime53 // dibi libraries require_once dirname(__FILE__) . '/libs/interfaces.php'; require_once dirname(__FILE__) . '/libs/DibiObject.php'; +require_once dirname(__FILE__) . '/libs/DibiLazyStorage.php'; require_once dirname(__FILE__) . '/libs/DibiException.php'; require_once dirname(__FILE__) . '/libs/DibiConnection.php'; require_once dirname(__FILE__) . '/libs/DibiResult.php'; diff --git a/dibi/libs/DibiLazyStorage.php b/dibi/libs/DibiLazyStorage.php new file mode 100644 index 00000000..ffccb398 --- /dev/null +++ b/dibi/libs/DibiLazyStorage.php @@ -0,0 +1,66 @@ +setCallback($callback); + } + + + + public function setCallback($callback) + { + if (!is_callable($callback)) { + $able = is_callable($callback, TRUE, $textual); + throw new InvalidArgumentException("Handler '$textual' is not " . ($able ? 'callable.' : 'valid PHP callback.')); + } + $this->callback = $callback; + } + + + + public function getCallback() + { + return $this->callback; + } + +} + + + +final class DibiLazyStorage extends DibiLazyStorageBase +{ + + public function __get($nm) + { + if (is_array($nm)) { // preg_replace_callback support + $nm = $nm[1]; + } + return $this->$nm = call_user_func($this->getCallback(), $nm); + } + +} +/**#@-*/