/** * Constructor * * @throws Exception if `default` group connection fails * @return void */ public function __construct() { if (static::$init == FALSE) { // Register exception and error handler set_exception_handler(function ($e) { Gas::exception($e); }); // Access current instance singleton $CI =& get_instance(); // Load necessary configuration(s) $CI->config->load('gas', TRUE, TRUE); $CI->config->load('migration', TRUE, TRUE); // Set temporary config handler $config = array_merge($CI->config->item('gas'), array('migration' => $CI->config->item('migration'))); // Validate DB instance if (!class_exists('CI_DB')) { $DB = $CI->load->database('default', TRUE); // Register into CI super object, so we could monitore it $CI->db = $DB; } else { $DB = $CI->db; } if ($config['auto_create_models'] == TRUE or $config['auto_create_tables'] == TRUE) { // Load necessary helper and library $CI->load->helper('file'); $CI->load->library('migration'); } // Include the bootstrap include_once APPPATH . 'third_party' . DIRECTORY_SEPARATOR . 'gas' . DIRECTORY_SEPARATOR . 'bootstrap.php'; if (array_key_exists('auto', Gas\Core::$migration)) { // Execute migration if necessary if (!$CI->migration->latest()) { show_error($CI->migration->error_string()); } } // Set initialization flag static::$init = TRUE; } }