1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-07 14:46:50 +02:00

DibiDatabaseInfo: uses DibiLazyStorage for column type detecting

This commit is contained in:
David Grudl
2010-08-03 07:35:18 +02:00
parent c93137340e
commit 8c5dc153f2

View File

@@ -472,9 +472,6 @@ class DibiColumnInfo extends DibiObject
/** @var array (name, nativetype, [table], [fullname], [size], [nullable], [default], [autoincrement], [vendor]) */ /** @var array (name, nativetype, [table], [fullname], [size], [nullable], [default], [autoincrement], [vendor]) */
private $info; private $info;
/** @var string */
private $type;
public function __construct(IDibiReflector $driver, array $info) public function __construct(IDibiReflector $driver, array $info)
@@ -533,10 +530,10 @@ class DibiColumnInfo extends DibiObject
*/ */
public function getType() public function getType()
{ {
if ($this->type === NULL) { if (self::$types === NULL) {
$this->type = self::detectType($this->info['nativetype']); self::$types = new DibiLazyStorage(array(__CLASS__, 'detectType'));
} }
return $this->type; return self::$types->{$this->info['nativetype']};
} }
@@ -616,8 +613,9 @@ class DibiColumnInfo extends DibiObject
* Heuristic type detection. * Heuristic type detection.
* @param string * @param string
* @return string * @return string
* @internal
*/ */
private static function detectType($type) public static function detectType($type)
{ {
static $patterns = array( static $patterns = array(
'BYTEA|BLOB|BIN' => dibi::BINARY, 'BYTEA|BLOB|BIN' => dibi::BINARY,
@@ -630,15 +628,12 @@ class DibiColumnInfo extends DibiObject
'BOOL|BIT' => dibi::BOOL, 'BOOL|BIT' => dibi::BOOL,
); );
if (!isset(self::$types[$type])) { foreach ($patterns as $s => $val) {
self::$types[$type] = dibi::TEXT; if (preg_match("#$s#i", $type)) {
foreach ($patterns as $s => $val) { return $val;
if (preg_match("#$s#i", $type)) {
return self::$types[$type] = $val;
}
} }
} }
return self::$types[$type]; return dibi::TEXT;
} }
} }