Go to the source code of this file.
Functions | |
| is_really_writable ($file) | |
| Tests for file writability. | |
| & | load_class ($class, $instantiate=TRUE) |
| Class registry. | |
| & | get_config () |
| Loads the main config.php file. | |
| config_item ($item) | |
| Gets a config item. | |
| show_error ($message) | |
| Error Handler. | |
| show_404 ($page= '') | |
| 404 Page Handler | |
| log_message ($level= 'error', $message, $php_error=FALSE) | |
| Error Logging Interface. | |
| _exception_handler ($severity, $message, $filepath, $line) | |
| Exception Handler. | |
| _exception_handler | ( | $ | severity, | |
| $ | message, | |||
| $ | filepath, | |||
| $ | line | |||
| ) |
Exception Handler.
This is the custom exception handler that is declaired at the top of Codeigniter.php. The main reason we use this is permit PHP errors to be logged in our own log files since we may not have access to server logs. Since this function effectively intercepts PHP errors, however, we also need to display errors based on the current error_reporting level. We do that with the use of a PHP error template.
private
Definition at line 262 of file Common.php.
References $config, get_config(), and load_class().
00263 { 00264 // We don't bother with "strict" notices since they will fill up 00265 // the log file with information that isn't normally very 00266 // helpful. For example, if you are running PHP 5 and you 00267 // use version 4 style class functions (without prefixes 00268 // like "public", "private", etc.) you'll get notices telling 00269 // you that these have been deprecated. 00270 00271 if ($severity == E_STRICT) 00272 { 00273 return; 00274 } 00275 00276 $error =& load_class('Exceptions'); 00277 00278 // Should we display the error? 00279 // We'll get the current error_reporting level and add its bits 00280 // with the severity bits to find out. 00281 00282 if (($severity & error_reporting()) == $severity) 00283 { 00284 $error->show_php_error($severity, $message, $filepath, $line); 00285 } 00286 00287 // Should we log the error? No? We're done... 00288 $config =& get_config(); 00289 if ($config['log_threshold'] == 0) 00290 { 00291 return; 00292 } 00293 00294 $error->log_exception($severity, $message, $filepath, $line); 00295 }

| config_item | ( | $ | item | ) |
Gets a config item.
public
Definition at line 168 of file Common.php.
References $config, and get_config().
Referenced by CI_Loader::_ci_load(), CI_Loader::_ci_load_class(), CI_Loader::helper(), and load_class().
00169 { 00170 static $config_item = array(); 00171 00172 if ( ! isset($config_item[$item])) 00173 { 00174 $config =& get_config(); 00175 00176 if ( ! isset($config[$item])) 00177 { 00178 return FALSE; 00179 } 00180 $config_item[$item] = $config[$item]; 00181 } 00182 00183 return $config_item[$item]; 00184 }


| & get_config | ( | ) |
Loads the main config.php file.
private
Definition at line 139 of file Common.php.
References $config.
Referenced by _exception_handler(), CI_Config::CI_Config(), CI_Log::CI_Log(), config_item(), and log_message().
00140 { 00141 static $main_conf; 00142 00143 if ( ! isset($main_conf)) 00144 { 00145 if ( ! file_exists(APPPATH.'config/config'.EXT)) 00146 { 00147 exit('The configuration file config'.EXT.' does not exist.'); 00148 } 00149 00150 require(APPPATH.'config/config'.EXT); 00151 00152 if ( ! isset($config) OR ! is_array($config)) 00153 { 00154 exit('Your config file does not appear to be formatted correctly.'); 00155 } 00156 00157 $main_conf[0] =& $config; 00158 } 00159 return $main_conf[0]; 00160 }

| is_really_writable | ( | $ | file | ) |
Tests for file writability.
is_writable() returns TRUE on Windows servers when you really can't write to the file as the OS reports to PHP as FALSE only if the read-only attribute is marked. Ugh?
private
Definition at line 43 of file Common.php.
Referenced by CI_Output::_display_cache(), CI_Output::_write_cache(), CI_DB_Cache::check_path(), CI_Log::CI_Log(), create_captcha(), and CI_Upload::validate_upload_path().
00044 { 00045 if (is_dir($file)) 00046 { 00047 $file = rtrim($file, '/').'/'.md5(rand(1,100)); 00048 00049 if (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE) 00050 { 00051 return FALSE; 00052 } 00053 00054 fclose($fp); 00055 @chmod($file, DIR_WRITE_MODE); 00056 @unlink($file); 00057 return TRUE; 00058 } 00059 elseif (($fp = @fopen($file, FOPEN_WRITE_CREATE)) === FALSE) 00060 { 00061 return FALSE; 00062 } 00063 00064 fclose($fp); 00065 return TRUE; 00066 }

| & load_class | ( | $ | class, | |
| $ | instantiate = TRUE | |||
| ) |
Class registry.
This function acts as a singleton. If the requested class does not exist it is instantiated and set to a static variable. If it has previously been instantiated the variable is returned.
public
| string | the class name being requested | |
| bool | optional flag that lets classes get loaded but not instantiated |
Definition at line 82 of file Common.php.
References $class, and config_item().
Referenced by Controller::_ci_initialize(), _exception_handler(), CI_Hooks::_initialize(), CI_Input::CI_Input(), CI_Router::CI_Router(), CI_URI::CI_URI(), CI_DB_driver::display_error(), log_message(), CI_Loader::model(), show_404(), and show_error().
00083 { 00084 static $objects = array(); 00085 00086 // Does the class exist? If so, we're done... 00087 if (isset($objects[$class])) 00088 { 00089 return $objects[$class]; 00090 } 00091 00092 // If the requested class does not exist in the application/libraries 00093 // folder we'll load the native class from the system/libraries folder. 00094 if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) 00095 { 00096 require(BASEPATH.'libraries/'.$class.EXT); 00097 require(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT); 00098 $is_subclass = TRUE; 00099 } 00100 else 00101 { 00102 if (file_exists(APPPATH.'libraries/'.$class.EXT)) 00103 { 00104 require(APPPATH.'libraries/'.$class.EXT); 00105 $is_subclass = FALSE; 00106 } 00107 else 00108 { 00109 require(BASEPATH.'libraries/'.$class.EXT); 00110 $is_subclass = FALSE; 00111 } 00112 } 00113 00114 if ($instantiate == FALSE) 00115 { 00116 $objects[$class] = TRUE; 00117 return $objects[$class]; 00118 } 00119 00120 if ($is_subclass == TRUE) 00121 { 00122 $name = config_item('subclass_prefix').$class; 00123 $objects[$class] =& new $name(); 00124 return $objects[$class]; 00125 } 00126 00127 $name = ($class != 'Controller') ? 'CI_'.$class : $class; 00128 00129 $objects[$class] =& new $name(); 00130 return $objects[$class]; 00131 }


| log_message | ( | $ | level = 'error', |
|
| $ | message, | |||
| $ | php_error = FALSE | |||
| ) |
Error Logging Interface.
We use this as a simple mechanism to access the logging class and send messages to be logged.
public
Definition at line 234 of file Common.php.
References $config, get_config(), and load_class().
Referenced by CI_Loader::_ci_load(), CI_Loader::_ci_load_class(), CI_Output::_display(), CI_Output::_display_cache(), CI_Input::_sanitize_globals(), CI_Router::_set_routing(), CI_Output::_write_cache(), CI_Calendar::CI_Calendar(), CI_Config::CI_Config(), CI_DB_driver::CI_DB_driver(), CI_DB_forge::CI_DB_forge(), CI_DB_utility::CI_DB_utility(), CI_Email::CI_Email(), CI_Encrypt::CI_Encrypt(), CI_FTP::CI_FTP(), CI_Hooks::CI_Hooks(), CI_Image_lib::CI_Image_lib(), CI_Input::CI_Input(), CI_Language::CI_Language(), CI_Loader::CI_Loader(), CI_Output::CI_Output(), CI_Pagination::CI_Pagination(), CI_Router::CI_Router(), CI_Session::CI_Session(), CI_SHA::CI_SHA(), CI_Table::CI_Table(), CI_Trackback::CI_Trackback(), CI_Unit_test::CI_Unit_test(), CI_Upload::CI_Upload(), CI_URI::CI_URI(), CI_User_agent::CI_User_agent(), CI_Validation::CI_Validation(), CI_Xmlrpc::CI_Xmlrpc(), CI_Xmlrpcs::CI_Xmlrpcs(), CI_Zip::CI_Zip(), Controller::Controller(), CI_DB_sqlite_driver::db_connect(), CI_DB_sqlite_driver::db_pconnect(), CI_Loader::helper(), CI_DB_driver::initialize(), CI_Language::load(), CI_Config::load(), CI_Exceptions::log_exception(), Model::Model(), CI_Loader::plugin(), CI_DB_driver::query(), Scaffolding::Scaffolding(), CI_Loader::script(), CI_Session::sess_gc(), CI_Session::sess_read(), CI_Session::sess_run(), CI_Upload::set_error(), CI_Trackback::set_error(), CI_Image_lib::set_error(), CI_Exceptions::show_404(), CI_DB_oci8_driver::stored_procedure(), CI_DB_driver::trans_complete(), and CI_Input::xss_clean().
00235 { 00236 static $LOG; 00237 00238 $config =& get_config(); 00239 if ($config['log_threshold'] == 0) 00240 { 00241 return; 00242 } 00243 00244 $LOG =& load_class('Log'); 00245 $LOG->write_log($level, $message, $php_error); 00246 }

| show_404 | ( | $ | page = '' |
) |
404 Page Handler
This function is similar to the show_error() function above However, instead of the standard error template it displays 404 errors.
public
Definition at line 217 of file Common.php.
References load_class().
Referenced by Controller::_ci_scaffolding(), and CI_Router::_validate_request().
00218 { 00219 $error =& load_class('Exceptions'); 00220 $error->show_404($page); 00221 exit; 00222 }


| show_error | ( | $ | message | ) |
Error Handler.
This function lets us invoke the exception class and display errors using the standard error template located in application/errors/errors.php This function will send the error page directly to the browser and exit.
public
Definition at line 199 of file Common.php.
References load_class().
Referenced by CI_Loader::_ci_load(), CI_Loader::_ci_load_class(), CI_FTP::_error(), CI_Router::_set_routing(), CI_DB_forge::add_column(), CI_DB_forge::add_field(), CI_DB_forge::add_key(), CI_Pagination::create_links(), CI_DB_forge::create_table(), CI_DB_utility::csv_from_result(), DB(), CI_DB_forge::drop_column(), CI_Encrypt::get_key(), CI_Loader::helper(), CI_Language::load(), CI_Config::load(), CI_Loader::model(), CI_DB_forge::modify_column(), CI_DB_utility::optimize_table(), CI_Loader::plugin(), CI_DB_forge::rename_table(), CI_Loader::scaffolding(), CI_Loader::script(), and CI_DB_utility::xml_from_result().
00200 { 00201 $error =& load_class('Exceptions'); 00202 echo $error->show_error('An Error Was Encountered', $message); 00203 exit; 00204 }

