7 * Some useful debugging functionality.
14 static private $mode = 'html';
20 static public function mode($mode = 'html')
26 * Show output and exit script.
27 * @param array|string $output
29 static public function dieWith($output)
31 if ('html' == self::$mode) {
36 error_log(var_dump($output));
42 * On true evaluation show output and exit script.
43 * @param unknown $evaluation
44 * @param array|string $output
46 static public function dieIf($evaluation, $output)
49 self::dieWith($output);
55 * @param string $label
56 * @param array|string $output
58 static public function log($label, $output)
60 if ('html' == self::$mode) {
67 error_log(print_r($output, true));
72 * Log to php error log.
73 * @param string $label
74 * @param array|string $output
76 static public function errorLog($label, $output)
78 error_log("$label: ".print_r($output, true));
82 * Recursively strip doctrine entities from stacked array.
86 static public function stripEntities(array $data)
88 foreach ($data as $key => $value)
90 if (is_object($value) && strpos(get_class($value), 'Entity') !== false)
92 $data[$key] = self::stripEntities($value->toArray());
96 $data[$key] = self::stripEntities($value);
103 * Log to php error log with doctrine entities stripped to arrays.
104 * @param string $label
105 * @param array|string $output
107 static public function errorLogStripped($label, $output)
109 if (is_object($output) && strpos(get_class($output), 'Entity') !== false)
111 $output = $output->toArray();
113 if (is_array($output))
115 foreach ($output as $key => $value)
117 if (is_object($value) && strpos(get_class($value), 'Entity') !== false)
119 $output[$key] = self::stripEntities($value->toArray());
121 if (is_array($value))
123 $output[$key] = self::stripEntities($value);
127 error_log("$label: ".print_r($output, true));
131 * Log a debug backtrace to php error log.
133 static public function logBacktrace()
135 error_log(print_r(debug_backtrace(), true));
139 * Output php array as html table.
140 * @param array $array
141 * @param string $title
144 static public function arrayToTable(array $array, $title = null)
148 if (!empty($title)) {
152 <th colspan="2">' . htmlentities($title) . '</th>
158 foreach ($array as $key => $val) {
160 if (is_object($val)) {
161 $type = "\n" . '(Class: ' . get_class($val) . ')';
162 $val = $val->toArray();
166 if (is_array($val)) {
167 $val = self::arrayToTable($val, $type);
169 $val = htmlentities($val);
172 <td><b>" . htmlentities($key) . ":</b></td>
173 <td>" . $val . " </td>";