public function init() { $packages = PhpBURN_Configuration::getConfig(); print "<pre>"; foreach ($packages as $package => $packageConfig) { print_r($packageConfig); } $class = new _ReverseClass('teste', 'syscore'); $tables = $class->getConnection()->getTables(); foreach ($tables as $table) { $fieldData = $class->getConnection()->describe($table); // var_dump($fieldData); foreach ($fieldData as $data) { $options['primary'] = $data[4]; $options['not_null'] = $data[5]; $options['default_value'] = $data[6]; $options['auto_increment'] = $data[7]; $fields[] = self::generateField($data[0], $data[2], $data[3], $options); } print "============== {$table} ============== <br/>"; print_r($fields); $fks = !is_array($fks) ? array() : $fks; $localArr = $class->getConnection()->getForeignKeys($table); print_r($localArr); foreach ($localArr as $index => $keyArr) { $fks[$index][] = $keyArr; } // post-reverse unset($fields); } print "============== <b>FINAL</b> ============== <br/>"; var_dump($fks); }
public function init() { self::$thisPath = realpath(dirname(__FILE__)); $fks = null; $packages = PhpBURN_Configuration::getConfig(); foreach ($packages as $package => $packageConfig) { $class = new PhpBURN_ReverseClass('null', $packageConfig->package); $tables = $class->getConnection()->getTables(); foreach ($tables as $table) { $fieldData = $class->getConnection()->describe($table); foreach ($fieldData as $data) { $field['name'] = $data[0]; $field['type'] = $data[2]; $field['lenght'] = $data[3]; $options['primary'] = $data[4]; $options['not_null'] = $data[5]; $options['default_value'] = $data[6]; $options['auto_increment'] = $data[7]; $field['options'] = $options; $field['package'] = $packageConfig->package; $field['tableName'] = $table; self::$rawFields[$packageConfig->database . '.' . $table][] = $field; self::$fields[$packageConfig->database . '.' . $table][] = self::generateField($data[0], $data[2], $data[3], $options); unset($field); } // self::$fields[$packageConfig->database . '.' . $table] = $fields; $fks = !is_array($fks) ? array() : $fks; $tableFks = $class->getConnection()->getForeignKeys($table); //IS NOT MODEL FK IS TABLE foreach ($tableFks as $index => $keyArr) { self::$rawFks[$index][] = $keyArr; self::$thisTableFks[$keyArr['referencedTable']][] = $keyArr; } // post-reverse unset($fields, $tableFks, $fieldData); } } // // print "<h1> ===== FINAL FIELDS ===== </h1>"; // print_r(self::$fields); // // print "<h1> ===== RAW FKS ===== </h1>"; // print_r(self::$rawFks); foreach (self::$thisTableFks as $origin => $item) { foreach ($item as $index => $value) { self::$fks[$value['referencedTable']][] = self::generateRelationship($origin, $value); } } // // print "<h1> ===== FINAL EXAMPLE ===== </h1>"; // print_r(self::$thisTableFks); // // print "<h1> ===== FINAL FKS ===== </h1>"; // print_r(self::$fks); self::constructModelFiles(); }
public function migrate(PhpBURN_Core $model = null) { if ($model == null) { $packages = PhpBURN_Configuration::getConfig(); foreach ($packages as $package => $packageConfig) { self::loadModels($packageConfig); } } else { $model->getDialect()->migrate(); } }
/** * Enables autoload for PhpBURN Models */ public static function enableAutoload() { // Setting up Model if (array_search('PhpBURN_Core', get_declared_classes()) == true) { // Adds Models Paths to include Path $packages = PhpBURN_Configuration::getConfig(); foreach ($packages as $package => $configItem) { $includePath = get_include_path(); $separator = strpos($includePath, ':') !== false ? ':' : ';'; set_include_path($includePath . $separator . $configItem->class_path . DS . $package); } } }
/** * Auxiliar Method : Gets the Connection Object for the model * @return PhpBURN_Connection_(DatabaseType) * @see app/libs/Connection(Folder) */ public function getConnection() { //return $this->_connObj; return PhpBURN_ConnectionManager::create(PhpBURN_Configuration::getConfig($this->_package)); }
/** * Starts the PhpBURN Application - Should be called at the index of the application * <code> * PhpBURN::StartApplication(); * </code> */ public static function startApplication() { // Setting up Model if (array_search('PhpBURN_Core', get_declared_classes()) == true) { // Adds Models Paths to include Path $packages = PhpBURN_Configuration::getConfig(); foreach ($packages as $package => $configItem) { $includePath = get_include_path(); $separator = strpos($includePath, ':') !== false ? ':' : ';'; set_include_path($includePath . $separator . $configItem->class_path . DS . $package); } } // Setting up Controller if (array_search('Controller', get_declared_classes()) == true) { PhpBURN::load('Tools.Util.Router'); include_once SYS_APPLICATION_PATH . DS . 'config' . DS . 'routes.php'; //Define the main route functions $router = new Router($routes); $currentRoute = $router->parseRoute(); if ($currentRoute != false) { $router->executeRoute($currentRoute); } else { Controller::callErrorPage('404'); } } }
<?php ################################ # Model Settings ################################ $thisConfig = array('dialect' => 'MySQL', 'database' => 'Flisol', 'user' => 'flisol', 'password' => 'flisol', 'port' => '3306', 'host' => 'localhost', 'class_path' => SYS_MODEL_PATH, 'database_options' => array(), 'options' => array(), 'packages' => array('Flisol')); //Loading the configuration file $config = new PhpBURN_Configuration($thisConfig); $configItems = $config->getConfig(); foreach ($configItems as $package => $infos) { $path = $infos->class_path . $package . DS; set_include_path(get_include_path() . ': ' . $path); } spl_autoload_register(null, false); spl_autoload_extensions(SYS_MODEL_EXT); spl_autoload_register('PhpBURN::import');