PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/system/core/Exceptions.php

https://bitbucket.org/sarahman/my-tiny-todo-list
PHP | 178 lines | 76 code | 24 blank | 78 comment | 5 complexity | bd474068af0a0aeaf7e1d4c5fa60950e 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. var $ob_level;
  32. var $levels = array(
  33. E_ERROR => 'Error',
  34. E_WARNING => 'Warning',
  35. E_PARSE => 'Parsing Error',
  36. E_NOTICE => 'Notice',
  37. E_CORE_ERROR => 'Core Error',
  38. E_CORE_WARNING => 'Core Warning',
  39. E_COMPILE_ERROR => 'Compile Error',
  40. E_COMPILE_WARNING => 'Compile Warning',
  41. E_USER_ERROR => 'User Error',
  42. E_USER_WARNING => 'User Warning',
  43. E_USER_NOTICE => 'User Notice',
  44. E_STRICT => 'Runtime Notice'
  45. );
  46. /**
  47. * Constructor
  48. */
  49. public function __construct()
  50. {
  51. $this->ob_level = ob_get_level();
  52. // Note: Do not log messages from this constructor.
  53. }
  54. // --------------------------------------------------------------------
  55. /**
  56. * Exception Logger
  57. *
  58. * This function logs PHP generated error messages
  59. *
  60. * @access private
  61. * @param string the error severity
  62. * @param string the error string
  63. * @param string the error filepath
  64. * @param string the error line number
  65. * @return string
  66. */
  67. function log_exception($severity, $message, $filepath, $line)
  68. {
  69. $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
  70. log_message('error', 'Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE);
  71. }
  72. // --------------------------------------------------------------------
  73. /**
  74. * 404 Page Not Found Handler
  75. *
  76. * @access private
  77. * @param string
  78. * @return string
  79. */
  80. function show_404($page = '', $log_error = TRUE)
  81. {
  82. $heading = "404 Page Not Found";
  83. $message = "The page you requested was not found.";
  84. // By default we log this, but allow a dev to skip it
  85. if ($log_error)
  86. {
  87. log_message('error', '404 Page Not Found --> '.$page);
  88. }
  89. echo $this->show_error($heading, $message, 'error_404', 404);
  90. exit;
  91. }
  92. // --------------------------------------------------------------------
  93. /**
  94. * General Error Page
  95. *
  96. * This function takes an error message as input
  97. * (either as a string or an array) and displays
  98. * it using the specified template.
  99. *
  100. * @access private
  101. * @param string the heading
  102. * @param string the message
  103. * @param string the template name
  104. * @return string
  105. */
  106. function show_error($heading, $message, $template = 'error_general', $status_code = 500)
  107. {
  108. set_status_header($status_code);
  109. $message = '<p>'.implode('</p><p>', ( ! is_array($message)) ? array($message) : $message).'</p>';
  110. if (ob_get_level() > $this->ob_level + 1)
  111. {
  112. ob_end_flush();
  113. }
  114. ob_start();
  115. include(APPPATH.'errors/'.$template.EXT);
  116. $buffer = ob_get_contents();
  117. ob_end_clean();
  118. return $buffer;
  119. }
  120. // --------------------------------------------------------------------
  121. /**
  122. * Native PHP error handler
  123. *
  124. * @access private
  125. * @param string the error severity
  126. * @param string the error string
  127. * @param string the error filepath
  128. * @param string the error line number
  129. * @return string
  130. */
  131. function show_php_error($severity, $message, $filepath, $line)
  132. {
  133. $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
  134. $filepath = str_replace("\\", "/", $filepath);
  135. // For safety reasons we do not show the full file path
  136. if (FALSE !== strpos($filepath, '/'))
  137. {
  138. $x = explode('/', $filepath);
  139. $filepath = $x[count($x)-2].'/'.end($x);
  140. }
  141. if (ob_get_level() > $this->ob_level + 1)
  142. {
  143. ob_end_flush();
  144. }
  145. ob_start();
  146. include(APPPATH.'errors/error_php'.EXT);
  147. $buffer = ob_get_contents();
  148. ob_end_clean();
  149. echo $buffer;
  150. }
  151. }
  152. // END Exceptions Class
  153. /* End of file Exceptions.php */
  154. /* Location: ./system/core/Exceptions.php */