/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

  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. * 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. */
  50. function CI_Exceptions()
  51. {
  52. $this->ob_level = ob_get_level();
  53. // Note: Do not log messages from this constructor.
  54. }
  55. // --------------------------------------------------------------------
  56. /**
  57. * Exception Logger
  58. *
  59. * This function logs PHP generated error messages
  60. *
  61. * @access private
  62. * @param string the error severity
  63. * @param string the error string
  64. * @param string the error filepath
  65. * @param string the error line number
  66. * @return string
  67. */
  68. function log_exception($severity, $message, $filepath, $line)
  69. {
  70. $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
  71. log_message('error', 'Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line, TRUE);
  72. }
  73. // --------------------------------------------------------------------
  74. /**
  75. * 404 Page Not Found Handler
  76. *
  77. * @access private
  78. * @param string
  79. * @return string
  80. */
  81. function show_404($page = '')
  82. {
  83. $heading = "404 Page Not Found";
  84. $message = "The page you requested was not found.";
  85. log_message('error', '404 Page Not Found --> '.$page);
  86. echo $this->show_error($heading, $message, 'error_404', 404);
  87. exit;
  88. }
  89. // --------------------------------------------------------------------
  90. /**
  91. * General Error Page
  92. *
  93. * This function takes an error message as input
  94. * (either as a string or an array) and displays
  95. * it using the specified template.
  96. *
  97. * @access private
  98. * @param string the heading
  99. * @param string the message
  100. * @param string the template name
  101. * @return string
  102. */
  103. function show_error($heading, $message, $template = 'error_general', $status_code = 500)
  104. {
  105. set_status_header($status_code);
  106. $message = '<p>'.implode('</p><p>', ( ! is_array($message)) ? array($message) : $message).'</p>';
  107. if (ob_get_level() > $this->ob_level + 1)
  108. {
  109. ob_end_flush();
  110. }
  111. ob_start();
  112. include(APPPATH.'errors/'.$template.EXT);
  113. $buffer = ob_get_contents();
  114. ob_end_clean();
  115. return $buffer;
  116. }
  117. // --------------------------------------------------------------------
  118. /**
  119. * Native PHP error handler
  120. *
  121. * @access private
  122. * @param string the error severity
  123. * @param string the error string
  124. * @param string the error filepath
  125. * @param string the error line number
  126. * @return string
  127. */
  128. function show_php_error($severity, $message, $filepath, $line)
  129. {
  130. $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
  131. $filepath = str_replace("\\", "/", $filepath);
  132. // For safety reasons we do not show the full file path
  133. if (FALSE !== strpos($filepath, '/'))
  134. {
  135. $x = explode('/', $filepath);
  136. $filepath = $x[count($x)-2].'/'.end($x);
  137. }
  138. if (ob_get_level() > $this->ob_level + 1)
  139. {
  140. ob_end_flush();
  141. }
  142. ob_start();
  143. include(APPPATH.'errors/error_php'.EXT);
  144. $buffer = ob_get_contents();
  145. ob_end_clean();
  146. echo $buffer;
  147. }
  148. }
  149. // END Exceptions Class
  150. /* End of file Exceptions.php */
  151. /* Location: ./system/libraries/Exceptions.php */