2010-08-03 06:28:17 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2010-09-14 18:40:41 +02:00
|
|
|
* This file is part of the "dibi" - smart database abstraction layer.
|
2010-08-03 06:28:17 +02:00
|
|
|
*
|
2010-09-14 18:40:41 +02:00
|
|
|
* 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
|
2010-08-03 06:28:17 +02:00
|
|
|
* @package dibi
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**#@+
|
|
|
|
* Lazy cached storage.
|
|
|
|
*
|
2010-09-14 18:40:41 +02:00
|
|
|
* @author David Grudl
|
2010-08-03 06:28:17 +02:00
|
|
|
* @internal
|
|
|
|
*/
|
2011-01-25 18:00:29 +01:00
|
|
|
abstract class DibiHashMapBase
|
2010-08-03 06:28:17 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-01-25 18:00:29 +01:00
|
|
|
final class DibiHashMap extends DibiHashMapBase
|
2010-08-03 06:28:17 +02:00
|
|
|
{
|
|
|
|
|
2010-08-06 01:30:22 +02:00
|
|
|
public function __set($nm, $val)
|
2010-08-03 06:28:17 +02:00
|
|
|
{
|
2010-08-06 01:30:22 +02:00
|
|
|
if ($nm == '') {
|
|
|
|
$nm = "\xFF";
|
2010-08-03 06:28:17 +02:00
|
|
|
}
|
2010-08-06 01:30:22 +02:00
|
|
|
$this->$nm = $val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function __get($nm)
|
|
|
|
{
|
2010-08-03 13:40:47 +02:00
|
|
|
if ($nm == '') {
|
2010-08-06 01:30:22 +02:00
|
|
|
$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);
|
2010-08-03 13:40:47 +02:00
|
|
|
}
|
2010-08-03 06:28:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
/**#@-*/
|