1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Diagnostics;
9:
10: use Nette;
11:
12:
13: 14: 15: 16: 17:
18: class Helpers
19: {
20:
21: 22: 23: 24:
25: public static function editorLink($file, $line)
26: {
27: if (Debugger::$editor && is_file($file)) {
28: $dir = dirname(strtr($file, '/', DIRECTORY_SEPARATOR));
29: $base = isset($_SERVER['SCRIPT_FILENAME']) ? dirname(dirname(strtr($_SERVER['SCRIPT_FILENAME'], '/', DIRECTORY_SEPARATOR))) : dirname($dir);
30: if (substr($dir, 0, strlen($base)) === $base) {
31: $dir = '...' . substr($dir, strlen($base));
32: }
33: return Nette\Utils\Html::el('a')
34: ->href(strtr(Debugger::$editor, array('%file' => rawurlencode($file), '%line' => $line)))
35: ->title("$file:$line")
36: ->setHtml(htmlSpecialChars(rtrim($dir, DIRECTORY_SEPARATOR), ENT_IGNORE) . DIRECTORY_SEPARATOR . '<b>' . htmlSpecialChars(basename($file), ENT_IGNORE) . '</b>' . ($line ? ":$line" : ''));
37: } else {
38: return Nette\Utils\Html::el('span')->setText($file . ($line ? ":$line" : ''));
39: }
40: }
41:
42:
43: public static function findTrace(array $trace, $method, & $index = NULL)
44: {
45: $m = explode('::', $method);
46: foreach ($trace as $i => $item) {
47: if (isset($item['function']) && $item['function'] === end($m)
48: && isset($item['class']) === isset($m[1])
49: && (!isset($item['class']) || $item['class'] === $m[0] || $m[0] === '*' || is_subclass_of($item['class'], $m[0]))
50: ) {
51: $index = $i;
52: return $item;
53: }
54: }
55: }
56:
57:
58: public static function fixStack($exception)
59: {
60: if (function_exists('xdebug_get_function_stack')) {
61: $stack = array();
62: foreach (array_slice(array_reverse(xdebug_get_function_stack()), 2, -1) as $row) {
63: $frame = array(
64: 'file' => $row['file'],
65: 'line' => $row['line'],
66: 'function' => isset($row['function']) ? $row['function'] : '*unknown*',
67: 'args' => array(),
68: );
69: if (!empty($row['class'])) {
70: $frame['type'] = isset($row['type']) && $row['type'] === 'dynamic' ? '->' : '::';
71: $frame['class'] = $row['class'];
72: }
73: $stack[] = $frame;
74: }
75: $ref = new \ReflectionProperty('Exception', 'trace');
76: $ref->setAccessible(TRUE);
77: $ref->setValue($exception, $stack);
78: }
79: return $exception;
80: }
81:
82:
83:
84: public static function htmlDump($var)
85: {
86: trigger_error(__METHOD__ . '() is deprecated; use Nette\Diagnostics\Dumper::toHtml() instead.', E_USER_DEPRECATED);
87: return Dumper::toHtml($var);
88: }
89:
90:
91: public static function clickableDump($var)
92: {
93: trigger_error(__METHOD__ . '() is deprecated; use Nette\Diagnostics\Dumper::toHtml() instead.', E_USER_DEPRECATED);
94: return Dumper::toHtml($var);
95: }
96:
97:
98: public static function textDump($var)
99: {
100: trigger_error(__METHOD__ . '() is deprecated; use Nette\Diagnostics\Dumper::toText() instead.', E_USER_DEPRECATED);
101: return Dumper::toText($var);
102: }
103:
104: }
105: