1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-06 14:16:39 +02:00

renamed DibiLazyStorage to DibiHashMap

This commit is contained in:
David Grudl
2011-01-25 18:00:29 +01:00
parent 1ada6fab97
commit 9c52b8ea9d
6 changed files with 12 additions and 12 deletions

77
dibi/libs/DibiHashMap.php Normal file
View File

@@ -0,0 +1,77 @@
<?php
/**
* This file is part of the "dibi" - smart database abstraction layer.
*
* Copyright (c) 2005, 2010 David Grudl (http://davidgrudl.com)
*
* This source file is subject to the "dibi license", and/or
* GPL license. For more information please see http://dibiphp.com
* @package dibi
*/
/**#@+
* Lazy cached storage.
*
* @author David Grudl
* @internal
*/
abstract class DibiHashMapBase
{
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 DibiHashMap extends DibiHashMapBase
{
public function __set($nm, $val)
{
if ($nm == '') {
$nm = "\xFF";
}
$this->$nm = $val;
}
public function __get($nm)
{
if ($nm == '') {
$nm = "\xFF";
return isset($this->$nm) ? $this->$nm : $this->$nm = call_user_func($this->getCallback(), '');
} else {
return $this->$nm = call_user_func($this->getCallback(), $nm);
}
}
}
/**#@-*/