reecriture des adresses dans le bon sens selon le pays
[platal.git] / htdocs / TESTS / simpletest / errors.php
1 <?php
2 /**
3 * base include file for SimpleTest
4 * @package SimpleTest
5 * @subpackage UnitTester
6 * @version $Id: errors.php,v 1.12 2004/08/08 13:16:00 lastcraft Exp $
7 */
8 /** @ignore - PHP5 compatibility fix. */
9 if (! defined('E_STRICT')) {
10 define('E_STRICT', 2048);
11 }
12
13 /**
14 * Singleton error queue used to record trapped
15 * errors.
16 * @package SimpleTest
17 * @subpackage UnitTester
18 */
19 class SimpleErrorQueue {
20 var $_queue;
21
22 /**
23 * Starts with an empty queue.
24 * @access public
25 */
26 function SimpleErrorQueue() {
27 $this->clear();
28 }
29
30 /**
31 * Adds an error to the front of the queue.
32 * @param $severity PHP error code.
33 * @param $message Text of error.
34 * @param $filename File error occoured in.
35 * @param $line Line number of error.
36 * @param $super_globals Hash of PHP super global arrays.
37 * @access public
38 */
39 function add($severity, $message, $filename, $line, $super_globals) {
40 array_push(
41 $this->_queue,
42 array($severity, $message, $filename, $line, $super_globals));
43 }
44
45 /**
46 * Pulls the earliest error from the queue.
47 * @return False if none, or a list of error
48 * information. Elements are: severity
49 * as the PHP error code, the error message,
50 * the file with the error, the line number
51 * and a list of PHP super global arrays.
52 * @access public
53 */
54 function extract() {
55 if (count($this->_queue)) {
56 return array_shift($this->_queue);
57 }
58 return false;
59 }
60
61 /**
62 * Discards the contents of the error queue.
63 * @access public
64 */
65 function clear() {
66 $this->_queue = array();
67 }
68
69 /**
70 * Tests to see if the queue is empty.
71 * @return True if empty.
72 */
73 function isEmpty() {
74 return (count($this->_queue) == 0);
75 }
76
77 /**
78 * Global access to a single error queue.
79 * @return Global error queue object.
80 * @access public
81 * @static
82 */
83 function &instance() {
84 static $queue = false;
85 if (! $queue) {
86 $queue = new SimpleErrorQueue();
87 }
88 return $queue;
89 }
90
91 /**
92 * Converst an error code into it's string
93 * representation.
94 * @param $severity PHP integer error code.
95 * @return String version of error code.
96 * @access public
97 * @static
98 */
99 function getSeverityAsString($severity) {
100 static $map = array(
101 E_STRICT => 'E_STRICT',
102 E_ERROR => 'E_ERROR',
103 E_WARNING => 'E_WARNING',
104 E_PARSE => 'E_PARSE',
105 E_NOTICE => 'E_NOTICE',
106 E_CORE_ERROR => 'E_CORE_ERROR',
107 E_CORE_WARNING => 'E_CORE_WARNING',
108 E_COMPILE_ERROR => 'E_COMPILE_ERROR',
109 E_COMPILE_WARNING => 'E_COMPILE_WARNING',
110 E_USER_ERROR => 'E_USER_ERROR',
111 E_USER_WARNING => 'E_USER_WARNING',
112 E_USER_NOTICE => 'E_USER_NOTICE');
113 return $map[$severity];
114 }
115 }
116
117 /**
118 * Error handler that simply stashes any errors into the global
119 * error queue. Simulates the existing behaviour with respect to
120 * logging errors, but this feature may be removed in future.
121 * @param $severity PHP error code.
122 * @param $message Text of error.
123 * @param $filename File error occoured in.
124 * @param $line Line number of error.
125 * @param $super_globals Hash of PHP super global arrays.
126 * @static
127 * @access public
128 */
129 function simpleTestErrorHandler($severity, $message, $filename, $line, $super_globals) {
130 restore_error_handler();
131 if (ini_get('log_errors')) {
132 $label = SimpleErrorQueue::getSeverityAsString($severity);
133 error_log("$label: $message in $filename on line $line");
134 }
135 if ($severity = $severity & error_reporting()) {
136 $queue = &SimpleErrorQueue::instance();
137 $queue->add($severity, $message, $filename, $line, $super_globals);
138 }
139 set_error_handler('simpleTestErrorHandler');
140 }
141 ?>