PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/system/libraries/Exceptions.php

http://github.com/imagecms/ImageCMS
PHP | 172 lines | 72 code | 22 blank | 78 comment | 4 complexity | 0f73b01b152efbbdbe2665fca50a1923 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.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, 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');
  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')
  104. {
  105. $message = '<p>'.implode('</p><p>', ( ! is_array($message)) ? array($message) : $message).'</p>';
  106. if (ob_get_level() > $this->ob_level + 1)
  107. {
  108. ob_end_flush();
  109. }
  110. ob_start();
  111. include(APPPATH.'errors/'.$template.EXT);
  112. $buffer = ob_get_contents();
  113. ob_end_clean();
  114. return $buffer;
  115. }
  116. // --------------------------------------------------------------------
  117. /**
  118. * Native PHP error handler
  119. *
  120. * @access private
  121. * @param string the error severity
  122. * @param string the error string
  123. * @param string the error filepath
  124. * @param string the error line number
  125. * @return string
  126. */
  127. function show_php_error($severity, $message, $filepath, $line)
  128. {
  129. $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
  130. $filepath = str_replace("\\", "/", $filepath);
  131. // For safety reasons we do not show the full file path
  132. if (FALSE !== strpos($filepath, '/'))
  133. {
  134. $x = explode('/', $filepath);
  135. $filepath = $x[count($x)-2].'/'.end($x);
  136. }
  137. if (ob_get_level() > $this->ob_level + 1)
  138. {
  139. ob_end_flush();
  140. }
  141. ob_start();
  142. include(APPPATH.'errors/error_php'.EXT);
  143. $buffer = ob_get_contents();
  144. ob_end_clean();
  145. echo $buffer;
  146. }
  147. }
  148. // END Exceptions Class
  149. /* End of file Exceptions.php */
  150. /* Location: ./system/libraries/Exceptions.php */