PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/system/core/Exceptions.php

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