mirror of
https://github.com/dg/dibi.git
synced 2025-08-07 22:56:35 +02:00
added DibiLazyStorage, simple caching layer
This commit is contained in:
@@ -107,6 +107,7 @@ class DibiVariable extends DateTime53
|
|||||||
// dibi libraries
|
// dibi libraries
|
||||||
require_once dirname(__FILE__) . '/libs/interfaces.php';
|
require_once dirname(__FILE__) . '/libs/interfaces.php';
|
||||||
require_once dirname(__FILE__) . '/libs/DibiObject.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/DibiException.php';
|
||||||
require_once dirname(__FILE__) . '/libs/DibiConnection.php';
|
require_once dirname(__FILE__) . '/libs/DibiConnection.php';
|
||||||
require_once dirname(__FILE__) . '/libs/DibiResult.php';
|
require_once dirname(__FILE__) . '/libs/DibiResult.php';
|
||||||
|
66
dibi/libs/DibiLazyStorage.php
Normal file
66
dibi/libs/DibiLazyStorage.php
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dibi - tiny'n'smart database abstraction layer
|
||||||
|
* ----------------------------------------------
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2005, 2010 David Grudl
|
||||||
|
* @license http://dibiphp.com/license dibi license
|
||||||
|
* @link http://dibiphp.com
|
||||||
|
* @package dibi
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**#@+
|
||||||
|
* Lazy cached storage.
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2005, 2010 David Grudl
|
||||||
|
* @package dibi
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
abstract class DibiLazyStorageBase
|
||||||
|
{
|
||||||
|
private $callback;
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct($callback)
|
||||||
|
{
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/**#@-*/
|
Reference in New Issue
Block a user