summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authoradmin <devnull@localhost>2006-10-10 09:12:31 +0200
committeradmin <devnull@localhost>2006-10-10 09:12:31 +0200
commitcf49390d3d699d878eb6e151745e80285465ddb9 (patch)
treefa66a6ae5d96f9cf828ecc86435e5dbde9fa285b /system
parentada5fa37c19c2f7f3de210869dca6243ca9b4174 (diff)
Diffstat (limited to 'system')
-rw-r--r--system/codeigniter/Base4.php29
-rw-r--r--system/libraries/Controller.php17
-rw-r--r--system/libraries/Loader.php219
-rw-r--r--system/libraries/Model.php4
-rw-r--r--system/scaffolding/Scaffolding.php2
5 files changed, 188 insertions, 83 deletions
diff --git a/system/codeigniter/Base4.php b/system/codeigniter/Base4.php
index eccf58ed8..115c10727 100644
--- a/system/codeigniter/Base4.php
+++ b/system/codeigniter/Base4.php
@@ -18,10 +18,18 @@
/**
* CI_BASE - For PHP 4
*
- * This file is used only when Code Igniter is being run under PHP 4.
- * Since PHP 4 has such poor object handling we had to come up with
- * a hack (and a really ugly one at that...) to resolve some scoping
- * problems. PHP 5 doesn't suffer from this problem so we load one of
+ * This file is used only when Code Igniter is being run under PHP 4.
+ *
+ * In order to allow CI to work under PHP 4 we had to make the Loader class
+ * the parent class of the Controller Base class. It's the only way we
+ * could enable functions like $this->load->library('email') to instantiate
+ * classes that can then be used within controllers as $this->email->send()
+ *
+ * PHP 4 also has trouble referencing the CI super object within application
+ * constructors since objects do not exist until the class is fully
+ * instantiated. Basically PHP 4 sucks...
+ *
+ * Since PHP 5 doesn't suffer from this problem so we load one of
* two files based on the version of PHP being run.
*
* @package CodeIgniter
@@ -34,18 +42,25 @@
function CI_Base()
{
- global $OBJ;
parent::CI_Loader();
$this->load =& $this;
+
+ global $OBJ;
$OBJ = $this->load;
}
}
function &get_instance()
{
- global $OBJ, $CI;
+ global $CI, $OBJ;
+
+ if (is_object($CI))
+ {
+ $CI->_ci_use_instance = TRUE;
+ return $CI;
+ }
- return (is_object($CI)) ? $CI : $OBJ->load;
+ return $OBJ->load;
}
?> \ No newline at end of file
diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php
index 4b9e3e960..c80097a17 100644
--- a/system/libraries/Controller.php
+++ b/system/libraries/Controller.php
@@ -80,20 +80,13 @@ class Controller extends CI_Base {
if (floor(phpversion()) >= 5)
{
$this->load = new CI_Loader();
+ $this->load->_ci_use_instance = TRUE;
+ $this->load->_ci_autoloader();
}
-
- // Load everything specified in the autoload.php file
- $this->load->_ci_autoloader();
-
- // This allows anything loaded using $this->load (viwes, files, etc.)
- // to become accessible from within the Controller class functions.
- foreach (get_object_vars($this) as $key => $var)
+ else
{
- if (is_object($var))
- {
- $this->load->$key =& $this->$key;
- }
- }
+ $this->_ci_autoloader();
+ }
}
// --------------------------------------------------------------------
diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php
index ca4c4feba..1738438ed 100644
--- a/system/libraries/Loader.php
+++ b/system/libraries/Loader.php
@@ -28,15 +28,18 @@
*/
class CI_Loader {
- var $CI;
- var $ob_level;
- var $view_path = '';
- var $cached_vars = array();
- var $models = array();
- var $helpers = array();
- var $plugins = array();
- var $scripts = array();
- var $varmap = array('unit_test' => 'unit', 'user_agent' => 'agent');
+ var $_ci_ob_level;
+ var $_ci_view_path = '';
+ var $_ci_cached_vars = array();
+ var $_ci_models = array();
+ var $_ci_helpers = array();
+ var $_ci_plugins = array();
+ var $_ci_scripts = array();
+ var $_ci_varmap = array('unit_test' => 'unit', 'user_agent' => 'agent');
+
+ var $_ci_use_instance = FALSE; // This variable determines whether we should
+ // use $this or $CI =& get_instance()
+ // throughout this class. Don't mess with it.
/**
* Constructor
@@ -47,11 +50,9 @@ class CI_Loader {
* @access public
*/
function CI_Loader()
- {
- $this->CI =& get_instance();
-
- $this->view_path = APPPATH.'views/';
- $this->ob_level = ob_get_level();
+ {
+ $this->_ci_view_path = APPPATH.'views/';
+ $this->_ci_ob_level = ob_get_level();
log_message('debug', "Loader Class Initialized");
}
@@ -95,8 +96,7 @@ class CI_Loader {
if ($model == '')
return;
- // Is the model in a sub-folder?
- // If so, parse out the filename and path.
+ // Is the model in a sub-folder? If so, parse out the filename and path.
if (strpos($model, '/') === FALSE)
{
$path = '';
@@ -114,14 +114,25 @@ class CI_Loader {
$name = $model;
}
- if (in_array($name, $this->models, TRUE))
+ if (in_array($name, $this->_ci_models, TRUE))
{
return;
- }
+ }
- if (isset($this->CI->$name))
+ if ($this->_ci_use_instance)
+ {
+ $CI =& get_instance();
+ if (isset($CI->$name))
+ {
+ show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
+ }
+ }
+ else
{
- show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
+ if (isset($this->$name))
+ {
+ show_error('The model name you are loading is the name of a resource that is already being used: '.$name);
+ }
}
$model = strtolower($model);
@@ -136,7 +147,14 @@ class CI_Loader {
if ($db_conn === TRUE)
$db_conn = '';
- $this->CI->load->database($db_conn, FALSE, TRUE);
+ if ($this->_ci_use_instance)
+ {
+ $CI->load->database($db_conn, FALSE, TRUE);
+ }
+ else
+ {
+ $this->database($db_conn, FALSE, TRUE);
+ }
}
if ( ! class_exists('Model'))
@@ -147,8 +165,17 @@ class CI_Loader {
require_once(APPPATH.'models/'.$path.$model.EXT);
$model = ucfirst($model);
- $this->CI->$name = new $model();
- $this->models[] = $name;
+
+ if ($this->_ci_use_instance)
+ {
+ $CI->$name = new $model();
+ }
+ else
+ {
+ $this->$name = new $model();
+ }
+
+ $this->_ci_models[] = $name;
$this->_ci_assign_to_models();
}
@@ -239,7 +266,7 @@ class CI_Loader {
{
foreach ($vars as $key => $val)
{
- $this->cached_vars[$key] = $val;
+ $this->_ci_cached_vars[$key] = $val;
}
}
}
@@ -264,7 +291,7 @@ class CI_Loader {
foreach ($helpers as $helper)
{
- if (isset($this->helpers[$helper]))
+ if (isset($this->_ci_helpers[$helper]))
{
continue;
}
@@ -287,7 +314,7 @@ class CI_Loader {
}
}
- $this->helpers[$helper] = TRUE;
+ $this->_ci_helpers[$helper] = TRUE;
}
log_message('debug', 'Helpers loaded: '.implode(', ', $helpers));
@@ -330,7 +357,7 @@ class CI_Loader {
foreach ($plugins as $plugin)
{
- if (isset($this->plugins[$plugin]))
+ if (isset($this->_ci_plugins[$plugin]))
{
continue;
}
@@ -353,7 +380,7 @@ class CI_Loader {
}
}
- $this->plugins[$plugin] = TRUE;
+ $this->_ci_plugins[$plugin] = TRUE;
}
log_message('debug', 'Plugins loaded: '.implode(', ', $plugins));
@@ -400,7 +427,7 @@ class CI_Loader {
foreach ($scripts as $script)
{
- if (isset($this->scripts[$script]))
+ if (isset($this->_ci_scripts[$script]))
{
continue;
}
@@ -414,7 +441,7 @@ class CI_Loader {
include_once(APPPATH.'scripts/'.$script.EXT);
- $this->scripts[$script] = TRUE;
+ $this->_ci_scripts[$script] = TRUE;
}
log_message('debug', 'Scripts loaded: '.implode(', ', $scripts));
@@ -431,7 +458,15 @@ class CI_Loader {
*/
function language($file = '', $lang = '', $return = FALSE)
{
- return $this->CI->lang->load($file, $lang, $return);
+ if ($this->_ci_use_instance)
+ {
+ $CI =& get_instance();
+ return $CI->lang->load($file, $lang, $return);
+ }
+ else
+ {
+ return $this->lang->load($file, $lang, $return);
+ }
}
// --------------------------------------------------------------------
@@ -444,8 +479,16 @@ class CI_Loader {
* @return void
*/
function config($file = '')
- {
- $this->CI->config->load($file);
+ {
+ if ($this->_ci_use_instance)
+ {
+ $CI =& get_instance();
+ $CI->config->load($file);
+ }
+ else
+ {
+ $this->config->load($file);
+ }
}
// --------------------------------------------------------------------
@@ -471,9 +514,18 @@ class CI_Loader {
{
show_error('You must include the name of the table you would like access when you initialize scaffolding');
}
-
- $this->CI->_ci_scaffolding = TRUE;
- $this->CI->_ci_scaff_table = $table;
+
+ if ($this->_ci_use_instance)
+ {
+ $CI =& get_instance();
+ $CI->_ci_scaffolding = TRUE;
+ $CI->_ci_scaff_table = $table;
+ }
+ else
+ {
+ $this->_ci_scaffolding = TRUE;
+ $this->_ci_scaff_table = $table;
+ }
}
// --------------------------------------------------------------------
@@ -491,14 +543,20 @@ class CI_Loader {
{
// This allows anything loaded using $this->load (viwes, files, etc.)
// to become accessible from within the Controller and Model functions.
- foreach (get_object_vars($this->CI) as $key => $var)
+ // Only needed when running PHP 5
+
+ if ($this->_ci_use_instance)
{
- if (is_object($var))
+ $CI =& get_instance();
+ foreach (get_object_vars($CI) as $key => $var)
{
- $this->$key =& $this->CI->$key;
+ if ( ! isset($this->$key))
+ {
+ $this->$key =& $CI->$key;
+ }
}
}
-
+
// Set the default data variables
foreach (array('view', 'vars', 'path', 'return') as $val)
{
@@ -515,16 +573,16 @@ class CI_Loader {
*/
if (is_array($vars))
{
- $this->cached_vars = array_merge($this->cached_vars, $vars);
+ $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $vars);
}
- extract($this->cached_vars);
+ extract($this->_ci_cached_vars);
// Set the path to the requested file
if ($path == '')
{
$ext = pathinfo($view, PATHINFO_EXTENSION);
$file = ($ext == '') ? $view.EXT : $view;
- $path = $this->view_path.$file;
+ $path = $this->_ci_view_path.$file;
}
else
{
@@ -572,14 +630,15 @@ class CI_Loader {
* it can be seen and included properly by the first included
* template and any subsequent ones. Oy!
*
- */
- if (ob_get_level() > $this->ob_level + 1)
+ */
+ if (ob_get_level() > $this->_ci_ob_level + 1)
{
ob_end_flush();
}
else
{
- $this->CI->output->set_output(ob_get_contents());
+ global $OUT;
+ $OUT->set_output(ob_get_contents());
ob_end_clean();
}
}
@@ -682,18 +741,33 @@ class CI_Loader {
else
{
$class = strtolower($class);
- $classvar = ( ! isset($this->varmap[$class])) ? $class : $this->varmap[$class];
+ $classvar = ( ! isset($this->_ci_varmap[$class])) ? $class : $this->_ci_varmap[$class];
}
- // Instantiate the class
- if ($config !== NULL)
+ // Instantiate the class
+ if ($this->_ci_use_instance)
{
- $this->CI->$classvar = new $name($config);
+ $CI =& get_instance();
+ if ($config !== NULL)
+ {
+ $CI->$classvar = new $name($config);
+ }
+ else
+ {
+ $CI->$classvar = new $name;
+ }
}
else
- {
- $this->CI->$classvar = new $name;
- }
+ {
+ if ($config !== NULL)
+ {
+ $this->$classvar = new $name($config);
+ }
+ else
+ {
+ $this->$classvar = new $name;
+ }
+ }
}
// --------------------------------------------------------------------
@@ -719,10 +793,21 @@ class CI_Loader {
// Load any custome config file
if (count($autoload['config']) > 0)
- {
- foreach ($autoload['config'] as $key => $val)
+ {
+ if ($this->_ci_use_instance)
+ {
+ $CI =& get_instance();
+ foreach ($autoload['config'] as $key => $val)
+ {
+ $CI->config->load($val);
+ }
+ }
+ else
{
- $this->CI->config->load($val);
+ foreach ($autoload['config'] as $key => $val)
+ {
+ $this->config->load($val);
+ }
}
}
@@ -788,14 +873,26 @@ class CI_Loader {
*/
function _ci_assign_to_models()
{
- if (count($this->models) == 0)
+ if (count($this->_ci_models) == 0)
{
return;
}
- foreach ($this->models as $model)
- {
- $this->CI->$model->_assign_libraries();
- }
+
+ if ($this->_ci_use_instance)
+ {
+ $CI =& get_instance();
+ foreach ($this->_ci_models as $model)
+ {
+ $CI->$model->_assign_libraries();
+ }
+ }
+ else
+ {
+ foreach ($this->_ci_models as $model)
+ {
+ $this->$model->_assign_libraries();
+ }
+ }
}
// --------------------------------------------------------------------
diff --git a/system/libraries/Model.php b/system/libraries/Model.php
index 46f0367cb..48615e07c 100644
--- a/system/libraries/Model.php
+++ b/system/libraries/Model.php
@@ -51,8 +51,8 @@ class Model {
{
$CI =& get_instance();
foreach (get_object_vars($CI) as $key => $var)
- {
- if (is_object($var) AND ! isset($this->$key))
+ {
+ if ( ! isset($this->$key))
{
if ($use_reference === TRUE)
{
diff --git a/system/scaffolding/Scaffolding.php b/system/scaffolding/Scaffolding.php
index c046d228f..6c4b3a537 100644
--- a/system/scaffolding/Scaffolding.php
+++ b/system/scaffolding/Scaffolding.php
@@ -56,7 +56,7 @@ class Scaffolding {
* the load->view function knows where to look.
*/
- $this->CI->load->view_path = BASEPATH.'scaffolding/views/';
+ $this->CI->load->_ci_view_path = BASEPATH.'scaffolding/views/';
// Set the base URL
$this->base_url = $this->CI->config->site_url().'/'.$this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'both');