|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Kint\Renderer; |
|
4
|
|
|
|
|
5
|
|
|
use Kint\Kint; |
|
6
|
|
|
use Kint\Object\BasicObject; |
|
7
|
|
|
use Kint\Object\BlobObject; |
|
8
|
|
|
|
|
9
|
|
|
class PlainRenderer extends TextRenderer |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
public static $pre_render_sources = array( |
|
|
|
|
|
|
12
|
|
|
'script' => array(), |
|
13
|
|
|
'style' => array( |
|
14
|
|
|
array('Kint\\Renderer\\PlainRenderer', 'renderCss'), |
|
15
|
|
|
), |
|
16
|
|
|
'raw' => array(), |
|
17
|
|
|
); |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Path to the CSS file to load by default. |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
public static $theme = 'plain.css'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Output htmlentities instead of utf8. |
|
28
|
|
|
* |
|
29
|
|
|
* @var bool |
|
30
|
|
|
*/ |
|
31
|
|
|
public static $disable_utf8 = false; |
|
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
protected static $been_run = false; |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
View Code Duplication |
protected function utf8ToHtmlentity($string) |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
return str_replace( |
|
38
|
|
|
array('┌', '═', '┐', '│', '└', '─', '┘'), |
|
39
|
|
|
array('┌', '═', '┐', '│', '└', '─', '┘'), |
|
40
|
|
|
$string |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function colorValue($string) |
|
45
|
|
|
{ |
|
46
|
|
|
return '<i>'.$string.'</i>'; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function colorType($string) |
|
50
|
|
|
{ |
|
51
|
|
|
return '<b>'.$string.'</b>'; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function colorTitle($string) |
|
55
|
|
|
{ |
|
56
|
|
|
return '<u>'.$string.'</u>'; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function renderTitle(BasicObject $o) |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
if (self::$disable_utf8) { |
|
62
|
|
|
return $this->utf8ToHtmlentity(parent::renderTitle($o)); |
|
63
|
|
|
} else { |
|
64
|
|
|
return parent::renderTitle($o); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
View Code Duplication |
protected static function renderCss() |
|
|
|
|
|
|
69
|
|
|
{ |
|
70
|
|
|
if (file_exists(KINT_DIR.'/resources/compiled/'.self::$theme)) { |
|
71
|
|
|
return file_get_contents(KINT_DIR.'/resources/compiled/'.self::$theme); |
|
72
|
|
|
} else { |
|
73
|
|
|
return file_get_contents(self::$theme); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
View Code Duplication |
public function preRender() |
|
|
|
|
|
|
78
|
|
|
{ |
|
79
|
|
|
$output = ''; |
|
80
|
|
|
|
|
81
|
|
|
if (!self::$been_run || $this->return_mode) { |
|
82
|
|
|
foreach (self::$pre_render_sources as $type => $values) { |
|
83
|
|
|
$contents = ''; |
|
84
|
|
|
foreach ($values as $v) { |
|
85
|
|
|
$contents .= call_user_func($v, $this); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
if (!strlen($contents)) { |
|
89
|
|
|
continue; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
switch ($type) { |
|
93
|
|
|
case 'script': |
|
94
|
|
|
$output .= '<script class="kint-script">'.$contents.'</script>'; |
|
95
|
|
|
break; |
|
96
|
|
|
case 'style': |
|
97
|
|
|
$output .= '<style class="kint-style">'.$contents.'</style>'; |
|
98
|
|
|
break; |
|
99
|
|
|
default: |
|
100
|
|
|
$output .= $contents; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
if (!$this->return_mode) { |
|
105
|
|
|
self::$been_run = true; |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
return $output.'<div class="kint-plain">'; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function postRender() |
|
113
|
|
|
{ |
|
114
|
|
|
if (self::$disable_utf8) { |
|
115
|
|
|
return $this->utf8ToHtmlentity(parent::postRender()).'</div>'; |
|
116
|
|
|
} else { |
|
117
|
|
|
return parent::postRender().'</div>'; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
View Code Duplication |
public function ideLink($file, $line) |
|
|
|
|
|
|
122
|
|
|
{ |
|
123
|
|
|
$path = $this->escape(Kint::shortenPath($file)).':'.$line; |
|
124
|
|
|
$ideLink = Kint::getIdeLink($file, $line); |
|
125
|
|
|
|
|
126
|
|
|
if (!$ideLink) { |
|
127
|
|
|
return $path; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
$class = ''; |
|
131
|
|
|
|
|
132
|
|
|
if (preg_match($ideLink, '/https?:\/\//i')) { |
|
133
|
|
|
$class = 'class="kint-ide-link" '; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
return '<a '.$class.'href="'.$this->escape($ideLink).'">'.$path.'</a>'; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
View Code Duplication |
public function escape($string, $encoding = false) |
|
|
|
|
|
|
140
|
|
|
{ |
|
141
|
|
|
if ($encoding === false) { |
|
142
|
|
|
$encoding = BlobObject::detectEncoding($string); |
|
|
|
|
|
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
$original_encoding = $encoding; |
|
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
if ($encoding === false || $encoding === 'ASCII') { |
|
148
|
|
|
$encoding = 'UTF-8'; |
|
|
|
|
|
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
$string = htmlspecialchars($string, ENT_NOQUOTES, $encoding); |
|
|
|
|
|
|
152
|
|
|
|
|
153
|
|
|
// this call converts all non-ASCII characters into numeirc htmlentities |
|
154
|
|
|
if (extension_loaded('mbstring') && $original_encoding !== 'ASCII') { |
|
|
|
|
|
|
155
|
|
|
$string = mb_encode_numericentity($string, array(0x80, 0xffff, 0, 0xffff), $encoding); |
|
|
|
|
|
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
return $string; |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.