1
0
mirror of https://github.com/dg/dibi.git synced 2025-02-23 10:26:21 +01:00

DibiLazyStorage: allows empty string as property name for reading

This commit is contained in:
David Grudl 2010-08-06 01:30:22 +02:00
parent 325305326b
commit 79735e96d1
2 changed files with 15 additions and 6 deletions

View File

@ -544,7 +544,7 @@ class DibiColumnInfo extends DibiObject
if (self::$types === NULL) {
self::$types = new DibiLazyStorage(array(__CLASS__, 'detectType'));
}
return $this->info['nativetype'] ? self::$types->{$this->info['nativetype']} : dibi::TEXT;
return self::$types->{$this->info['nativetype']};
}

View File

@ -54,15 +54,24 @@ abstract class DibiLazyStorageBase
final class DibiLazyStorage extends DibiLazyStorageBase
{
public function __set($nm, $val)
{
if ($nm == '') {
$nm = "\xFF";
}
$this->$nm = $val;
}
public function __get($nm)
{
if (is_array($nm)) { // preg_replace_callback support
$nm = $nm[1];
}
if ($nm == '') {
throw new InvalidStateException('Missing identifier name.');
$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);
}
return $this->$nm = call_user_func($this->getCallback(), $nm);
}
}