4 require_once 'DB/DataObject/Generator.php';
7 class HTML_FlexyFramework_Generator extends DB_DataObject_Generator
9 // block class generation.
10 static $generateClasses = false;
12 function generateClasses()
14 //echo "GENERATE CLASSES?";
15 if (!HTML_FlexyFramework_Generator::$generateClasses ) {
19 parent::generateClasses();
23 function generateReaders()
25 $options = &PEAR::getStaticProperty('DB_DataObject','options');
28 foreach($this->tables as $this->table) {
29 $this->table = trim($this->table);
31 $out = array_merge($out, $this->_generateReader($this->table));
35 //echo '<PRE>';print_r($out);exit;
37 file_put_contents($options["ini_{$this->_database}"] . '.reader', serialize($out));
40 function _generateReader($table)
42 $DB = $this->getDatabaseConnection();
43 $dbtype = $DB->phptype;
44 $def = $this->_definitions[$table] ;
47 switch (strtoupper($t->type)) {
50 case 'INT2': // postgres
51 case 'INT4': // postgres
52 case 'INT8': // postgres
53 case 'SERIAL4': // postgres
54 case 'SERIAL8': // postgres
63 $ret[$table.'.'.$t->name] = array('type' => 'int');
68 case 'DOUBLE PRECISION': // double precision (firebird)
70 case 'FLOAT4': // real (postgres)
71 case 'FLOAT8': // double precision (postgres)
73 case 'MONEY': // mssql and maybe others
75 case 'NUMBER': // oci8
76 $ret[$table.'.'.$t->name] = array('type' => 'float'); //???
82 $ret[$table.'.'.$t->name] = array('type' => 'boolean'); //???
83 // postgres needs to quote '0'
84 if ($dbtype == 'pgsql') {
85 ///$type += DB_DATAOBJECT_STR;
96 case 'SET': // not really but oh well
98 case 'POINT': // mysql geometry stuff - not really string - but will do..
100 case 'TIMESTAMPTZ': // postgres
101 case 'BPCHAR': // postgres
102 case 'INTERVAL': // postgres (eg. '12 days')
104 case 'CIDR': // postgres IP net spec
105 case 'INET': // postgres IP
106 case 'MACADDR': // postgress network Mac address.
108 case 'INTEGER[]': // postgres type
109 case 'BOOLEAN[]': // postgres type
115 case 'BLOB': /// these should really be ignored!!!???
120 case 'CLOB': // oracle character lob support
122 case 'BYTEA': // postgres blob support..
123 $ret[$table.'.'.$t->name] = $t->name; // strings are not sent as arrays..
124 // $type = DB_DATAOBJECT_STR;
131 $ret[$table.'.'.$t->name] = array('type' => 'date', 'dateFormat' => 'Y-m-d'); //???
135 $ret[$table.'.'.$t->name] = $t->name; // technically not...
140 $ret[$table.'.'.$t->name] = array('type' => 'date', 'dateFormat' => 'Y-m-d H:i:s'); //???
143 case 'TIMESTAMP': // do other databases use this???
145 $ret[$table.'.'.$t->name] = ($dbtype == 'mysql') ?
146 array('type' => 'float') :
147 array('type' => 'date', 'dateFormat' => 'Y-m-d H:i:s');
155 $ret[$table.'.'.$t->name] = $t->name;
165 static function writeCache($iniCacheTmp, $iniCache)
168 $ff = HTML_FlexyFramework::get();
170 //var_dump($iniCacheTmp);
171 // echo '<PRE>';echo file_get_contents($iniCacheTmp);exit;
172 // only unpdate if nothing went wrong.
173 if (filesize($iniCacheTmp)) {
174 if (file_exists($iniCache)) {
177 rename($iniCacheTmp, $iniCache);
181 if (filesize($iniCacheTmp.'.reader')) {
182 if (file_exists($iniCache.'.reader')) {
183 unlink($iniCache.'.reader');
185 rename($iniCacheTmp.'.reader', $iniCache.'.reader');
189 // merge and set links..
191 $inis = explode(PATH_SEPARATOR,$ff->dataObjectsOriginalIni);
193 foreach($inis as $ini) {
194 $ini = preg_replace('/\.ini$/', '.links.ini', $ini);
195 if (!file_exists($ini)) {
196 // try scanning the directory for another ini file..
197 $ar = glob(dirname($ini).'/*.ini');
202 // first file.. = with links removed..
203 $ini = preg_replace('/\.links\./' , '.', $ar[0]);
204 $ini = preg_replace('/\.ini$/', '.links.ini', $ini);
206 $links = array_merge_recursive($links , parse_ini_file($ini, true));
209 $iniLinksCache = preg_replace('/\.ini$/', '.links.ini', $iniCache);
211 foreach($links as $tbl=>$ar) {
212 $out[] = '['. $tbl .']';
213 foreach ($ar as $k=>$v) {
214 $out[] = $k . '=' .$v;
219 file_put_contents($iniLinksCache. '.tmp', implode("\n", $out));
220 if (file_exists($iniLinksCache)) {
221 unlink($iniLinksCache);
223 rename($iniLinksCache. '.tmp', $iniLinksCache);