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 //echo "GENERATE CLASSES?";
20 parent::generateClasses();
24 function generateReaders()
26 $options = &PEAR::getStaticProperty('DB_DataObject','options');
29 foreach($this->tables as $this->table) {
30 $this->table = trim($this->table);
32 $out = array_merge($out, $this->_generateReader($this->table));
36 //echo '<PRE>';print_r($out);exit;
38 file_put_contents($options["ini_{$this->_database}"] . '.reader', serialize($out));
42 * Generate the cached readers used for meta data in the queries.
45 function _generateReader($table)
47 $DB = $this->getDatabaseConnection();
48 $dbtype = $DB->phptype;
49 $def = $this->_definitions[$table] ;
52 switch (strtoupper($t->type)) {
55 case 'INT2': // postgres
56 case 'INT4': // postgres
57 case 'INT8': // postgres
58 case 'SERIAL4': // postgres
59 case 'SERIAL8': // postgres
68 $ret[$table.'.'.$t->name] = array('type' => 'int');
73 case 'DOUBLE PRECISION': // double precision (firebird)
75 case 'FLOAT4': // real (postgres)
76 case 'FLOAT8': // double precision (postgres)
78 case 'MONEY': // mssql and maybe others
80 case 'NUMBER': // oci8
81 $ret[$table.'.'.$t->name] = array('type' => 'float'); //???
87 $ret[$table.'.'.$t->name] = array('type' => 'boolean'); //???
88 // postgres needs to quote '0'
89 if ($dbtype == 'pgsql') {
90 ///$type += DB_DATAOBJECT_STR;
101 case 'SET': // not really but oh well
103 case 'POINT': // mysql geometry stuff - not really string - but will do..
105 case 'TIMESTAMPTZ': // postgres
106 case 'BPCHAR': // postgres
107 case 'INTERVAL': // postgres (eg. '12 days')
109 case 'CIDR': // postgres IP net spec
110 case 'INET': // postgres IP
111 case 'MACADDR': // postgress network Mac address.
113 case 'INTEGER[]': // postgres type
114 case 'BOOLEAN[]': // postgres type
120 case 'BLOB': /// these should really be ignored!!!???
125 case 'CLOB': // oracle character lob support
127 case 'BYTEA': // postgres blob support..
128 $ret[$table.'.'.$t->name] = $t->name; // strings are not sent as arrays..
129 // $type = DB_DATAOBJECT_STR;
136 $ret[$table.'.'.$t->name] = array('type' => 'date', 'dateFormat' => 'Y-m-d'); //???
140 $ret[$table.'.'.$t->name] = $t->name; // technically not...
145 $ret[$table.'.'.$t->name] = array('type' => 'date', 'dateFormat' => 'Y-m-d H:i:s'); //???
148 case 'TIMESTAMP': // do other databases use this???
150 $ret[$table.'.'.$t->name] = ($dbtype == 'mysql') ?
151 array('type' => 'float') :
152 array('type' => 'date', 'dateFormat' => 'Y-m-d H:i:s');
160 $ret[$table.'.'.$t->name] = $t->name;
170 * Generate the cached *.ini and links.ini files (merged for all components)
173 static function writeCache($iniCacheTmp, $iniCache)
176 $ff = HTML_FlexyFramework::get();
177 $ff->debug('Framework Generator:writeCache ' . $iniCacheTmp . ' ' . $iniCache);
179 //var_dump($iniCacheTmp);
180 // echo '<PRE>';echo file_get_contents($iniCacheTmp);exit;
181 // only unpdate if nothing went wrong.
182 if (file_exists($iniCacheTmp) && filesize($iniCacheTmp)) {
183 if (file_exists($iniCache)) {
186 $ff->debug("Writing merged ini file : $iniCache\n");
187 rename($iniCacheTmp, $iniCache);
190 // readers..??? not needed??? (historical)
191 if (file_exists($iniCacheTmp.'.reader') && filesize($iniCacheTmp.'.reader')) {
192 if (file_exists($iniCache.'.reader')) {
193 unlink($iniCache.'.reader');
195 $ff->debug("Writing merged reader file : $iniCache.reader\n");
196 rename($iniCacheTmp.'.reader', $iniCache.'.reader');
200 // merge and set links.. test for generated links file..
202 $linksCacheTmp = preg_replace('/\.ini/', '.links.ini', $iniCacheTmp );
204 if (file_exists($linksCacheTmp )) {
205 $links = self::mergeIni( parse_ini_file($linksCacheTmp, true), $links);
206 unlink($linksCacheTmp);
208 // we are going to use the DataObject directories..
210 $inis = explode(PATH_SEPARATOR,$ff->DB_DataObject['class_location']);
211 //print_r($inis);exit;
212 $ff->debug("class_location = ". $ff->DB_DataObject['class_location']);
214 foreach($inis as $path) {
215 $ini = $path . '/'. strtolower( $ff->project) . '.links.ini';
217 if (!file_exists($ini)) {
218 $ff->debug("Framework Generator:writeCache PROJECT.links.ini does not exist in $path - trying glob");
220 // try scanning the directory for another ini file..
221 $ar = glob(dirname($ini).'/*.links.ini');
230 $ff->debug("Framework Generator:writeCache using {$ar[0]}");
232 // first file.. = with links removed..
233 $ini = preg_replace('/\.links\./' , '.', $ar[0]);
234 $ini = preg_replace('/\.ini$/', '.links.ini', $ini);
237 // why do this twice???
238 if (!file_exists($ini)) {
241 $ff->debug("Adding in $ini");
243 $links = self::mergeIni( parse_ini_file($ini, true), $links);
245 $iniLinksCache = preg_replace('/\.ini$/', '.links.ini', $iniCache);
247 foreach($links as $tbl=>$ar) {
248 $out[] = '['. $tbl .']';
249 foreach ($ar as $k=>$v) {
250 $out[] = $k . '=' .$v;
255 $ff->debug("Writing merged Links file : $iniLinksCache \n");
257 file_put_contents($iniCacheTmp. '.links.ini', implode("\n", $out));
258 if (file_exists($iniLinksCache)) {
259 unlink($iniLinksCache);
261 rename($iniCacheTmp. '.links.ini', $iniLinksCache);
264 /* bit like merge recursive, but it avoids doing stuff with arrays.. */
265 static function mergeIni($new, $old)
267 foreach($new as $g => $ar) {
268 if (!isset($old[$g])) {
272 foreach($ar as $k=>$v) {
273 if (isset($old[$g][$k])) {