diff options
author | admin <devnull@localhost> | 2006-09-28 08:50:16 +0200 |
---|---|---|
committer | admin <devnull@localhost> | 2006-09-28 08:50:16 +0200 |
commit | 33de9a144aad28763405f8ae2d5c59df5e929b4f (patch) | |
tree | e774e7aa9eb99b40979cf2b678aea333dc2de3a5 /system/libraries | |
parent | 2296fc3ca61b689a2a486d1d39346424c069dc25 (diff) |
Diffstat (limited to 'system/libraries')
-rw-r--r-- | system/libraries/Benchmark.php | 9 | ||||
-rw-r--r-- | system/libraries/Calendar.php | 5 | ||||
-rw-r--r-- | system/libraries/Controller.php | 165 | ||||
-rw-r--r-- | system/libraries/Email.php | 11 | ||||
-rw-r--r-- | system/libraries/Encrypt.php | 5 | ||||
-rw-r--r-- | system/libraries/Hooks.php | 2 | ||||
-rw-r--r-- | system/libraries/Image_lib.php | 11 | ||||
-rw-r--r-- | system/libraries/Input.php | 2 | ||||
-rw-r--r-- | system/libraries/Loader.php | 2 | ||||
-rw-r--r-- | system/libraries/Output.php | 4 | ||||
-rw-r--r-- | system/libraries/Pagination.php | 11 | ||||
-rw-r--r-- | system/libraries/Parser.php | 5 | ||||
-rw-r--r-- | system/libraries/Router.php | 21 | ||||
-rw-r--r-- | system/libraries/Session.php | 5 | ||||
-rw-r--r-- | system/libraries/Trackback.php | 5 | ||||
-rw-r--r-- | system/libraries/URI.php | 2 | ||||
-rw-r--r-- | system/libraries/Unit_test.php | 5 | ||||
-rw-r--r-- | system/libraries/Upload.php | 11 | ||||
-rw-r--r-- | system/libraries/Validation.php | 5 | ||||
-rw-r--r-- | system/libraries/Xmlrpc.php | 4 | ||||
-rw-r--r-- | system/libraries/Xmlrpcs.php | 5 |
21 files changed, 109 insertions, 186 deletions
diff --git a/system/libraries/Benchmark.php b/system/libraries/Benchmark.php index 9dd9d4ac4..d8dd903e7 100644 --- a/system/libraries/Benchmark.php +++ b/system/libraries/Benchmark.php @@ -31,15 +31,6 @@ class CI_Benchmark { var $marker = array(); - /** - * Constructor - * - * @access public - */ - function CI_Benchmark() - { - } - // END CI_Benchmark() // -------------------------------------------------------------------- diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index bde98113a..8c7d95aa5 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -13,11 +13,6 @@ * @filesource */ -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Calendar'); - // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 56b4d6f90..aa7b87b00 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -32,8 +32,6 @@ class Controller extends CI_Base { var $_ci_models = array(); var $_ci_scaffolding = FALSE; var $_ci_scaff_table = FALSE; - var $_ci_last_handle = NULL; - var $_ci_last_params = NULL; /** * Constructor @@ -71,48 +69,6 @@ class Controller extends CI_Base { /** * Initialization Handler * - * Designed to be called from the class files themselves. - * See: http://www.codeigniter.com/user_guide/general/creating_libraries.html - * - * @access public - * @param string class name - * @param string variable name - * @param mixed any additional parameters - * @return void - */ - function init_class($class, $varname = '', $params = NULL) - { - // First figure out what variable we're going to assign the class to - if ($varname == '') - { - $varname = ( ! is_null($this->_ci_last_handle)) ? $this->_ci_last_handle : strtolower(str_replace('CI_', '', $class)); - } - - // Are there any parameters? - if ($params === NULL AND $this->_ci_last_params !== NULL) - { - $params = $this->_ci_last_params; - } - - // Instantiate the class - if ( ! is_null($params)) - { - $this->$varname = new $class($params); - } - else - { - $this->$varname = new $class; - } - - $this->_ci_last_params = NULL; - $this->_ci_last_handle = NULL; - } - - // -------------------------------------------------------------------- - - /** - * Initialization Handler - * * This function loads the requested class. * * @access private @@ -120,15 +76,21 @@ class Controller extends CI_Base { * @param mixed any additional parameters * @return void */ - function _ci_init_class($class, $params = NULL) + function _ci_load_class($class, $params = NULL) { // Prep the class name $class = strtolower(str_replace(EXT, '', $class)); - - // These are used by $this->init_class() above. - // They lets us dynamically set the object name and pass parameters - $this->_ci_last_handle = $class; - $this->_ci_last_params = $params; + + // Is this a class extension request? + if (substr($class, 0, 3) == 'my_') + { + $class = preg_replace("/my_(.+)/", "\\1", $class); + $extend = TRUE; + } + else + { + $extend = FALSE; + } // Does THIS file (Controller.php) contain an initialization // function that maps to the requested class? @@ -150,30 +112,101 @@ class Controller extends CI_Base { return TRUE; } - // Lets search for the requested library file and load it. - // We'll assume that the file we load contains a call to - // $obj->init_class() so that the class can get instantiated. - // For backward compatibility we'll test for filenames that are - // both uppercase and lower. - foreach (array(ucfirst($class), $class) as $filename) + // Are we extending one of the base classes? + if ($extend == TRUE) { - for ($i = 1; $i < 3; $i++) + // Load the requested library from the main system/libraries folder + if (file_exists(BASEPATH.'libraries/'.ucfirst($class).EXT)) { - $path = ($i % 2) ? APPPATH : BASEPATH; + include_once(BASEPATH.'libraries/'.ucfirst($class).EXT); + } - if (file_exists($path.'libraries/'.$filename.EXT)) + // Now look for a matching library + foreach (array(ucfirst($class), $class) as $filename) + { + if (file_exists(APPPATH.'libraries/'.$filename.EXT)) { - include_once($path.'libraries/'.$filename.EXT); - return TRUE; + include_once(APPPATH.'libraries/'.$filename.EXT); + } + } + + return $this->_ci_init_class($filename, 'MY_', $params); + } + else + { + // Lets search for the requested library file and load it. + // For backward compatibility we'll test for filenames that are + // both uppercase and lower. + foreach (array(ucfirst($class), $class) as $filename) + { + for ($i = 1; $i < 3; $i++) + { + $path = ($i % 2) ? APPPATH : BASEPATH; + + if (file_exists($path.'libraries/'.$filename.EXT)) + { + include_once($path.'libraries/'.$filename.EXT); + return $this->_ci_init_class($filename, '', $params); + } } } - } // If we got this far we were unable to find the requested class log_message('error', "Unable to load the requested class: ".$class); show_error("Unable to load the class: ".$class); } + + // -------------------------------------------------------------------- + + /** + * Instantiates a class + * + * @access private + * @param string + * @param string + * @return null + */ + function _ci_init_class($class, $prefix = '', $config = NULL) + { + // Is there an associated config file for this class? + + if ($config == NULL) + { + if (file_exists(APPPATH.'config/'.$class.EXT)) + { + include_once(APPPATH.'config/'.$class.EXT); + } + } + + if ($prefix == '') + { + $name = ( ! class_exists($class)) ? 'CI_'.$class : $class; + } + else + { + $name = $prefix.ucfirst($class); + } + + $remap = array( + 'DB_export' => 'dbexport', + 'DB_utility' => 'dbutility', + 'Encryption' => 'encrypt', + 'Unit_test' => 'unit' + ); + + $varname = ( ! isset($remap[$class])) ? $class : $remap[$class]; + + // Instantiate the class + if ($config !== NULL) + { + $this->$varname = new $name($config); + } + else + { + $this->$varname = new $name; + } + } // -------------------------------------------------------------------- @@ -305,7 +338,7 @@ class Controller extends CI_Base { { if ( ! in_array($item, $exceptions)) { - $this->_ci_init_class($item); + $this->_ci_load_class($item); } else { @@ -334,10 +367,10 @@ class Controller extends CI_Base { foreach (array('Config', 'Input', 'Benchmark', 'URI', 'Output') as $val) { $class = strtolower($val); - $this->$class =& _load_class('CI_'.$val); + $this->$class =& _load_class($val); } - $this->lang =& _load_class('CI_Language'); + $this->lang =& _load_class('Language'); // In PHP 4 the Controller class is a child of CI_Loader. // In PHP 5 we run it as its own class. @@ -529,7 +562,7 @@ class Controller extends CI_Base { } $this->_ci_init_database("", FALSE, TRUE); - $this->_ci_init_class('pagination'); + $this->_ci_load_class('pagination'); require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); $this->scaff = new Scaffolding($this->_ci_scaff_table); $this->scaff->$method(); diff --git a/system/libraries/Email.php b/system/libraries/Email.php index fd3fb8f17..5b991d1fa 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -13,17 +13,6 @@ * @filesource */ -// INITIALIZE THE CLASS --------------------------------------------------- - -$config = array(); -if (file_exists(APPPATH.'config/email'.EXT)) -{ - include_once(APPPATH.'config/email'.EXT); -} - -$obj =& get_instance(); -$obj->init_class('CI_Email', 'email', $config); - // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 6a3ca17b0..abc769460 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Encrypt'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Hooks.php b/system/libraries/Hooks.php index 7ff0592ff..69ca1a9f1 100644 --- a/system/libraries/Hooks.php +++ b/system/libraries/Hooks.php @@ -41,7 +41,7 @@ class CI_Hooks { { log_message('debug', "Hooks Class Initialized"); - $CFG =& _load_class('CI_Config'); + $CFG =& _load_class('Config'); // If hooks are not enabled in the config file // there is nothing else to do diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 4962760eb..18e3253f7 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -13,17 +13,6 @@ * @filesource */ -// INITIALIZE THE CLASS --------------------------------------------------- - -$config = array(); -if (file_exists(APPPATH.'config/image_lib'.EXT)) -{ - include_once(APPPATH.'config/image_lib'.EXT); -} - -$obj =& get_instance(); -$obj->init_class('CI_Image_lib', '', $config); - // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Input.php b/system/libraries/Input.php index dbf939b18..ad7b0c571 100644 --- a/system/libraries/Input.php +++ b/system/libraries/Input.php @@ -42,7 +42,7 @@ class CI_Input { */ function CI_Input() { - $CFG =& _load_class('CI_Config'); + $CFG =& _load_class('Config'); $this->use_xss_clean = ($CFG->item('global_xss_filtering') === TRUE) ? TRUE : FALSE; $this->allow_get_array = ($CFG->item('enable_query_strings') === TRUE) ? TRUE : FALSE; diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 90d824049..fff9e78d3 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -71,7 +71,7 @@ class CI_Loader { return; $obj =& get_instance(); - $obj->_ci_init_class($class, $param); + $obj->_ci_load_class($class, $param); $obj->_ci_assign_to_models(); } diff --git a/system/libraries/Output.php b/system/libraries/Output.php index 5a158245f..1c3f0d604 100644 --- a/system/libraries/Output.php +++ b/system/libraries/Output.php @@ -237,8 +237,8 @@ class CI_Output { */ function _display_cache(&$CFG, &$RTR) { - $CFG =& _load_class('CI_Config'); - $RTR =& _load_class('CI_Router'); + $CFG =& _load_class('Config'); + $RTR =& _load_class('Router'); $cache_path = ($CFG->item('cache_path') == '') ? BASEPATH.'cache/' : $CFG->item('cache_path'); diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index cd55d56e0..867d214fc 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -12,17 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$config = array(); -if (file_exists(APPPATH.'config/pagination'.EXT)) -{ - include_once(APPPATH.'config/pagination'.EXT); -} - -$obj =& get_instance(); -$obj->init_class('CI_Pagination', '', $config); // ------------------------------------------------------------------------ diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 76182271f..42e78b0ee 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Parser'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Router.php b/system/libraries/Router.php index 34a2512a6..c056530a3 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -33,6 +33,7 @@ class CI_Router { var $segments = array(); var $rsegments = array(); var $routes = array(); + var $error_routes = array(); var $class = ''; var $method = 'index'; var $directory = ''; @@ -47,7 +48,7 @@ class CI_Router { */ function CI_Router() { - $this->config =& _load_class('CI_Config'); + $this->config =& _load_class('Config'); $this->_set_route_mapping(); log_message('debug', "Router Class Initialized"); } @@ -87,8 +88,8 @@ class CI_Router { // Set the default controller so we can display it in the event // the URI doesn't correlated to a valid controller. - $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); - + $this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']); + // Fetch the complete URI string $this->uri_string = $this->_get_uri_string(); @@ -138,7 +139,6 @@ class CI_Router { // Re-index the segment array so that it starts with 1 rather than 0 $this->_reindex_segments(); } - // END _set_route_mapping() // -------------------------------------------------------------------- @@ -185,7 +185,6 @@ class CI_Router { // identical to $this->segments $this->rsegments = $segments; } - // END _compile_segments() // -------------------------------------------------------------------- @@ -240,7 +239,6 @@ class CI_Router { // Can't find the requested controller... show_404(); } - // END _validate_segments() // -------------------------------------------------------------------- /** @@ -280,7 +278,6 @@ class CI_Router { unset($this->rsegments[0]); } } - // END _reindex_segments() // -------------------------------------------------------------------- @@ -333,7 +330,6 @@ class CI_Router { return getenv($uri); } } - // END _get_uri_string() // -------------------------------------------------------------------- @@ -381,7 +377,6 @@ class CI_Router { return $parsed_uri; } - // END _parse_request_uri() // -------------------------------------------------------------------- @@ -403,7 +398,6 @@ class CI_Router { } return $str; } - // END _filter_uri() // -------------------------------------------------------------------- @@ -461,7 +455,6 @@ class CI_Router { // matching route so we'll set the site default route $this->_compile_segments($this->segments); } - // END set_method() // -------------------------------------------------------------------- @@ -476,7 +469,6 @@ class CI_Router { { $this->class = $class; } - // END set_class() // -------------------------------------------------------------------- @@ -490,7 +482,6 @@ class CI_Router { { return $this->class; } - // END fetch_class() // -------------------------------------------------------------------- @@ -505,7 +496,6 @@ class CI_Router { { $this->method = $method; } - // END set_method() // -------------------------------------------------------------------- @@ -519,7 +509,6 @@ class CI_Router { { return $this->method; } - // END fetch_method() // -------------------------------------------------------------------- @@ -534,7 +523,6 @@ class CI_Router { { $this->directory = $dir.'/'; } - // END set_directory() // -------------------------------------------------------------------- @@ -548,7 +536,6 @@ class CI_Router { { return $this->directory; } - // END fetch_directory() } // END Router Class diff --git a/system/libraries/Session.php b/system/libraries/Session.php index 76acbfea9..28e469da7 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Session'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Trackback.php b/system/libraries/Trackback.php index 9b6138453..8b6cce16d 100644 --- a/system/libraries/Trackback.php +++ b/system/libraries/Trackback.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->trackback =& new CI_Trackback(); // ------------------------------------------------------------------------ diff --git a/system/libraries/URI.php b/system/libraries/URI.php index 89ca42e44..80b112660 100644 --- a/system/libraries/URI.php +++ b/system/libraries/URI.php @@ -42,7 +42,7 @@ class CI_URI { */ function CI_URI() { - $this->router =& _load_class('CI_Router'); + $this->router =& _load_class('Router'); log_message('debug', "URI Class Initialized"); } diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 04c3c199b..b2f4bf8cd 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -13,11 +13,6 @@ * @filesource */ -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Unit_test'); - // ------------------------------------------------------------------------ /** diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 3a6a6fc34..091c6c30d 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -12,17 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$config = array(); -if (file_exists(APPPATH.'config/upload'.EXT)) -{ - include_once(APPPATH.'config/upload'.EXT); -} - -$obj =& get_instance(); -$obj->init_class('CI_Upload', '', $config); // ------------------------------------------------------------------------ diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 34cacd5d8..80ee6a533 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -12,11 +12,6 @@ * @since Version 1.0 * @filesource */ - -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Validation'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index 24f79f2ba..f90785430 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -18,10 +18,6 @@ if ( ! function_exists('xml_parser_create')) show_error('Your PHP installation does not support XML'); } -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Xmlrpc'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index f41437342..b47104857 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -23,11 +23,6 @@ if ( ! class_exists('CI_Xmlrpc')) show_error('You must load the Xmlrpc class before loading the Xmlrpcs class in order to create a server.'); } -// INITIALIZE THE CLASS --------------------------------------------------- - -$obj =& get_instance(); -$obj->init_class('CI_Xmlrpcs'); - // ------------------------------------------------------------------------ /** |