-
Notifications
You must be signed in to change notification settings - Fork 0
/
Metadata.php
executable file
·71 lines (61 loc) · 1.99 KB
/
Metadata.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* Sabel_Db_Metadata
*
* @category DB
* @package org.sabel.db
* @author Ebine Yutaka <ebine.yutaka@sabel.jp>
* @copyright 2004-2008 Mori Reo <mori.reo@sabel.jp>
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
*/
class Sabel_Db_Metadata
{
private static $metadata = array();
public static function getTableInfo($tblName, $connectionName = "default")
{
if (isset(self::$metadata[$tblName])) {
return self::$metadata[$tblName];
}
if (self::schemaClassExists($tblName)) {
$cols = array();
$className = "Schema_" . convert_to_modelname($tblName);
$schemaClass = new $className();
foreach ($schemaClass->get() as $colName => $info) {
$co = new Sabel_Db_Metadata_Column();
$co->name = $colName;
foreach ($info as $key => $val) $co->$key = $val;
$cols[$colName] = $co;
}
$tblSchema = new Sabel_Db_Metadata_Table($tblName, $cols);
$properties = $schemaClass->getProperty();
$tblSchema->setTableEngine($properties["tableEngine"]);
$tblSchema->setUniques($properties["uniques"]);
$tblSchema->setForeignKeys($properties["fkeys"]);
} else {
$schemaObj = Sabel_Db::createMetadata($connectionName);
$tblSchema = $schemaObj->getTable($tblName);
}
return self::$metadata[$tblName] = $tblSchema;
}
public static function schemaClassExists($tblName)
{
$className = "Schema_" . convert_to_modelname($tblName);
return Sabel::using($className);
}
public static function getTableList($connectionName = "default")
{
$className = "Schema_" . ucfirst($connectionName) . "TableList";
if (Sabel::using($className)) {
$sc = new $className();
return $sc->get();
} else {
return Sabel_Db::createMetadata($connectionName)->getTableList();
}
}
public static function clear()
{
$metadata = self::$metadata;
self::$metadata = array();
return $metadata;
}
}