1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-11 00:24:19 +02:00

dibi::$substs & fall-back provided via DibiLazyStorage

This commit is contained in:
David Grudl
2010-08-06 02:01:00 +02:00
parent 79735e96d1
commit 16dd0c7230
2 changed files with 13 additions and 18 deletions

View File

@@ -176,11 +176,8 @@ class dibi
/** @var DibiConnection Current connection */
private static $connection;
/** @var array Substitutions for identifiers */
public static $substs = array();
/** @var callback Substitution fallback */
public static $substFallBack = array(__CLASS__, 'defaultSubstFallback');
/** @var DibiLazyStorage Substitutions for identifiers */
public static $substs;
/** @var array @see addHandler */
private static $handlers = array();
@@ -638,7 +635,7 @@ class dibi
*/
public static function addSubst($expr, $subst)
{
self::$substs[$expr] = $subst;
self::$substs->$expr = $subst;
}
@@ -651,9 +648,9 @@ class dibi
public static function removeSubst($expr)
{
if ($expr === TRUE) {
self::$substs = array();
self::$substs = new DibiLazyStorage(self::$substs->getCallback());
} else {
unset(self::$substs[$expr]);
unset(self::$substs->$expr);
}
}
@@ -666,12 +663,7 @@ class dibi
*/
public static function setSubstFallback($callback)
{
if (!is_callable($callback)) {
$able = is_callable($callback, TRUE, $textual);
throw new InvalidArgumentException("Handler '$textual' is not " . ($able ? 'callable.' : 'valid PHP callback.'));
}
self::$substFallBack = $callback;
self::$substs->setCallback($callback);
}
@@ -755,3 +747,8 @@ class dibi
}
}
// static constructor
dibi::$substs = new DibiLazyStorage(array('dibi', 'defaultSubstFallback'));