Exceptions.php

Go to the documentation of this file.
00001 <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002 /**
00003  * CodeIgniter
00004  *
00005  * An open source application development framework for PHP 4.3.2 or newer
00006  *
00007  * @package             CodeIgniter
00008  * @author              ExpressionEngine Dev Team
00009  * @copyright   Copyright (c) 2006, EllisLab, Inc.
00010  * @license             http://codeigniter.com/user_guide/license.html
00011  * @link                http://codeigniter.com
00012  * @since               Version 1.0
00013  * @filesource
00014  */
00015 
00016 // ------------------------------------------------------------------------
00017 
00018 /**
00019  * Exceptions Class
00020  *
00021  * @package             CodeIgniter
00022  * @subpackage  Libraries
00023  * @category    Exceptions
00024  * @author              ExpressionEngine Dev Team
00025  * @link                http://codeigniter.com/user_guide/libraries/exceptions.html
00026  */
00027 class CI_Exceptions {
00028         var $action;
00029         var $severity;
00030         var $message;
00031         var $filename;
00032         var $line;
00033         var $ob_level;
00034 
00035         var $levels = array(
00036                                                 E_ERROR                         =>      'Error',
00037                                                 E_WARNING                       =>      'Warning',
00038                                                 E_PARSE                         =>      'Parsing Error',
00039                                                 E_NOTICE                        =>      'Notice',
00040                                                 E_CORE_ERROR            =>      'Core Error',
00041                                                 E_CORE_WARNING          =>      'Core Warning',
00042                                                 E_COMPILE_ERROR         =>      'Compile Error',
00043                                                 E_COMPILE_WARNING       =>      'Compile Warning',
00044                                                 E_USER_ERROR            =>      'User Error',
00045                                                 E_USER_WARNING          =>      'User Warning',
00046                                                 E_USER_NOTICE           =>      'User Notice',
00047                                                 E_STRICT                        =>      'Runtime Notice'
00048                                         );
00049 
00050 
00051         /**
00052          * Constructor
00053          *
00054          */     
00055         function CI_Exceptions()
00056         {
00057                 $this->ob_level = ob_get_level();
00058                 // Note:  Do not log messages from this constructor.
00059         }
00060         
00061         // --------------------------------------------------------------------
00062 
00063         /**
00064          * Exception Logger
00065          *
00066          * This function logs PHP generated error messages
00067          *
00068          * @access      private
00069          * @param       string  the error severity
00070          * @param       string  the error string
00071          * @param       string  the error filepath
00072          * @param       string  the error line number
00073          * @return      string
00074          */
00075         function log_exception($severity, $message, $filepath, $line)
00076         {       
00077                 $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
00078                 
00079                 log_message('error', 'Severity: '.$severity.'  --> '.$message. ' '.$filepath.' '.$line, TRUE);
00080         }
00081 
00082         // --------------------------------------------------------------------
00083 
00084         /**
00085          * 404 Page Not Found Handler
00086          *
00087          * @access      private
00088          * @param       string
00089          * @return      string
00090          */
00091         function show_404($page = '')
00092         {       
00093                 $heading = "404 Page Not Found";
00094                 $message = "The page you requested was not found.";
00095 
00096                 log_message('error', '404 Page Not Found --> '.$page);
00097                 echo $this->show_error($heading, $message, 'error_404');
00098                 exit;
00099         }
00100         
00101         // --------------------------------------------------------------------
00102 
00103         /**
00104          * General Error Page
00105          *
00106          * This function takes an error message as input
00107          * (either as a string or an array) and displays
00108          * it using the specified template.
00109          *
00110          * @access      private
00111          * @param       string  the heading
00112          * @param       string  the message
00113          * @param       string  the template name
00114          * @return      string
00115          */
00116         function show_error($heading, $message, $template = 'error_general')
00117         {
00118                 $message = '<p>'.implode('</p><p>', ( ! is_array($message)) ? array($message) : $message).'</p>';
00119 
00120                 if (ob_get_level() > $this->ob_level + 1)
00121                 {
00122                         ob_end_flush(); 
00123                 }
00124                 ob_start();
00125                 include(APPPATH.'errors/'.$template.EXT);
00126                 $buffer = ob_get_contents();
00127                 ob_end_clean();
00128                 return $buffer;
00129         }
00130 
00131         // --------------------------------------------------------------------
00132 
00133         /**
00134          * Native PHP error handler
00135          *
00136          * @access      private
00137          * @param       string  the error severity
00138          * @param       string  the error string
00139          * @param       string  the error filepath
00140          * @param       string  the error line number
00141          * @return      string
00142          */
00143         function show_php_error($severity, $message, $filepath, $line)
00144         {       
00145                 $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
00146         
00147                 $filepath = str_replace("\\", "/", $filepath);
00148                 
00149                 // For safety reasons we do not show the full file path
00150                 if (FALSE !== strpos($filepath, '/'))
00151                 {
00152                         $x = explode('/', $filepath);
00153                         $filepath = $x[count($x)-2].'/'.end($x);
00154                 }
00155                 
00156                 if (ob_get_level() > $this->ob_level + 1)
00157                 {
00158                         ob_end_flush(); 
00159                 }
00160                 ob_start();
00161                 include(APPPATH.'errors/error_php'.EXT);
00162                 $buffer = ob_get_contents();
00163                 ob_end_clean();
00164                 echo $buffer;
00165         }
00166 
00167 
00168 }
00169 // END Exceptions Class
00170 
00171 /* End of file Exceptions.php */
00172 /* Location: ./system/libraries/Exceptions.php */