diff options
Diffstat (limited to 'system')
-rw-r--r-- | system/database/DB_export.php | 2 | ||||
-rw-r--r-- | system/database/DB_utility.php | 2 | ||||
-rw-r--r-- | system/libraries/Calendar.php | 2 | ||||
-rw-r--r-- | system/libraries/Controller.php | 137 | ||||
-rw-r--r-- | system/libraries/Email.php | 2 | ||||
-rw-r--r-- | system/libraries/Encrypt.php | 2 | ||||
-rw-r--r-- | system/libraries/Image_lib.php | 2 | ||||
-rw-r--r-- | system/libraries/Loader.php | 23 | ||||
-rw-r--r-- | system/libraries/Pagination.php | 2 | ||||
-rw-r--r-- | system/libraries/Parser.php | 2 | ||||
-rw-r--r-- | system/libraries/Session.php | 2 | ||||
-rw-r--r-- | system/libraries/Unit_test.php | 2 | ||||
-rw-r--r-- | system/libraries/Upload.php | 2 | ||||
-rw-r--r-- | system/libraries/Validation.php | 2 | ||||
-rw-r--r-- | system/libraries/Xmlrpc.php | 26 | ||||
-rw-r--r-- | system/libraries/Xmlrpcs.php | 57 |
16 files changed, 144 insertions, 123 deletions
diff --git a/system/database/DB_export.php b/system/database/DB_export.php index 8194cb9b1..14e7af68b 100644 --- a/system/database/DB_export.php +++ b/system/database/DB_export.php @@ -18,7 +18,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->dbexport =& new CI_DB_export(); +$obj->init_class('CI_DB_export', 'dbexport'); // ------------------------------------------------------------------------ diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index e4ae0c5df..3b4b09d6e 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->dbutility =& new CI_DB_utility(); +$obj->init_class('CI_DB_utility', 'dbutility'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Calendar.php b/system/libraries/Calendar.php index a3c070390..bde98113a 100644 --- a/system/libraries/Calendar.php +++ b/system/libraries/Calendar.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->calendar =& new CI_Calendar(); +$obj->init_class('CI_Calendar'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Controller.php b/system/libraries/Controller.php index 97aa4b789..74b233ef3 100644 --- a/system/libraries/Controller.php +++ b/system/libraries/Controller.php @@ -32,6 +32,8 @@ 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 @@ -63,57 +65,117 @@ class Controller extends CI_Base { log_message('debug', "Controller Class Initialized"); } - // END Controller() // -------------------------------------------------------------------- /** * Initialization Handler * - * Looks for the existence of a handler method and calls it + * 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 + // use to instantiate 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 * @param string the item that is being loaded * @param mixed any additional parameters * @return void */ - function _ci_initialize($class, $params = FALSE) - { + function _ci_init_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; + + // Does THIS file (Controller.php) contain an initialization + // function that maps to the requested class? + $method = '_ci_init_'.$class; - - if ( ! method_exists($this, $method)) - { - $class = ucfirst($class); - if ( ! file_exists(APPPATH.'libraries/'.$class.EXT)) + if (method_exists($this, $method)) + { + if (is_null($params)) { - if ( ! file_exists(BASEPATH.'libraries/'.$class.EXT)) - { - log_message('error', "Unable to load the requested class: ".$class); - show_error("Unable to load the class: ".$class); - } - - include_once(BASEPATH.'libraries/'.$class.EXT); + $this->$method(); } else { - include_once(APPPATH.'libraries/'.$class.EXT); - } + $this->$method($params); + } + + // We're done... + return TRUE; } - else + + // 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) { - if ($params === FALSE) + for ($i = 1; $i < 3; $i++) { - $this->$method(); - } - else - { - $this->$method($params); + $path = ($i % 2) ? APPPATH : BASEPATH; + + if (file_exists($path.'libraries/'.$filename.EXT)) + { + include_once($path.'libraries/'.$filename.EXT); + return TRUE; + } } + } + + // 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); } - // END _ci_initialize() // -------------------------------------------------------------------- @@ -124,7 +186,7 @@ class Controller extends CI_Base { * @param string * @return array */ - function _ci_load_model($model, $name = '', $db_conn = FALSE) + function _ci_init_model($model, $name = '', $db_conn = FALSE) { if ($name == '') { @@ -168,9 +230,7 @@ class Controller extends CI_Base { $this->$name = new $model(); $this->_ci_models[] = $name; $this->_ci_assign_to_models(); - } - // END _ci_load_model() - + } // -------------------------------------------------------------------- @@ -195,9 +255,7 @@ class Controller extends CI_Base { { $obj->$model->_assign_libraries(); } - } - // END _ci_assign_to_models() - + } // -------------------------------------------------------------------- @@ -245,13 +303,12 @@ class Controller extends CI_Base { foreach ($autoload['libraries'] as $item) { - $this->_ci_initialize($item); + $this->_ci_init_class($item); } unset($autoload['libraries']); return $autoload; } - // END _ci_autoload() // -------------------------------------------------------------------- @@ -282,7 +339,6 @@ class Controller extends CI_Base { $this->load = new CI_Loader(); } } - // END _ci_assign_core() // -------------------------------------------------------------------- @@ -311,7 +367,6 @@ class Controller extends CI_Base { $this->_ci_scaffolding = TRUE; $this->_ci_scaff_table = $table; } - // END _ci_init_scaffolding() // -------------------------------------------------------------------- @@ -324,7 +379,7 @@ class Controller extends CI_Base { * @return void */ function _ci_init_database($params = '', $return = FALSE, $active_record = FALSE) - { + { if ($this->_ci_is_loaded('db') == TRUE AND $return == FALSE AND $active_record == FALSE) { return; @@ -394,7 +449,6 @@ class Controller extends CI_Base { $obj =& get_instance(); $obj->db =& $DB; } - // END _ci_init_database() // -------------------------------------------------------------------- @@ -409,7 +463,6 @@ class Controller extends CI_Base { { return ( ! isset($this->$class) OR ! is_object($this->$class)) ? FALSE : TRUE; } - // END _ci_is_loaded() // -------------------------------------------------------------------- @@ -440,13 +493,11 @@ class Controller extends CI_Base { } $this->_ci_init_database("", FALSE, TRUE); - - $this->_ci_initialize('pagination'); + $this->_ci_init_class('pagination'); require_once(BASEPATH.'scaffolding/Scaffolding'.EXT); $this->scaff = new Scaffolding($this->_ci_scaff_table); $this->scaff->$method(); } - // END _ci_scaffolding() } // END _Controller class diff --git a/system/libraries/Email.php b/system/libraries/Email.php index c153043d9..c9b9365ec 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->email =& new CI_Email(); +$obj->init_class('CI_Email'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 446f64aa6..6a3ca17b0 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->encrypt =& new CI_Encrypt(); +$obj->init_class('CI_Encrypt'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 86ed05943..4962760eb 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -22,7 +22,7 @@ if (file_exists(APPPATH.'config/image_lib'.EXT)) } $obj =& get_instance(); -$obj->image_lib =& new CI_Image_lib($config); +$obj->init_class('CI_Image_lib', '', $config); // ------------------------------------------------------------------------ diff --git a/system/libraries/Loader.php b/system/libraries/Loader.php index 7449fa34a..df067cbc1 100644 --- a/system/libraries/Loader.php +++ b/system/libraries/Loader.php @@ -66,13 +66,13 @@ class CI_Loader { * @param mixed any initialization parameters * @return void */ - function library($class, $param = FALSE) + function library($class, $param = NULL) { if ($class == '') return; $obj =& get_instance(); - $obj->_ci_initialize($class, $param); + $obj->_ci_init_class($class, $param); $obj->_ci_assign_to_models(); } // END library() @@ -95,7 +95,7 @@ class CI_Loader { return; $obj =& get_instance(); - $obj->_ci_load_model($model, $name, $db_conn); + $obj->_ci_init_model($model, $name, $db_conn); } // END library() @@ -125,23 +125,6 @@ class CI_Loader { } } // END database() - - // -------------------------------------------------------------------- - - /** - * Database Utilities Loader - * - * @access public - * @param string the DB platform - * @param bool whether to return the DB object - * @return object - */ - function dbutil() - { - $obj =& get_instance(); - return $obj->_ci_init_dbutil($db, $return); - } - // END dbutils() // -------------------------------------------------------------------- diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index d83a2bd0f..cd55d56e0 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -22,7 +22,7 @@ if (file_exists(APPPATH.'config/pagination'.EXT)) } $obj =& get_instance(); -$obj->pagination =& new CI_Pagination($config); +$obj->init_class('CI_Pagination', '', $config); // ------------------------------------------------------------------------ diff --git a/system/libraries/Parser.php b/system/libraries/Parser.php index 5bc2eb5a3..76182271f 100644 --- a/system/libraries/Parser.php +++ b/system/libraries/Parser.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->parser =& new CI_Parser(); +$obj->init_class('CI_Parser'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Session.php b/system/libraries/Session.php index bcd2e4d7e..76acbfea9 100644 --- a/system/libraries/Session.php +++ b/system/libraries/Session.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->session =& new CI_Session(); +$obj->init_class('CI_Session'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 19fac79a7..04c3c199b 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->unit =& new CI_Unit_test(); +$obj->init_class('CI_Unit_test'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Upload.php b/system/libraries/Upload.php index 26f216544..3a6a6fc34 100644 --- a/system/libraries/Upload.php +++ b/system/libraries/Upload.php @@ -22,7 +22,7 @@ if (file_exists(APPPATH.'config/upload'.EXT)) } $obj =& get_instance(); -$obj->upload = new CI_Upload($config); +$obj->init_class('CI_Upload', '', $config); // ------------------------------------------------------------------------ diff --git a/system/libraries/Validation.php b/system/libraries/Validation.php index 6c755a991..34cacd5d8 100644 --- a/system/libraries/Validation.php +++ b/system/libraries/Validation.php @@ -16,7 +16,7 @@ // INITIALIZE THE CLASS --------------------------------------------------- $obj =& get_instance(); -$obj->validation =& new CI_Validation(); +$obj->init_class('CI_Validation'); // ------------------------------------------------------------------------ diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index b470f720a..24f79f2ba 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author Rick Ellis, Paul Burdick * @copyright Copyright (c) 2006, pMachine, Inc. * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com @@ -20,14 +20,8 @@ if ( ! function_exists('xml_parser_create')) // INITIALIZE THE CLASS --------------------------------------------------- -$config = array(); -if (file_exists(APPPATH.'config/xmlrpc'.EXT)) -{ - include_once(APPPATH.'config/xmlrpc'.EXT); -} - $obj =& get_instance(); -$obj->xmlrpc = new CI_XML_RPC($config); +$obj->init_class('CI_Xmlrpc'); // ------------------------------------------------------------------------ @@ -40,7 +34,7 @@ $obj->xmlrpc = new CI_XML_RPC($config); * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html */ -class CI_XML_RPC { +class CI_Xmlrpc { var $debug = FALSE; // Debugging on or off var $xmlrpcI4 = 'i4'; @@ -78,7 +72,7 @@ class CI_XML_RPC { // VALUES THAT MULTIPLE CLASSES NEED //------------------------------------- - function CI_XML_RPC ($config = array()) + function CI_Xmlrpc ($config = array()) { $this->xmlrpcName = $this->xmlrpcName; @@ -351,7 +345,7 @@ class CI_XML_RPC { * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html */ -class XML_RPC_Client extends CI_XML_RPC +class XML_RPC_Client extends CI_Xmlrpc { var $path = ''; var $server = ''; @@ -363,7 +357,7 @@ class XML_RPC_Client extends CI_XML_RPC function XML_RPC_Client($path, $server, $port=80) { - parent::CI_XML_RPC(); + parent::CI_Xmlrpc(); $this->port = $port; $this->server = $server; @@ -609,7 +603,7 @@ class XML_RPC_Response * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html */ -class XML_RPC_Message extends CI_XML_RPC +class XML_RPC_Message extends CI_Xmlrpc { var $payload; var $method_name; @@ -618,7 +612,7 @@ class XML_RPC_Message extends CI_XML_RPC function XML_RPC_Message($method, $pars=0) { - parent::CI_XML_RPC(); + parent::CI_Xmlrpc(); $this->method_name = $method; if (is_array($pars) && sizeof($pars) > 0) @@ -1206,14 +1200,14 @@ class XML_RPC_Message extends CI_XML_RPC * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html */ -class XML_RPC_Values extends CI_XML_RPC +class XML_RPC_Values extends CI_Xmlrpc { var $me = array(); var $mytype = 0; function XML_RPC_Values($val=-1, $type='') { - parent::CI_XML_RPC(); + parent::CI_Xmlrpc(); if ($val != -1 || $type != '') { diff --git a/system/libraries/Xmlrpcs.php b/system/libraries/Xmlrpcs.php index 4d50dfb96..a95764a98 100644 --- a/system/libraries/Xmlrpcs.php +++ b/system/libraries/Xmlrpcs.php @@ -5,7 +5,7 @@ * An open source application development framework for PHP 4.3.2 or newer * * @package CodeIgniter - * @author Rick Ellis + * @author Rick Ellis, Paul Burdick * @copyright Copyright (c) 2006, pMachine, Inc. * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com @@ -13,36 +13,18 @@ * @filesource */ +if ( ! function_exists('xml_parser_create')) +{ + show_error('Your PHP installation does not support XML'); +} + // INITIALIZE THE CLASS --------------------------------------------------- -$config = array(); -if (file_exists(APPPATH.'config/xmlrpcs'.EXT)) -{ - include_once(APPPATH.'config/xmlrpcs'.EXT); -} +require_once(BASEPATH.'libraries/Xmlrpc'.EXT); -if ( ! class_exists('CI_XML_RPC')) -{ - if ( ! file_exists(BASEPATH.'libraries/Xmlrpc'.EXT)) - { - if ( ! file_exists(APPPATH.'libraries/Xmlrpc'.EXT)) - { - show_error('Unable to locate the Xmlrpc class'); - } - else - { - require_once(APPPATH.'libraries/Xmlrpc'.EXT); - } - } - else - { - require_once(BASEPATH.'libraries/Xmlrpc'.EXT); - } -} - -$obj =& get_instance(); -$obj->xmlrpcs = new CI_XML_RPC_Server($config); +// The initialization code is at the bottom of this file. It seems to +// cause an error to have it at the top // ------------------------------------------------------------------------ @@ -55,7 +37,7 @@ $obj->xmlrpcs = new CI_XML_RPC_Server($config); * @author Paul Burdick * @link http://www.codeigniter.com/user_guide/libraries/xmlrpc.html */ -class CI_XML_RPC_Server extends CI_XML_RPC +class CI_Xmlrpcs extends CI_Xmlrpc { var $methods = array(); //array of methods mapped to function names and signatures var $debug_msg = ''; // Debug Message @@ -67,9 +49,9 @@ class CI_XML_RPC_Server extends CI_XML_RPC // Constructor, more or less //------------------------------------- - function CI_XML_RPC_Server($config=array()) + function CI_Xmlrpcs($config=array()) { - parent::CI_XML_RPC(); + parent::CI_Xmlrpc(); $this->set_system_methods(); if (isset($config['functions']) && is_array($config['functions'])) @@ -235,7 +217,7 @@ class CI_XML_RPC_Server extends CI_XML_RPC echo "</pre>"; } - $r = $this->execute($m); + $r = $this->_execute($m); } //------------------------------------- @@ -508,7 +490,7 @@ class CI_XML_RPC_Server extends CI_XML_RPC $msg->params[] = $params->me['array'][$i]; } - $result = $this->execute($msg); + $result = $this->_execute($msg); if ($result->faultCode() != 0) { @@ -520,4 +502,15 @@ class CI_XML_RPC_Server extends CI_XML_RPC } // END XML_RPC_Server class + + +// INITIALIZE THE CLASS --------------------------------------------------- + +$obj =& get_instance(); +$obj->init_class('CI_Xmlrpc'); +$obj->init_class('CI_Xmlrpcs'); + +// ------------------------------------------------------------------------ + + ?>
\ No newline at end of file |