summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2014-02-24 10:31:36 +0100
committerAndrey Andreev <narf@devilix.net>2014-02-24 10:31:36 +0100
commitc26b9ebb00e29be2e972fece3bcf73d33249a64b (patch)
treeb10dac6db61cc657bf5c906a8495994f935c102f /system
parent82179bf31f00564282f2a4d9873c6107b6732631 (diff)
Don't use globals
- Use load_class() to get objects during bootstrap process. - Change load_class() to accept a class constructor parameter instead of previously unused class name prefix. - Change CI_Router::__construct() to accept as a parameter.
Diffstat (limited to 'system')
-rw-r--r--system/core/CodeIgniter.php5
-rw-r--r--system/core/Common.php11
-rw-r--r--system/core/Input.php6
-rw-r--r--system/core/Output.php5
-rw-r--r--system/core/Router.php6
-rw-r--r--system/core/URI.php4
6 files changed, 16 insertions, 21 deletions
diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php
index 6d6747106..df5fa3b02 100644
--- a/system/core/CodeIgniter.php
+++ b/system/core/CodeIgniter.php
@@ -212,7 +212,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
* Instantiate the routing class and set the routing
* ------------------------------------------------------
*/
- $RTR =& load_class('Router', 'core');
+ $RTR =& load_class('Router', 'core', isset($routing) ? $routing : NULL);
/*
* ------------------------------------------------------
@@ -226,8 +226,7 @@ defined('BASEPATH') OR exit('No direct script access allowed');
* Is there a valid cache file? If so, we're done...
* ------------------------------------------------------
*/
- if ($EXT->call_hook('cache_override') === FALSE
- && $OUT->_display_cache($CFG, $URI) === TRUE)
+ if ($EXT->call_hook('cache_override') === FALSE && $OUT->_display_cache($CFG, $URI) === TRUE)
{
exit;
}
diff --git a/system/core/Common.php b/system/core/Common.php
index 0ea53c4e2..24315a054 100644
--- a/system/core/Common.php
+++ b/system/core/Common.php
@@ -130,7 +130,7 @@ if ( ! function_exists('load_class'))
* @param string the class name prefix
* @return object
*/
- function &load_class($class, $directory = 'libraries', $prefix = 'CI_')
+ function &load_class($class, $directory = 'libraries', $param = NULL)
{
static $_classes = array();
@@ -148,7 +148,7 @@ if ( ! function_exists('load_class'))
{
if (file_exists($path.$directory.'/'.$class.'.php'))
{
- $name = $prefix.$class;
+ $name = 'CI_'.$class;
if (class_exists($name, FALSE) === FALSE)
{
@@ -166,7 +166,7 @@ if ( ! function_exists('load_class'))
if (class_exists($name, FALSE) === FALSE)
{
- require_once(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php');
+ require_once(APPPATH.$directory.'/'.$name.'.php');
}
}
@@ -183,8 +183,9 @@ if ( ! function_exists('load_class'))
// Keep track of what we just loaded
is_loaded($class);
- $_classes[$class] = new $name();
- return $_classes[$class];
+ return $_classes[$class] = isset($param)
+ ? new $name($param)
+ : new $name();
}
}
diff --git a/system/core/Input.php b/system/core/Input.php
index fdb308b5a..620e50f63 100644
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -126,14 +126,12 @@ class CI_Input {
$this->_enable_csrf = (config_item('csrf_protection') === TRUE);
$this->_sandardize_newlines = (bool) config_item('standardize_newlines');
- global $SEC;
- $this->security =& $SEC;
+ $this->security =& load_class('Security', 'core');
// Do we need the UTF-8 class?
if (UTF8_ENABLED === TRUE)
{
- global $UNI;
- $this->uni =& $UNI;
+ $this->uni =& load_class('Utf8', 'core');
}
// Sanitize global arrays
diff --git a/system/core/Output.php b/system/core/Output.php
index e8c1c3972..2811a73bc 100644
--- a/system/core/Output.php
+++ b/system/core/Output.php
@@ -401,10 +401,11 @@ class CI_Output {
*/
public function _display($output = '')
{
- // Note: We use globals because we can't use $CI =& get_instance()
+ // Note: We use load_class() because we can't use $CI =& get_instance()
// since this function is sometimes called by the caching mechanism,
// which happens before the CI super object is available.
- global $BM, $CFG;
+ $BM =& load_class('Benchmark', 'core');
+ $CFG =& load_class('Config', 'core');
// Grab the super object if we can.
if (class_exists('CI_Controller', FALSE))
diff --git a/system/core/Router.php b/system/core/Router.php
index 05263b153..2448d9c8c 100644
--- a/system/core/Router.php
+++ b/system/core/Router.php
@@ -109,10 +109,8 @@ class CI_Router {
*
* @return void
*/
- public function __construct()
+ public function __construct($routing = NULL)
{
- global $routing;
-
$this->config =& load_class('Config', 'core');
$this->uri =& load_class('URI', 'core');
@@ -120,7 +118,7 @@ class CI_Router {
$this->_set_routing();
// Set any routing overrides that may exist in the main index file
- if (isset($routing) && is_array($routing))
+ if (is_array($routing))
{
if (isset($routing['directory']))
{
diff --git a/system/core/URI.php b/system/core/URI.php
index 5f5a9ce42..9a545fd3a 100644
--- a/system/core/URI.php
+++ b/system/core/URI.php
@@ -628,9 +628,7 @@ class CI_URI {
*/
public function ruri_string()
{
- global $RTR;
-
- return ltrim($RTR->directory, '/').implode('/', $this->rsegments);
+ return ltrim(load_class('Router', 'core')->directory, '/').implode('/', $this->rsegments);
}
}