/
Helpers.php
94 lines (77 loc) 路 2.29 KB
/
Helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* This file is part of the Nette Framework (http://nette.org)
*
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
*/
namespace Tracy;
use Tracy;
/**
* Rendering helpers for Debugger.
*
* @author David Grudl
*/
final class Helpers
{
/**
* Returns link to editor.
* @return string
*/
public static function editorLink($file, $line)
{
if (Debugger::$editor && is_file($file)) {
$dir = dirname(strtr($file, '/', DIRECTORY_SEPARATOR));
$base = isset($_SERVER['SCRIPT_FILENAME']) ? dirname(dirname(strtr($_SERVER['SCRIPT_FILENAME'], '/', DIRECTORY_SEPARATOR))) : dirname($dir);
if (substr($dir, 0, strlen($base)) === $base) {
$dir = '...' . substr($dir, strlen($base));
}
return self::createHtml('<a href="%" title="%">%<b>%</b>%</a>',
strtr(Debugger::$editor, array('%file' => rawurlencode($file), '%line' => $line)),
"$file:$line",
rtrim($dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR,
basename($file),
$line ? ":$line" : ''
);
} else {
return self::createHtml('<span>%</span>', $file . ($line ? ":$line" : ''));
}
}
public static function createHtml($mask)
{
$args = func_get_args();
return preg_replace_callback('#%#', function() use (& $args, & $count) {
return htmlspecialchars($args[++$count]);
}, $mask);
}
public static function findTrace(array $trace, $method, & $index = NULL)
{
$m = explode('::', $method);
foreach ($trace as $i => $item) {
if (isset($item['function']) && $item['function'] === end($m)
&& isset($item['class']) === isset($m[1])
&& (!isset($item['class']) || $item['class'] === $m[0] || $m[0] === '*' || is_subclass_of($item['class'], $m[0]))
) {
$index = $i;
return $item;
}
}
}
/**
* Returns correctly encoded string.
* @param string byte stream to fix
* @return string
*/
public static function fixEncoding($s)
{
// removes xD800-xDFFF, x110000 and higher
if (PHP_VERSION_ID >= 50400) {
ini_set('mbstring.substitute_character', 'none');
return mb_convert_encoding($s, 'UTF-8', 'UTF-8');
} else {
return @iconv('UTF-16', 'UTF-8//IGNORE', iconv('UTF-8', 'UTF-16//IGNORE', $s)); // intentionally @
}
}
}