summaryrefslogtreecommitdiffstats
path: root/system/core/Loader.php
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-11-06 00:11:22 +0100
committerAndrey Andreev <narf@bofh.bg>2012-11-06 00:11:22 +0100
commiteaa60c71082c1e49f8a48d633347c98b68a387c0 (patch)
tree41438b0e6fde0dcb3fd2348e5b52dc9c128f88db /system/core/Loader.php
parentd743cdbe448258cc7f02abf15e8dc797dc6403eb (diff)
Added possibility to pass custom database objects to DB Forge and DB Utilities
Also, their property is no longer public and the utility class no longer extends CI_DB_forge.
Diffstat (limited to 'system/core/Loader.php')
-rw-r--r--system/core/Loader.php61
1 files changed, 36 insertions, 25 deletions
diff --git a/system/core/Loader.php b/system/core/Loader.php
index 808fa80df..9525f35d0 100644
--- a/system/core/Loader.php
+++ b/system/core/Loader.php
@@ -352,26 +352,30 @@ class CI_Loader {
/**
* Load the Database Utilities Class
*
- * @return void
+ * @param object $db Database object
+ * @param bool $return Whether to return the DB Forge class object or not
+ * @return void|object
*/
- public function dbutil()
+ public function dbutil($db = NULL, $return = FALSE)
{
- if ( ! class_exists('CI_DB'))
- {
- $this->database();
- }
-
$CI =& get_instance();
- // for backwards compatibility, load dbforge so we can extend dbutils off it
- // this use is deprecated and strongly discouraged
- $CI->load->dbforge();
+ if ( ! is_object($db) OR ! ($db instanceof CI_DB))
+ {
+ class_exists('CI_DB', FALSE) OR $this->database();
+ $db =& $CI->db;
+ }
require_once(BASEPATH.'database/DB_utility.php');
- require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_utility.php');
- $class = 'CI_DB_'.$CI->db->dbdriver.'_utility';
+ require_once(BASEPATH.'database/drivers/'.$db->dbdriver.'/'.$db->dbdriver.'_utility.php');
+ $class = 'CI_DB_'.$db->dbdriver.'_utility';
+
+ if ($return === TRUE)
+ {
+ return new $class($db);
+ }
- $CI->dbutil = new $class();
+ $CI->dbutil = new $class($db);
}
// --------------------------------------------------------------------
@@ -379,35 +383,42 @@ class CI_Loader {
/**
* Load the Database Forge Class
*
- * @return void
+ * @param object $db Database object
+ * @param bool $return Whether to return the DB Forge class object or not
+ * @return void|object
*/
- public function dbforge()
+ public function dbforge($db = NULL, $return = FALSE)
{
- if ( ! class_exists('CI_DB'))
+ $CI =& get_instance();
+ if ( ! is_object($db) OR ! ($db instanceof CI_DB))
{
- $this->database();
+ class_exists('CI_DB', FALSE) OR $this->database();
+ $db =& $CI->db;
}
- $CI =& get_instance();
-
require_once(BASEPATH.'database/DB_forge.php');
- require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge.php');
+ require_once(BASEPATH.'database/drivers/'.$db->dbdriver.'/'.$db->dbdriver.'_forge.php');
- if ( ! empty($CI->db->subdriver))
+ if ( ! empty($db->subdriver))
{
- $driver_path = BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/subdrivers/'.$CI->db->dbdriver.'_'.$CI->db->subdriver.'_forge.php';
+ $driver_path = BASEPATH.'database/drivers/'.$db->dbdriver.'/subdrivers/'.$db->dbdriver.'_'.$db->subdriver.'_forge.php';
if (file_exists($driver_path))
{
require_once($driver_path);
- $class = 'CI_DB_'.$CI->db->dbdriver.'_'.$CI->db->subdriver.'_forge';
+ $class = 'CI_DB_'.$db->dbdriver.'_'.$db->subdriver.'_forge';
}
}
else
{
- $class = 'CI_DB_'.$CI->db->dbdriver.'_forge';
+ $class = 'CI_DB_'.$db->dbdriver.'_forge';
+ }
+
+ if ($return === TRUE)
+ {
+ return new $class($db);
}
- $CI->dbforge = new $class();
+ $CI->dbforge = new $class($db);
}
// --------------------------------------------------------------------