1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kint\Renderer; |
4
|
|
|
|
5
|
|
|
use Kint\Kint; |
6
|
|
|
use Kint\Object\BasicObject; |
7
|
|
|
use Kint\Object\BlobObject; |
8
|
|
|
use Kint\Object\InstanceObject; |
9
|
|
|
use Kint\Object\Representation\Representation; |
10
|
|
|
|
11
|
|
|
class RichRenderer extends Renderer |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* RichRenderer object plugins should implement Kint\Renderer\Rich\ObjectPluginInterface. |
15
|
|
|
*/ |
16
|
|
|
public static $object_plugins = array( |
|
|
|
|
17
|
|
|
'blacklist' => 'Kint\\Renderer\\Rich\\BlacklistPlugin', |
18
|
|
|
'callable' => 'Kint\\Renderer\\Rich\\CallablePlugin', |
19
|
|
|
'closure' => 'Kint\\Renderer\\Rich\\ClosurePlugin', |
20
|
|
|
'color' => 'Kint\\Renderer\\Rich\\ColorPlugin', |
21
|
|
|
'depth_limit' => 'Kint\\Renderer\\Rich\\DepthLimitPlugin', |
22
|
|
|
'recursion' => 'Kint\\Renderer\\Rich\\RecursionPlugin', |
23
|
|
|
'simplexml_element' => 'Kint\\Renderer\\Rich\\SimpleXMLElementPlugin', |
24
|
|
|
'trace_frame' => 'Kint\\Renderer\\Rich\\TraceFramePlugin', |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* RichRenderer tab plugins should implement Kint\Renderer\Rich\TabPluginInterface. |
29
|
|
|
*/ |
30
|
|
|
public static $tab_plugins = array( |
|
|
|
|
31
|
|
|
'binary' => 'Kint\\Renderer\\Rich\\BinaryPlugin', |
32
|
|
|
'color' => 'Kint\\Renderer\\Rich\\ColorPlugin', |
33
|
|
|
'docstring' => 'Kint\\Renderer\\Rich\\DocstringPlugin', |
34
|
|
|
'microtime' => 'Kint\\Renderer\\Rich\\MicrotimePlugin', |
35
|
|
|
'source' => 'Kint\\Renderer\\Rich\\SourcePlugin', |
36
|
|
|
'table' => 'Kint\\Renderer\\Rich\\TablePlugin', |
37
|
|
|
'timestamp' => 'Kint\\Renderer\\Rich\\TimestampPlugin', |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
public static $pre_render_sources = array( |
|
|
|
|
41
|
|
|
'script' => array( |
42
|
|
|
array('Kint\\Renderer\\RichRenderer', 'renderJs'), |
43
|
|
|
array('Kint\\Renderer\\Rich\\MicrotimePlugin', 'renderJs'), |
44
|
|
|
), |
45
|
|
|
'style' => array( |
46
|
|
|
array('Kint\\Renderer\\RichRenderer', 'renderCss'), |
47
|
|
|
), |
48
|
|
|
'raw' => array( |
49
|
|
|
array('Kint\\Renderer\\RichRenderer', 'renderFolder'), |
50
|
|
|
), |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Whether or not to render access paths. |
55
|
|
|
* |
56
|
|
|
* Access paths can become incredibly heavy with very deep and wide |
57
|
|
|
* structures. Given mostly public variables it will typically make |
58
|
|
|
* up one quarter of the output HTML size. |
59
|
|
|
* |
60
|
|
|
* If this is an unacceptably large amount and your browser is groaning |
61
|
|
|
* under the weight of the access paths - your first order of buisiness |
62
|
|
|
* should be to get a new browser. Failing that, use this to turn them off. |
63
|
|
|
* |
64
|
|
|
* @var bool |
65
|
|
|
*/ |
66
|
|
|
public static $access_paths = true; |
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* The maximum length of a string before it is truncated. |
70
|
|
|
* |
71
|
|
|
* Falsey to disable |
72
|
|
|
* |
73
|
|
|
* @var int |
74
|
|
|
*/ |
75
|
|
|
public static $strlen_max = 80; |
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Path to the CSS file to load by default. |
79
|
|
|
* |
80
|
|
|
* @var string |
81
|
|
|
*/ |
82
|
|
|
public static $theme = 'original.css'; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Assume types and sizes don't need to be escaped. |
86
|
|
|
* |
87
|
|
|
* Turn this off if you use anything but ascii in your class names, |
88
|
|
|
* but it'll cause a slowdown of around 10% |
89
|
|
|
* |
90
|
|
|
* @var bool |
91
|
|
|
*/ |
92
|
|
|
public static $escape_types = false; |
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Move all dumps to a folder at the bottom of the body. |
96
|
|
|
* |
97
|
|
|
* @var bool |
98
|
|
|
*/ |
99
|
|
|
public static $folder = true; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Sort mode for object properties. |
103
|
|
|
* |
104
|
|
|
* @var int |
105
|
|
|
*/ |
106
|
|
|
public static $sort = self::SORT_NONE; |
107
|
|
|
|
108
|
|
|
protected static $been_run = false; |
|
|
|
|
109
|
|
|
|
110
|
|
|
protected $plugin_objs = array(); |
|
|
|
|
111
|
|
|
|
112
|
|
|
public function render(BasicObject $o) |
|
|
|
|
113
|
|
|
{ |
114
|
|
|
if ($plugin = $this->getPlugin(self::$object_plugins, $o->hints)) { |
115
|
|
|
if (strlen($output = $plugin->renderObject($o))) { |
116
|
|
|
return $output; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
$children = $this->renderChildren($o); |
121
|
|
|
$header = $this->renderHeaderWrapper($o, (bool) strlen($children), $this->renderHeader($o)); |
122
|
|
|
|
123
|
|
|
return '<dl>'.$header.$children.'</dl>'; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function renderNothing() |
127
|
|
|
{ |
128
|
|
|
return '<dl><dt><var>No argument</var></dt></dl>'; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function renderHeaderWrapper(BasicObject $o, $has_children, $contents) |
|
|
|
|
132
|
|
|
{ |
133
|
|
|
$out = '<dt'; |
134
|
|
|
|
135
|
|
|
if ($has_children) { |
|
|
|
|
136
|
|
|
$out .= ' class="kint-parent'; |
137
|
|
|
|
138
|
|
|
if ($this->expand) { |
139
|
|
|
$out .= ' kint-show'; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
$out .= '"'; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
$out .= '>'; |
146
|
|
|
|
147
|
|
View Code Duplication |
if (self::$access_paths && $o->depth > 0 && $ap = $o->getAccessPath()) { |
|
|
|
|
148
|
|
|
$out .= '<span class="kint-access-path-trigger" title="Show access path">⇄</span>'; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
if ($has_children) { |
|
|
|
|
152
|
|
|
$out .= '<span class="kint-popup-trigger" title="Open in new window">⧉</span><nav></nav>'; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
$out .= $contents; |
156
|
|
|
|
157
|
|
|
if (!empty($ap)) { |
158
|
|
|
$out .= '<div class="access-path">'.$this->escape($ap).'</div>'; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
return $out.'</dt>'; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
public function renderHeader(BasicObject $o) |
|
|
|
|
165
|
|
|
{ |
166
|
|
|
$output = ''; |
167
|
|
|
|
168
|
|
|
if (($s = $o->getModifiers()) !== null) { |
|
|
|
|
169
|
|
|
$output .= '<var>'.$s.'</var> '; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
if (($s = $o->getName()) !== null) { |
173
|
|
|
$output .= '<dfn>'.$this->escape($s).'</dfn> '; |
174
|
|
|
|
175
|
|
|
if ($s = $o->getOperator()) { |
176
|
|
|
$output .= $this->escape($s, 'ASCII').' '; |
|
|
|
|
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
180
|
|
View Code Duplication |
if (($s = $o->getType()) !== null) { |
|
|
|
|
181
|
|
|
if (self::$escape_types) { |
182
|
|
|
$s = $this->escape($s); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
if ($o->reference) { |
186
|
|
|
$s = '&'.$s; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
$output .= '<var>'.$s.'</var> '; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
View Code Duplication |
if (($s = $o->getSize()) !== null) { |
|
|
|
|
193
|
|
|
if (self::$escape_types) { |
194
|
|
|
$s = $this->escape($s); |
195
|
|
|
} |
196
|
|
|
$output .= '('.$s.') '; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
if (($s = $o->getValueShort()) !== null) { |
200
|
|
|
$s = preg_replace('/\s+/', ' ', $s); |
201
|
|
|
|
202
|
|
|
if (self::$strlen_max && BlobObject::strlen($s) > self::$strlen_max) { |
203
|
|
|
$s = substr($s, 0, self::$strlen_max).'...'; |
204
|
|
|
} |
205
|
|
|
$output .= $this->escape($s); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
return trim($output); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
public function renderChildren(BasicObject $o) |
|
|
|
|
212
|
|
|
{ |
213
|
|
|
$contents = array(); |
214
|
|
|
$tabs = array(); |
215
|
|
|
|
216
|
|
|
foreach ($o->getRepresentations() as $rep) { |
217
|
|
|
$result = $this->renderTab($o, $rep); |
218
|
|
|
if (strlen($result)) { |
219
|
|
|
$contents[] = $result; |
220
|
|
|
$tabs[] = $rep; |
221
|
|
|
} |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
if (empty($tabs)) { |
225
|
|
|
return ''; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
$output = '<dd>'; |
229
|
|
|
|
230
|
|
|
if (count($tabs) === 1 && $tabs[0]->labelIsImplicit()) { |
231
|
|
|
$output .= reset($contents); |
232
|
|
|
} else { |
233
|
|
|
$output .= '<ul class="kint-tabs">'; |
234
|
|
|
|
235
|
|
|
foreach ($tabs as $i => $tab) { |
236
|
|
|
if ($i === 0) { |
237
|
|
|
$output .= '<li class="kint-active-tab">'; |
238
|
|
|
} else { |
239
|
|
|
$output .= '<li>'; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
$output .= $this->escape($tab->getLabel()).'</li>'; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
$output .= '</ul><ul>'; |
246
|
|
|
|
247
|
|
|
foreach ($contents as $tab) { |
248
|
|
|
$output .= '<li>'.$tab.'</li>'; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
$output .= '</ul>'; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
return $output.'</dd>'; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
protected function renderTab(BasicObject $o, Representation $rep) |
|
|
|
|
258
|
|
|
{ |
259
|
|
|
if ($plugin = $this->getPlugin(self::$tab_plugins, $rep->hints)) { |
260
|
|
|
if (strlen($output = $plugin->renderTab($rep))) { |
261
|
|
|
return $output; |
262
|
|
|
} |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
if (is_array($rep->contents)) { |
266
|
|
|
$output = ''; |
267
|
|
|
|
268
|
|
View Code Duplication |
if ($o instanceof InstanceObject && $rep->getName() === 'properties') { |
|
|
|
|
269
|
|
|
foreach (self::sortProperties($rep->contents, self::$sort) as $obj) { |
270
|
|
|
$output .= $this->render($obj); |
271
|
|
|
} |
272
|
|
|
} else { |
273
|
|
|
foreach ($rep->contents as $obj) { |
274
|
|
|
$output .= $this->render($obj); |
275
|
|
|
} |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
return $output; |
279
|
|
|
} elseif (is_string($rep->contents)) { |
280
|
|
|
$show_contents = false; |
|
|
|
|
281
|
|
|
|
282
|
|
|
// If it is the value representation of a string and its whitespace |
283
|
|
|
// was truncated in the header, always display the full string |
284
|
|
|
if ($o->type !== 'string' || $o->value !== $rep) { |
285
|
|
|
$show_contents = true; |
|
|
|
|
286
|
|
|
} else { |
287
|
|
|
if (preg_match('/(:?[\r\n\t\f\v]| {2})/', $rep->contents)) { |
288
|
|
|
$show_contents = true; |
|
|
|
|
289
|
|
|
} elseif (self::$strlen_max && BlobObject::strlen($o->getValueShort()) > self::$strlen_max) { |
290
|
|
|
$show_contents = true; |
|
|
|
|
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
if (empty($o->encoding)) { |
|
|
|
|
294
|
|
|
$show_contents = false; |
|
|
|
|
295
|
|
|
} |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
if ($show_contents) { |
|
|
|
|
299
|
|
|
return '<pre>'.$this->escape($rep->contents)."\n</pre>"; |
300
|
|
|
} |
301
|
|
|
} elseif ($rep->contents instanceof BasicObject) { |
302
|
|
|
return $this->render($rep->contents); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
return; |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
protected static function renderJs() |
309
|
|
|
{ |
310
|
|
|
return file_get_contents(KINT_DIR.'/resources/compiled/rich.js'); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
View Code Duplication |
protected static function renderCss() |
|
|
|
|
314
|
|
|
{ |
315
|
|
|
if (file_exists(KINT_DIR.'/resources/compiled/'.self::$theme)) { |
316
|
|
|
return file_get_contents(KINT_DIR.'/resources/compiled/'.self::$theme); |
317
|
|
|
} else { |
318
|
|
|
return file_get_contents(self::$theme); |
319
|
|
|
} |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
protected static function renderFolder() |
323
|
|
|
{ |
324
|
|
|
if (self::$folder) { |
325
|
|
|
return '<div class="kint-rich kint-folder"><dl><dt class="kint-parent"><nav></nav>Kint</dt><dd class="kint-folder"></dd></dl></div>'; |
326
|
|
|
} else { |
327
|
|
|
return ''; |
328
|
|
|
} |
329
|
|
|
} |
330
|
|
|
|
331
|
|
View Code Duplication |
public function preRender() |
|
|
|
|
332
|
|
|
{ |
333
|
|
|
$output = ''; |
334
|
|
|
|
335
|
|
|
if (!self::$been_run || $this->return_mode) { |
336
|
|
|
foreach (self::$pre_render_sources as $type => $values) { |
337
|
|
|
$contents = ''; |
338
|
|
|
foreach ($values as $v) { |
339
|
|
|
$contents .= call_user_func($v, $this); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
if (!strlen($contents)) { |
343
|
|
|
continue; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
switch ($type) { |
347
|
|
|
case 'script': |
348
|
|
|
$output .= '<script class="kint-script">'.$contents.'</script>'; |
349
|
|
|
break; |
350
|
|
|
case 'style': |
351
|
|
|
$output .= '<style class="kint-style">'.$contents.'</style>'; |
352
|
|
|
break; |
353
|
|
|
default: |
354
|
|
|
$output .= $contents; |
355
|
|
|
} |
356
|
|
|
} |
357
|
|
|
|
358
|
|
|
if (!$this->return_mode) { |
359
|
|
|
self::$been_run = true; |
360
|
|
|
} |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
return $output.'<div class="kint-rich">'; |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
public function postRender() |
367
|
|
|
{ |
368
|
|
|
if (!$this->show_trace) { |
369
|
|
|
return '</div>'; |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
$output = '<footer>'; |
373
|
|
|
$output .= '<span class="kint-popup-trigger" title="Open in new window">⧉</span> '; |
374
|
|
|
|
375
|
|
|
if (isset($this->call_info['callee']['file'])) { |
376
|
|
|
if (!empty($this->call_info['trace']) && count($this->call_info['trace']) > 1) { |
377
|
|
|
$output .= '<nav></nav>'; |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
$output .= 'Called from '.$this->ideLink( |
381
|
|
|
$this->call_info['callee']['file'], |
382
|
|
|
$this->call_info['callee']['line'] |
383
|
|
|
); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
View Code Duplication |
if (isset($this->call_info['callee']['function']) && ( |
|
|
|
|
387
|
|
|
!empty($this->call_info['callee']['class']) || |
388
|
|
|
!in_array( |
389
|
|
|
$this->call_info['callee']['function'], |
390
|
|
|
array('include', 'include_once', 'require', 'require_once') |
391
|
|
|
) |
392
|
|
|
) |
393
|
|
|
) { |
394
|
|
|
$output .= ' ['; |
395
|
|
|
if (isset($this->call_info['callee']['class'])) { |
396
|
|
|
$output .= $this->call_info['callee']['class']; |
397
|
|
|
} |
398
|
|
|
if (isset($this->call_info['callee']['type'])) { |
399
|
|
|
$output .= $this->call_info['callee']['type']; |
400
|
|
|
} |
401
|
|
|
$output .= $this->call_info['callee']['function'].'()]'; |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
if (!empty($this->call_info['trace']) && count($this->call_info['trace']) > 1) { |
405
|
|
|
$output .= '<ol>'; |
406
|
|
|
foreach ($this->call_info['trace'] as $index => $step) { |
407
|
|
|
if (!$index) { |
408
|
|
|
continue; |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
$output .= '<li>'.$this->ideLink($step['file'], $step['line']); // closing tag not required |
412
|
|
|
if (isset($step['function']) |
413
|
|
|
&& !in_array($step['function'], array('include', 'include_once', 'require', 'require_once')) |
414
|
|
|
) { |
415
|
|
|
$output .= ' ['; |
416
|
|
|
if (isset($step['class'])) { |
417
|
|
|
$output .= $step['class']; |
418
|
|
|
} |
419
|
|
|
if (isset($step['type'])) { |
420
|
|
|
$output .= $step['type']; |
421
|
|
|
} |
422
|
|
|
$output .= $step['function'].'()]'; |
423
|
|
|
} |
424
|
|
|
} |
425
|
|
|
$output .= '</ol>'; |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
$output .= '</footer></div>'; |
429
|
|
|
|
430
|
|
|
return $output; |
431
|
|
|
} |
432
|
|
|
|
433
|
|
View Code Duplication |
public function escape($string, $encoding = false) |
|
|
|
|
434
|
|
|
{ |
435
|
|
|
if ($encoding === false) { |
436
|
|
|
$encoding = BlobObject::detectEncoding($string); |
|
|
|
|
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
$original_encoding = $encoding; |
|
|
|
|
440
|
|
|
|
441
|
|
|
if ($encoding === false || $encoding === 'ASCII') { |
442
|
|
|
$encoding = 'UTF-8'; |
|
|
|
|
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
$string = htmlspecialchars($string, ENT_NOQUOTES, $encoding); |
|
|
|
|
446
|
|
|
|
447
|
|
|
// this call converts all non-ASCII characters into numeirc htmlentities |
448
|
|
|
if (extension_loaded('mbstring') && $original_encoding !== 'ASCII') { |
|
|
|
|
449
|
|
|
$string = mb_encode_numericentity($string, array(0x80, 0xffff, 0, 0xffff), $encoding); |
|
|
|
|
450
|
|
|
} |
451
|
|
|
|
452
|
|
|
return $string; |
453
|
|
|
} |
454
|
|
|
|
455
|
|
View Code Duplication |
protected function getPlugin(array $plugins, array $hints) |
|
|
|
|
456
|
|
|
{ |
457
|
|
|
if ($plugins = $this->matchPlugins($plugins, $hints)) { |
|
|
|
|
458
|
|
|
$plugin = end($plugins); |
459
|
|
|
|
460
|
|
|
if (!isset($this->plugin_objs[$plugin])) { |
461
|
|
|
$this->plugin_objs[$plugin] = new $plugin($this); |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
return $this->plugin_objs[$plugin]; |
465
|
|
|
} |
466
|
|
|
} |
467
|
|
|
|
468
|
|
View Code Duplication |
public function ideLink($file, $line) |
|
|
|
|
469
|
|
|
{ |
470
|
|
|
$path = $this->escape(Kint::shortenPath($file)).':'.$line; |
471
|
|
|
$ideLink = Kint::getIdeLink($file, $line); |
472
|
|
|
|
473
|
|
|
if (!$ideLink) { |
474
|
|
|
return $path; |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
$class = ''; |
478
|
|
|
|
479
|
|
|
if (preg_match($ideLink, '/https?:\/\//i')) { |
480
|
|
|
$class = 'class="kint-ide-link" '; |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
return '<a '.$class.'href="'.$this->escape($ideLink).'">'.$path.'</a>'; |
484
|
|
|
} |
485
|
|
|
} |
486
|
|
|
|
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
.