PageRenderTime 26ms CodeModel.GetById 23ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

/system/libraries/Exceptions.php

https://bitbucket.org/ksokmesa/sina-asian
PHP | 174 lines | 73 code | 23 blank | 78 comment | 4 complexity | 5c8266cb045cc7a69b73b5270feb37bd MD5 | raw file
Possible License(s): GPL-3.0
  1<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2/**
  3 * CodeIgniter
  4 *
  5 * An open source application development framework for PHP 4.3.2 or newer
  6 *
  7 * @package		CodeIgniter
  8 * @author		ExpressionEngine Dev Team
  9 * @copyright	Copyright (c) 2008 - 2010, EllisLab, Inc.
 10 * @license		http://codeigniter.com/user_guide/license.html
 11 * @link		http://codeigniter.com
 12 * @since		Version 1.0
 13 * @filesource
 14 */
 15
 16// ------------------------------------------------------------------------
 17
 18/**
 19 * Exceptions Class
 20 *
 21 * @package		CodeIgniter
 22 * @subpackage	Libraries
 23 * @category	Exceptions
 24 * @author		ExpressionEngine Dev Team
 25 * @link		http://codeigniter.com/user_guide/libraries/exceptions.html
 26 */
 27class CI_Exceptions {
 28	var $action;
 29	var $severity;
 30	var $message;
 31	var $filename;
 32	var $line;
 33	var $ob_level;
 34
 35	var $levels = array(
 36						E_ERROR				=>	'Error',
 37						E_WARNING			=>	'Warning',
 38						E_PARSE				=>	'Parsing Error',
 39						E_NOTICE			=>	'Notice',
 40						E_CORE_ERROR		=>	'Core Error',
 41						E_CORE_WARNING		=>	'Core Warning',
 42						E_COMPILE_ERROR		=>	'Compile Error',
 43						E_COMPILE_WARNING	=>	'Compile Warning',
 44						E_USER_ERROR		=>	'User Error',
 45						E_USER_WARNING		=>	'User Warning',
 46						E_USER_NOTICE		=>	'User Notice',
 47						E_STRICT			=>	'Runtime Notice'
 48					);
 49
 50
 51	/**
 52	 * Constructor
 53	 *
 54	 */	
 55	function CI_Exceptions()
 56	{
 57		$this->ob_level = ob_get_level();
 58		// Note:  Do not log messages from this constructor.
 59	}
 60  	
 61	// --------------------------------------------------------------------
 62
 63	/**
 64	 * Exception Logger
 65	 *
 66	 * This function logs PHP generated error messages
 67	 *
 68	 * @access	private
 69	 * @param	string	the error severity
 70	 * @param	string	the error string
 71	 * @param	string	the error filepath
 72	 * @param	string	the error line number
 73	 * @return	string
 74	 */
 75	function log_exception($severity, $message, $filepath, $line)
 76	{	
 77		$severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
 78		
 79		log_message('error', 'Severity: '.$severity.'  --> '.$message. ' '.$filepath.' '.$line, TRUE);
 80	}
 81
 82	// --------------------------------------------------------------------
 83
 84	/**
 85	 * 404 Page Not Found Handler
 86	 *
 87	 * @access	private
 88	 * @param	string
 89	 * @return	string
 90	 */
 91	function show_404($page = '')
 92	{	
 93		$heading = "404 Page Not Found";
 94		$message = "The page you requested was not found.";
 95
 96		log_message('error', '404 Page Not Found --> '.$page);
 97		echo $this->show_error($heading, $message, 'error_404', 404);
 98		exit;
 99	}
100  	
101	// --------------------------------------------------------------------
102
103	/**
104	 * General Error Page
105	 *
106	 * This function takes an error message as input
107	 * (either as a string or an array) and displays
108	 * it using the specified template.
109	 *
110	 * @access	private
111	 * @param	string	the heading
112	 * @param	string	the message
113	 * @param	string	the template name
114	 * @return	string
115	 */
116	function show_error($heading, $message, $template = 'error_general', $status_code = 500)
117	{
118		set_status_header($status_code);
119		
120		$message = '<p>'.implode('</p><p>', ( ! is_array($message)) ? array($message) : $message).'</p>';
121
122		if (ob_get_level() > $this->ob_level + 1)
123		{
124			ob_end_flush();	
125		}
126		ob_start();
127		include(APPPATH.'errors/'.$template.EXT);
128		$buffer = ob_get_contents();
129		ob_end_clean();
130		return $buffer;
131	}
132
133	// --------------------------------------------------------------------
134
135	/**
136	 * Native PHP error handler
137	 *
138	 * @access	private
139	 * @param	string	the error severity
140	 * @param	string	the error string
141	 * @param	string	the error filepath
142	 * @param	string	the error line number
143	 * @return	string
144	 */
145	function show_php_error($severity, $message, $filepath, $line)
146	{	
147		$severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
148	
149		$filepath = str_replace("\\", "/", $filepath);
150		
151		// For safety reasons we do not show the full file path
152		if (FALSE !== strpos($filepath, '/'))
153		{
154			$x = explode('/', $filepath);
155			$filepath = $x[count($x)-2].'/'.end($x);
156		}
157		
158		if (ob_get_level() > $this->ob_level + 1)
159		{
160			ob_end_flush();	
161		}
162		ob_start();
163		include(APPPATH.'errors/error_php'.EXT);
164		$buffer = ob_get_contents();
165		ob_end_clean();
166		echo $buffer;
167	}
168
169
170}
171// END Exceptions Class
172
173/* End of file Exceptions.php */
174/* Location: ./system/libraries/Exceptions.php */