|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class Kint_Renderer_Cli extends Kint_Renderer_Text |
|
|
|
|
|
|
5
|
|
|
{ |
|
6
|
|
|
/** |
|
7
|
|
|
* @var bool enable colors when Kint is run in *UNIX* command line |
|
8
|
|
|
*/ |
|
9
|
|
|
public static $cli_colors = true; |
|
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Forces utf8 output on windows. |
|
13
|
|
|
* |
|
14
|
|
|
* @var bool |
|
15
|
|
|
*/ |
|
16
|
|
|
public static $force_utf8 = false; |
|
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Detects the terminal width on startup. |
|
20
|
|
|
* |
|
21
|
|
|
* @var bool |
|
22
|
|
|
*/ |
|
23
|
|
|
public static $detect_width = true; |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The minimum width to detect terminal size as. |
|
27
|
|
|
* |
|
28
|
|
|
* Less than this is ignored and falls back to default width. |
|
29
|
|
|
* |
|
30
|
|
|
* @var int |
|
31
|
|
|
*/ |
|
32
|
|
|
public static $min_terminal_width = 40; |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
protected static $terminal_width = null; |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
protected $windows_output = false; |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
public function __construct(array $params = array()) |
|
39
|
|
|
{ |
|
40
|
|
|
parent::__construct($params); |
|
41
|
|
|
|
|
42
|
|
|
if (!self::$force_utf8) { |
|
43
|
|
|
$this->windows_output = KINT_WIN; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
if (!self::$terminal_width) { |
|
47
|
|
|
if (!KINT_WIN && self::$detect_width) { |
|
48
|
|
|
self::$terminal_width = exec('tput cols'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
if (self::$terminal_width < self::$min_terminal_width) { |
|
52
|
|
|
self::$terminal_width = self::$default_width; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$this->header_width = self::$terminal_width; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
View Code Duplication |
protected function utf8_to_windows($string) |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
return str_replace( |
|
62
|
|
|
array('┌', '═', '┐', '│', '└', '─', '┘'), |
|
63
|
|
|
array("\xda", "\xdc", "\xbf", "\xb3", "\xc0", "\xc4", "\xd9"), |
|
64
|
|
|
$string |
|
65
|
|
|
); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
View Code Duplication |
public function colorValue($string) |
|
|
|
|
|
|
69
|
|
|
{ |
|
70
|
|
|
if (!self::$cli_colors) { |
|
71
|
|
|
return $string; |
|
72
|
|
|
} else { |
|
73
|
|
|
return "\x1b[32m".str_replace("\n", "\x1b[0m\n\x1b[32m", $string)."\x1b[0m"; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
View Code Duplication |
public function colorType($string) |
|
|
|
|
|
|
78
|
|
|
{ |
|
79
|
|
|
if (!self::$cli_colors) { |
|
80
|
|
|
return $string; |
|
81
|
|
|
} else { |
|
82
|
|
|
return "\x1b[35;1m".str_replace("\n", "\x1b[0m\n\x1b[35;1m", $string)."\x1b[0m"; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
View Code Duplication |
public function colorTitle($string) |
|
|
|
|
|
|
87
|
|
|
{ |
|
88
|
|
|
if (!self::$cli_colors) { |
|
89
|
|
|
return $string; |
|
90
|
|
|
} else { |
|
91
|
|
|
return "\x1b[36m".str_replace("\n", "\x1b[0m\n\x1b[36m", $string)."\x1b[0m"; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function renderTitle(Kint_Object $o) |
|
|
|
|
|
|
96
|
|
|
{ |
|
97
|
|
|
if ($this->windows_output) { |
|
98
|
|
|
return $this->utf8_to_windows(parent::renderTitle($o)); |
|
99
|
|
|
} else { |
|
100
|
|
|
return parent::renderTitle($o); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function preRender() |
|
105
|
|
|
{ |
|
106
|
|
|
return PHP_EOL; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function postRender() |
|
|
|
|
|
|
110
|
|
|
{ |
|
111
|
|
|
if ($this->windows_output) { |
|
112
|
|
|
return $this->utf8_to_windows(parent::postRender()); |
|
113
|
|
|
} else { |
|
114
|
|
|
return parent::postRender(); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function escape($string, $encoding = false) |
|
|
|
|
|
|
119
|
|
|
{ |
|
120
|
|
|
return str_replace("\x1b", '\\x1b', $string); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.