This repository has been archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
/
YiiDebug.php
81 lines (69 loc) · 2.21 KB
/
YiiDebug.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
<?php
/**
* YiiDebug class file.
*
* @author Sergey Malyshev <[email protected]>
*/
/**
* YiiDebug class.
*
* @author Sergey Malyshev <[email protected]>
* @version $Id$
* @package YiiDebugToolbar
* @since 1.1.7
*/
class YiiDebug extends CComponent
{
/**
* Displays a variable.
* This method achieves the similar functionality as var_dump and print_r
* but is more robust when handling complex objects such as Yii controllers.
* @param mixed $var variable to be dumped
*/
public static function dump()
{
$args = func_get_args();
if (php_sapi_name() == "cli") {
foreach ($args as $k => $var) {
var_dump($var);
echo "\n";
}
return;
} else if (empty($_SERVER['SERVER_ADDR']) || empty($_SERVER['REMOTE_ADDR']) || $_SERVER['SERVER_ADDR'] !== $_SERVER['REMOTE_ADDR']) {
return;
}
$backTrace = debug_backtrace();
$backTrace = array_shift($backTrace);
echo '<div style="margin: 10px;border: 1px solid red;padding: 10px; background: #fff;">';
if (is_array($backTrace) && isset($backTrace['file']) && isset($backTrace['function']) && $backTrace['function'] === __FUNCTION__) {
echo "<b>{$backTrace['file']}</b> in line <b>{$backTrace['line']}</b> <br />";
echo '<div style="border-bottom:1px solid #006699;margin: 5px 0;"></div>';
}
foreach ($args as $k => $var) {
echo CVarDumper::dump($var, 10, true), '<br />';
}
echo "</div>";
}
/**
* Writes a trace dump.
* @param string $msg message to be logged
*/
public static function trace($message)
{
Yii::trace(self::dump($message), 'dump');
}
public static function getClass($class)
{
return new ReflectionClass($class);
}
public static function getClassMethod($class,$name)
{
$class = self::getClass($class);
$method = $class->getMethod($name);
$method->setAccessible(true);
return $method;
}
public static function t($str,$params=array(),$dic='yii-debug-toolbar') {
return Yii::t("YiiDebug.".$dic, $str, $params);
}
}