/** * Utility function : Model debugger. Will ensure and validate the mapping of a specified Model, or every one (in case no argument is passed) * @method modelDebug * @param string * @return boolean */ function modelDebug($model = null) { CI()->load->database(); CI()->load->dbutil(); $map_list = Manager()->getMap($model); is_array($map_list) or $map_list = array($map_list); foreach ($map_list as $model => $map) { $primary_key = false; foreach ($map as $key => $value) { $parts = explode('.', $key); // Database name verification if (!CI()->dbutil->database_exists($parts[1])) { show_error('Remap declaration error for attribute "' . $value . '" : ' . $parts[1] . ' is not a valid database name.<br /><br /><b>Filename :</b> ' . $model . '.php'); die; } // Table name verification if (!CI()->db->table_exists($parts[2])) { show_error('Remap declaration error for attribute "' . $value . '" : ' . $parts[2] . ' is not a valid table name.<br /><br /><b>Filename :</b> ' . $model . '.php'); die; } // Field name verification if (!CI()->db->field_exists($parts[3], $parts[2])) { show_error('Remap declaration error for attribute "' . $value . '" : ' . $parts[3] . ' is not a valid field name.<br /><br /><b>Filename :</b> ' . $model . '.php'); die; } // Primary keay verification $primary_key = $primary_key || $parts[3] === 'id'; } if (!$primary_key) { show_error('Remap declaration error : missing "id" attribute !<br /><br /><b>Filename :</b> ' . $model . '.php'); die; } } echo '<h1>Model Debbuger ended without any problem. Every Model seems correctly remaped, good work ! ;)</h1>'; die; }
/** * Utility function (internal use only) : clears Model / Manager variables (called right before returning a newly created instance). * @method _reset * @private * @return void */ private function _reset($new_instance = false) { // MICRO-OPTIMIZATION : MUST BE TESTED BEFORE BEING INTEGRATED // $Manager = Manager(); // $Manager->reset_db_result(); Manager()->resetDbResult(); if ($new_instance) { // $map = $Manager->get_map(get_class($this)); $map = Manager()->getMap(get_class($this)); if (is_array($map)) { foreach ($map as $m) { $this->{$m} = null; } } // MICRO-OPTIMIZATION : MUST BE TESTED BEFORE BEING INTEGRATED // unset($map); } }