| 148 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
* This file is part of the Symfony package.
|
|
|
5 |
*
|
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
7 |
*
|
|
|
8 |
* For the full copyright and license information, please view the LICENSE
|
|
|
9 |
* file that was distributed with this source code.
|
|
|
10 |
*/
|
|
|
11 |
|
|
|
12 |
namespace Symfony\Component\VarDumper\Dumper;
|
|
|
13 |
|
|
|
14 |
use Symfony\Component\VarDumper\Cloner\Cursor;
|
|
|
15 |
use Symfony\Component\VarDumper\Cloner\Data;
|
|
|
16 |
|
|
|
17 |
/**
|
|
|
18 |
* HtmlDumper dumps variables as HTML.
|
|
|
19 |
*
|
|
|
20 |
* @author Nicolas Grekas <p@tchwork.com>
|
|
|
21 |
*/
|
|
|
22 |
class HtmlDumper extends CliDumper
|
|
|
23 |
{
|
|
|
24 |
public static $defaultOutput = 'php://output';
|
|
|
25 |
|
|
|
26 |
protected static $themes = [
|
|
|
27 |
'dark' => [
|
|
|
28 |
'default' => 'background-color:#18171B; color:#FF8400; line-height:1.2em; font:12px Menlo, Monaco, Consolas, monospace; word-wrap: break-word; white-space: pre-wrap; position:relative; z-index:99999; word-break: break-all',
|
|
|
29 |
'num' => 'font-weight:bold; color:#1299DA',
|
|
|
30 |
'const' => 'font-weight:bold',
|
|
|
31 |
'str' => 'font-weight:bold; color:#56DB3A',
|
|
|
32 |
'note' => 'color:#1299DA',
|
|
|
33 |
'ref' => 'color:#A0A0A0',
|
|
|
34 |
'public' => 'color:#FFFFFF',
|
|
|
35 |
'protected' => 'color:#FFFFFF',
|
|
|
36 |
'private' => 'color:#FFFFFF',
|
|
|
37 |
'meta' => 'color:#B729D9',
|
|
|
38 |
'key' => 'color:#56DB3A',
|
|
|
39 |
'index' => 'color:#1299DA',
|
|
|
40 |
'ellipsis' => 'color:#FF8400',
|
|
|
41 |
'ns' => 'user-select:none;',
|
|
|
42 |
],
|
|
|
43 |
'light' => [
|
|
|
44 |
'default' => 'background:none; color:#CC7832; line-height:1.2em; font:12px Menlo, Monaco, Consolas, monospace; word-wrap: break-word; white-space: pre-wrap; position:relative; z-index:99999; word-break: break-all',
|
|
|
45 |
'num' => 'font-weight:bold; color:#1299DA',
|
|
|
46 |
'const' => 'font-weight:bold',
|
|
|
47 |
'str' => 'font-weight:bold; color:#629755;',
|
|
|
48 |
'note' => 'color:#6897BB',
|
|
|
49 |
'ref' => 'color:#6E6E6E',
|
|
|
50 |
'public' => 'color:#262626',
|
|
|
51 |
'protected' => 'color:#262626',
|
|
|
52 |
'private' => 'color:#262626',
|
|
|
53 |
'meta' => 'color:#B729D9',
|
|
|
54 |
'key' => 'color:#789339',
|
|
|
55 |
'index' => 'color:#1299DA',
|
|
|
56 |
'ellipsis' => 'color:#CC7832',
|
|
|
57 |
'ns' => 'user-select:none;',
|
|
|
58 |
],
|
|
|
59 |
];
|
|
|
60 |
|
|
|
61 |
protected $dumpHeader;
|
|
|
62 |
protected $dumpPrefix = '<pre class=sf-dump id=%s data-indent-pad="%s">';
|
|
|
63 |
protected $dumpSuffix = '</pre><script>Sfdump(%s)</script>';
|
|
|
64 |
protected $dumpId = 'sf-dump';
|
|
|
65 |
protected $colors = true;
|
|
|
66 |
protected $headerIsDumped = false;
|
|
|
67 |
protected $lastDepth = -1;
|
|
|
68 |
protected $styles;
|
|
|
69 |
|
|
|
70 |
private array $displayOptions = [
|
|
|
71 |
'maxDepth' => 1,
|
|
|
72 |
'maxStringLength' => 160,
|
|
|
73 |
'fileLinkFormat' => null,
|
|
|
74 |
];
|
|
|
75 |
private array $extraDisplayOptions = [];
|
|
|
76 |
|
|
|
77 |
public function __construct($output = null, string $charset = null, int $flags = 0)
|
|
|
78 |
{
|
|
|
79 |
AbstractDumper::__construct($output, $charset, $flags);
|
|
|
80 |
$this->dumpId = 'sf-dump-'.mt_rand();
|
|
|
81 |
$this->displayOptions['fileLinkFormat'] = \ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
|
|
|
82 |
$this->styles = static::$themes['dark'] ?? self::$themes['dark'];
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
public function setStyles(array $styles)
|
|
|
86 |
{
|
|
|
87 |
$this->headerIsDumped = false;
|
|
|
88 |
$this->styles = $styles + $this->styles;
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
public function setTheme(string $themeName)
|
|
|
92 |
{
|
|
|
93 |
if (!isset(static::$themes[$themeName])) {
|
|
|
94 |
throw new \InvalidArgumentException(sprintf('Theme "%s" does not exist in class "%s".', $themeName, static::class));
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
$this->setStyles(static::$themes[$themeName]);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
/**
|
|
|
101 |
* Configures display options.
|
|
|
102 |
*
|
|
|
103 |
* @param array $displayOptions A map of display options to customize the behavior
|
|
|
104 |
*/
|
|
|
105 |
public function setDisplayOptions(array $displayOptions)
|
|
|
106 |
{
|
|
|
107 |
$this->headerIsDumped = false;
|
|
|
108 |
$this->displayOptions = $displayOptions + $this->displayOptions;
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
/**
|
|
|
112 |
* Sets an HTML header that will be dumped once in the output stream.
|
|
|
113 |
*/
|
|
|
114 |
public function setDumpHeader(?string $header)
|
|
|
115 |
{
|
|
|
116 |
$this->dumpHeader = $header;
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
/**
|
|
|
120 |
* Sets an HTML prefix and suffix that will encapse every single dump.
|
|
|
121 |
*/
|
|
|
122 |
public function setDumpBoundaries(string $prefix, string $suffix)
|
|
|
123 |
{
|
|
|
124 |
$this->dumpPrefix = $prefix;
|
|
|
125 |
$this->dumpSuffix = $suffix;
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
public function dump(Data $data, $output = null, array $extraDisplayOptions = []): ?string
|
|
|
129 |
{
|
|
|
130 |
$this->extraDisplayOptions = $extraDisplayOptions;
|
|
|
131 |
$result = parent::dump($data, $output);
|
|
|
132 |
$this->dumpId = 'sf-dump-'.mt_rand();
|
|
|
133 |
|
|
|
134 |
return $result;
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
/**
|
|
|
138 |
* Dumps the HTML header.
|
|
|
139 |
*/
|
|
|
140 |
protected function getDumpHeader()
|
|
|
141 |
{
|
|
|
142 |
$this->headerIsDumped = $this->outputStream ?? $this->lineDumper;
|
|
|
143 |
|
|
|
144 |
if (null !== $this->dumpHeader) {
|
|
|
145 |
return $this->dumpHeader;
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
$line = str_replace('{$options}', json_encode($this->displayOptions, \JSON_FORCE_OBJECT), <<<'EOHTML'
|
|
|
149 |
<script>
|
|
|
150 |
Sfdump = window.Sfdump || (function (doc) {
|
|
|
151 |
|
|
|
152 |
var refStyle = doc.createElement('style'),
|
|
|
153 |
rxEsc = /([.*+?^${}()|\[\]\/\\])/g,
|
|
|
154 |
idRx = /\bsf-dump-\d+-ref[012]\w+\b/,
|
|
|
155 |
keyHint = 0 <= navigator.platform.toUpperCase().indexOf('MAC') ? 'Cmd' : 'Ctrl',
|
|
|
156 |
addEventListener = function (e, n, cb) {
|
|
|
157 |
e.addEventListener(n, cb, false);
|
|
|
158 |
};
|
|
|
159 |
|
|
|
160 |
refStyle.innerHTML = 'pre.sf-dump .sf-dump-compact, .sf-dump-str-collapse .sf-dump-str-collapse, .sf-dump-str-expand .sf-dump-str-expand { display: none; }';
|
| 200 |
lars |
161 |
doc.head.appendChild(refStyle);
|
| 148 |
lars |
162 |
refStyle = doc.createElement('style');
|
| 200 |
lars |
163 |
doc.head.appendChild(refStyle);
|
| 148 |
lars |
164 |
|
|
|
165 |
if (!doc.addEventListener) {
|
|
|
166 |
addEventListener = function (element, eventName, callback) {
|
|
|
167 |
element.attachEvent('on' + eventName, function (e) {
|
|
|
168 |
e.preventDefault = function () {e.returnValue = false;};
|
|
|
169 |
e.target = e.srcElement;
|
|
|
170 |
callback(e);
|
|
|
171 |
});
|
|
|
172 |
};
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
function toggle(a, recursive) {
|
|
|
176 |
var s = a.nextSibling || {}, oldClass = s.className, arrow, newClass;
|
|
|
177 |
|
|
|
178 |
if (/\bsf-dump-compact\b/.test(oldClass)) {
|
|
|
179 |
arrow = 'â–¼';
|
|
|
180 |
newClass = 'sf-dump-expanded';
|
|
|
181 |
} else if (/\bsf-dump-expanded\b/.test(oldClass)) {
|
|
|
182 |
arrow = 'â–¶';
|
|
|
183 |
newClass = 'sf-dump-compact';
|
|
|
184 |
} else {
|
|
|
185 |
return false;
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
if (doc.createEvent && s.dispatchEvent) {
|
|
|
189 |
var event = doc.createEvent('Event');
|
|
|
190 |
event.initEvent('sf-dump-expanded' === newClass ? 'sfbeforedumpexpand' : 'sfbeforedumpcollapse', true, false);
|
|
|
191 |
|
|
|
192 |
s.dispatchEvent(event);
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
a.lastChild.innerHTML = arrow;
|
|
|
196 |
s.className = s.className.replace(/\bsf-dump-(compact|expanded)\b/, newClass);
|
|
|
197 |
|
|
|
198 |
if (recursive) {
|
|
|
199 |
try {
|
|
|
200 |
a = s.querySelectorAll('.'+oldClass);
|
|
|
201 |
for (s = 0; s < a.length; ++s) {
|
|
|
202 |
if (-1 == a[s].className.indexOf(newClass)) {
|
|
|
203 |
a[s].className = newClass;
|
|
|
204 |
a[s].previousSibling.lastChild.innerHTML = arrow;
|
|
|
205 |
}
|
|
|
206 |
}
|
|
|
207 |
} catch (e) {
|
|
|
208 |
}
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
return true;
|
|
|
212 |
};
|
|
|
213 |
|
|
|
214 |
function collapse(a, recursive) {
|
|
|
215 |
var s = a.nextSibling || {}, oldClass = s.className;
|
|
|
216 |
|
|
|
217 |
if (/\bsf-dump-expanded\b/.test(oldClass)) {
|
|
|
218 |
toggle(a, recursive);
|
|
|
219 |
|
|
|
220 |
return true;
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
return false;
|
|
|
224 |
};
|
|
|
225 |
|
|
|
226 |
function expand(a, recursive) {
|
|
|
227 |
var s = a.nextSibling || {}, oldClass = s.className;
|
|
|
228 |
|
|
|
229 |
if (/\bsf-dump-compact\b/.test(oldClass)) {
|
|
|
230 |
toggle(a, recursive);
|
|
|
231 |
|
|
|
232 |
return true;
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
return false;
|
|
|
236 |
};
|
|
|
237 |
|
|
|
238 |
function collapseAll(root) {
|
|
|
239 |
var a = root.querySelector('a.sf-dump-toggle');
|
|
|
240 |
if (a) {
|
|
|
241 |
collapse(a, true);
|
|
|
242 |
expand(a);
|
|
|
243 |
|
|
|
244 |
return true;
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
return false;
|
|
|
248 |
}
|
|
|
249 |
|
|
|
250 |
function reveal(node) {
|
|
|
251 |
var previous, parents = [];
|
|
|
252 |
|
|
|
253 |
while ((node = node.parentNode || {}) && (previous = node.previousSibling) && 'A' === previous.tagName) {
|
|
|
254 |
parents.push(previous);
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
if (0 !== parents.length) {
|
|
|
258 |
parents.forEach(function (parent) {
|
|
|
259 |
expand(parent);
|
|
|
260 |
});
|
|
|
261 |
|
|
|
262 |
return true;
|
|
|
263 |
}
|
|
|
264 |
|
|
|
265 |
return false;
|
|
|
266 |
}
|
|
|
267 |
|
|
|
268 |
function highlight(root, activeNode, nodes) {
|
|
|
269 |
resetHighlightedNodes(root);
|
|
|
270 |
|
|
|
271 |
Array.from(nodes||[]).forEach(function (node) {
|
|
|
272 |
if (!/\bsf-dump-highlight\b/.test(node.className)) {
|
|
|
273 |
node.className = node.className + ' sf-dump-highlight';
|
|
|
274 |
}
|
|
|
275 |
});
|
|
|
276 |
|
|
|
277 |
if (!/\bsf-dump-highlight-active\b/.test(activeNode.className)) {
|
|
|
278 |
activeNode.className = activeNode.className + ' sf-dump-highlight-active';
|
|
|
279 |
}
|
|
|
280 |
}
|
|
|
281 |
|
|
|
282 |
function resetHighlightedNodes(root) {
|
|
|
283 |
Array.from(root.querySelectorAll('.sf-dump-str, .sf-dump-key, .sf-dump-public, .sf-dump-protected, .sf-dump-private')).forEach(function (strNode) {
|
|
|
284 |
strNode.className = strNode.className.replace(/\bsf-dump-highlight\b/, '');
|
|
|
285 |
strNode.className = strNode.className.replace(/\bsf-dump-highlight-active\b/, '');
|
|
|
286 |
});
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
return function (root, x) {
|
|
|
290 |
root = doc.getElementById(root);
|
|
|
291 |
|
|
|
292 |
var indentRx = new RegExp('^('+(root.getAttribute('data-indent-pad') || ' ').replace(rxEsc, '\\$1')+')+', 'm'),
|
|
|
293 |
options = {$options},
|
|
|
294 |
elt = root.getElementsByTagName('A'),
|
|
|
295 |
len = elt.length,
|
|
|
296 |
i = 0, s, h,
|
|
|
297 |
t = [];
|
|
|
298 |
|
|
|
299 |
while (i < len) t.push(elt[i++]);
|
|
|
300 |
|
|
|
301 |
for (i in x) {
|
|
|
302 |
options[i] = x[i];
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
function a(e, f) {
|
|
|
306 |
addEventListener(root, e, function (e, n) {
|
|
|
307 |
if ('A' == e.target.tagName) {
|
|
|
308 |
f(e.target, e);
|
|
|
309 |
} else if ('A' == e.target.parentNode.tagName) {
|
|
|
310 |
f(e.target.parentNode, e);
|
|
|
311 |
} else {
|
|
|
312 |
n = /\bsf-dump-ellipsis\b/.test(e.target.className) ? e.target.parentNode : e.target;
|
|
|
313 |
|
|
|
314 |
if ((n = n.nextElementSibling) && 'A' == n.tagName) {
|
|
|
315 |
if (!/\bsf-dump-toggle\b/.test(n.className)) {
|
|
|
316 |
n = n.nextElementSibling || n;
|
|
|
317 |
}
|
|
|
318 |
|
|
|
319 |
f(n, e, true);
|
|
|
320 |
}
|
|
|
321 |
}
|
|
|
322 |
});
|
|
|
323 |
};
|
|
|
324 |
function isCtrlKey(e) {
|
|
|
325 |
return e.ctrlKey || e.metaKey;
|
|
|
326 |
}
|
|
|
327 |
function xpathString(str) {
|
|
|
328 |
var parts = str.match(/[^'"]+|['"]/g).map(function (part) {
|
|
|
329 |
if ("'" == part) {
|
|
|
330 |
return '"\'"';
|
|
|
331 |
}
|
|
|
332 |
if ('"' == part) {
|
|
|
333 |
return "'\"'";
|
|
|
334 |
}
|
|
|
335 |
|
|
|
336 |
return "'" + part + "'";
|
|
|
337 |
});
|
|
|
338 |
|
|
|
339 |
return "concat(" + parts.join(",") + ", '')";
|
|
|
340 |
}
|
|
|
341 |
function xpathHasClass(className) {
|
|
|
342 |
return "contains(concat(' ', normalize-space(@class), ' '), ' " + className +" ')";
|
|
|
343 |
}
|
|
|
344 |
addEventListener(root, 'mouseover', function (e) {
|
|
|
345 |
if ('' != refStyle.innerHTML) {
|
|
|
346 |
refStyle.innerHTML = '';
|
|
|
347 |
}
|
|
|
348 |
});
|
|
|
349 |
a('mouseover', function (a, e, c) {
|
|
|
350 |
if (c) {
|
|
|
351 |
e.target.style.cursor = "pointer";
|
|
|
352 |
} else if (a = idRx.exec(a.className)) {
|
|
|
353 |
try {
|
|
|
354 |
refStyle.innerHTML = 'pre.sf-dump .'+a[0]+'{background-color: #B729D9; color: #FFF !important; border-radius: 2px}';
|
|
|
355 |
} catch (e) {
|
|
|
356 |
}
|
|
|
357 |
}
|
|
|
358 |
});
|
|
|
359 |
a('click', function (a, e, c) {
|
|
|
360 |
if (/\bsf-dump-toggle\b/.test(a.className)) {
|
|
|
361 |
e.preventDefault();
|
|
|
362 |
if (!toggle(a, isCtrlKey(e))) {
|
|
|
363 |
var r = doc.getElementById(a.getAttribute('href').slice(1)),
|
|
|
364 |
s = r.previousSibling,
|
|
|
365 |
f = r.parentNode,
|
|
|
366 |
t = a.parentNode;
|
|
|
367 |
t.replaceChild(r, a);
|
|
|
368 |
f.replaceChild(a, s);
|
|
|
369 |
t.insertBefore(s, r);
|
|
|
370 |
f = f.firstChild.nodeValue.match(indentRx);
|
|
|
371 |
t = t.firstChild.nodeValue.match(indentRx);
|
|
|
372 |
if (f && t && f[0] !== t[0]) {
|
|
|
373 |
r.innerHTML = r.innerHTML.replace(new RegExp('^'+f[0].replace(rxEsc, '\\$1'), 'mg'), t[0]);
|
|
|
374 |
}
|
|
|
375 |
if (/\bsf-dump-compact\b/.test(r.className)) {
|
|
|
376 |
toggle(s, isCtrlKey(e));
|
|
|
377 |
}
|
|
|
378 |
}
|
|
|
379 |
|
|
|
380 |
if (c) {
|
|
|
381 |
} else if (doc.getSelection) {
|
|
|
382 |
try {
|
|
|
383 |
doc.getSelection().removeAllRanges();
|
|
|
384 |
} catch (e) {
|
|
|
385 |
doc.getSelection().empty();
|
|
|
386 |
}
|
|
|
387 |
} else {
|
|
|
388 |
doc.selection.empty();
|
|
|
389 |
}
|
|
|
390 |
} else if (/\bsf-dump-str-toggle\b/.test(a.className)) {
|
|
|
391 |
e.preventDefault();
|
|
|
392 |
e = a.parentNode.parentNode;
|
|
|
393 |
e.className = e.className.replace(/\bsf-dump-str-(expand|collapse)\b/, a.parentNode.className);
|
|
|
394 |
}
|
|
|
395 |
});
|
|
|
396 |
|
|
|
397 |
elt = root.getElementsByTagName('SAMP');
|
|
|
398 |
len = elt.length;
|
|
|
399 |
i = 0;
|
|
|
400 |
|
|
|
401 |
while (i < len) t.push(elt[i++]);
|
|
|
402 |
len = t.length;
|
|
|
403 |
|
|
|
404 |
for (i = 0; i < len; ++i) {
|
|
|
405 |
elt = t[i];
|
|
|
406 |
if ('SAMP' == elt.tagName) {
|
|
|
407 |
a = elt.previousSibling || {};
|
|
|
408 |
if ('A' != a.tagName) {
|
|
|
409 |
a = doc.createElement('A');
|
|
|
410 |
a.className = 'sf-dump-ref';
|
|
|
411 |
elt.parentNode.insertBefore(a, elt);
|
|
|
412 |
} else {
|
|
|
413 |
a.innerHTML += ' ';
|
|
|
414 |
}
|
|
|
415 |
a.title = (a.title ? a.title+'\n[' : '[')+keyHint+'+click] Expand all children';
|
|
|
416 |
a.innerHTML += elt.className == 'sf-dump-compact' ? '<span>â–¶</span>' : '<span>â–¼</span>';
|
|
|
417 |
a.className += ' sf-dump-toggle';
|
|
|
418 |
|
|
|
419 |
x = 1;
|
|
|
420 |
if ('sf-dump' != elt.parentNode.className) {
|
|
|
421 |
x += elt.parentNode.getAttribute('data-depth')/1;
|
|
|
422 |
}
|
|
|
423 |
} else if (/\bsf-dump-ref\b/.test(elt.className) && (a = elt.getAttribute('href'))) {
|
|
|
424 |
a = a.slice(1);
|
|
|
425 |
elt.className += ' '+a;
|
|
|
426 |
|
|
|
427 |
if (/[\[{]$/.test(elt.previousSibling.nodeValue)) {
|
|
|
428 |
a = a != elt.nextSibling.id && doc.getElementById(a);
|
|
|
429 |
try {
|
|
|
430 |
s = a.nextSibling;
|
|
|
431 |
elt.appendChild(a);
|
|
|
432 |
s.parentNode.insertBefore(a, s);
|
|
|
433 |
if (/^[@#]/.test(elt.innerHTML)) {
|
|
|
434 |
elt.innerHTML += ' <span>â–¶</span>';
|
|
|
435 |
} else {
|
|
|
436 |
elt.innerHTML = '<span>â–¶</span>';
|
|
|
437 |
elt.className = 'sf-dump-ref';
|
|
|
438 |
}
|
|
|
439 |
elt.className += ' sf-dump-toggle';
|
|
|
440 |
} catch (e) {
|
|
|
441 |
if ('&' == elt.innerHTML.charAt(0)) {
|
|
|
442 |
elt.innerHTML = '…';
|
|
|
443 |
elt.className = 'sf-dump-ref';
|
|
|
444 |
}
|
|
|
445 |
}
|
|
|
446 |
}
|
|
|
447 |
}
|
|
|
448 |
}
|
|
|
449 |
|
|
|
450 |
if (doc.evaluate && Array.from && root.children.length > 1) {
|
|
|
451 |
root.setAttribute('tabindex', 0);
|
|
|
452 |
|
|
|
453 |
SearchState = function () {
|
|
|
454 |
this.nodes = [];
|
|
|
455 |
this.idx = 0;
|
|
|
456 |
};
|
|
|
457 |
SearchState.prototype = {
|
|
|
458 |
next: function () {
|
|
|
459 |
if (this.isEmpty()) {
|
|
|
460 |
return this.current();
|
|
|
461 |
}
|
|
|
462 |
this.idx = this.idx < (this.nodes.length - 1) ? this.idx + 1 : 0;
|
|
|
463 |
|
|
|
464 |
return this.current();
|
|
|
465 |
},
|
|
|
466 |
previous: function () {
|
|
|
467 |
if (this.isEmpty()) {
|
|
|
468 |
return this.current();
|
|
|
469 |
}
|
|
|
470 |
this.idx = this.idx > 0 ? this.idx - 1 : (this.nodes.length - 1);
|
|
|
471 |
|
|
|
472 |
return this.current();
|
|
|
473 |
},
|
|
|
474 |
isEmpty: function () {
|
|
|
475 |
return 0 === this.count();
|
|
|
476 |
},
|
|
|
477 |
current: function () {
|
|
|
478 |
if (this.isEmpty()) {
|
|
|
479 |
return null;
|
|
|
480 |
}
|
|
|
481 |
return this.nodes[this.idx];
|
|
|
482 |
},
|
|
|
483 |
reset: function () {
|
|
|
484 |
this.nodes = [];
|
|
|
485 |
this.idx = 0;
|
|
|
486 |
},
|
|
|
487 |
count: function () {
|
|
|
488 |
return this.nodes.length;
|
|
|
489 |
},
|
|
|
490 |
};
|
|
|
491 |
|
|
|
492 |
function showCurrent(state)
|
|
|
493 |
{
|
|
|
494 |
var currentNode = state.current(), currentRect, searchRect;
|
|
|
495 |
if (currentNode) {
|
|
|
496 |
reveal(currentNode);
|
|
|
497 |
highlight(root, currentNode, state.nodes);
|
|
|
498 |
if ('scrollIntoView' in currentNode) {
|
|
|
499 |
currentNode.scrollIntoView(true);
|
|
|
500 |
currentRect = currentNode.getBoundingClientRect();
|
|
|
501 |
searchRect = search.getBoundingClientRect();
|
|
|
502 |
if (currentRect.top < (searchRect.top + searchRect.height)) {
|
|
|
503 |
window.scrollBy(0, -(searchRect.top + searchRect.height + 5));
|
|
|
504 |
}
|
|
|
505 |
}
|
|
|
506 |
}
|
|
|
507 |
counter.textContent = (state.isEmpty() ? 0 : state.idx + 1) + ' of ' + state.count();
|
|
|
508 |
}
|
|
|
509 |
|
|
|
510 |
var search = doc.createElement('div');
|
|
|
511 |
search.className = 'sf-dump-search-wrapper sf-dump-search-hidden';
|
|
|
512 |
search.innerHTML = '
|
|
|
513 |
<input type="text" class="sf-dump-search-input">
|
|
|
514 |
<span class="sf-dump-search-count">0 of 0<\/span>
|
|
|
515 |
<button type="button" class="sf-dump-search-input-previous" tabindex="-1">
|
|
|
516 |
<svg viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1683 1331l-166 165q-19 19-45 19t-45-19L896 965l-531 531q-19 19-45 19t-45-19l-166-165q-19-19-19-45.5t19-45.5l742-741q19-19 45-19t45 19l742 741q19 19 19 45.5t-19 45.5z"\/><\/svg>
|
|
|
517 |
<\/button>
|
|
|
518 |
<button type="button" class="sf-dump-search-input-next" tabindex="-1">
|
|
|
519 |
<svg viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg"><path d="M1683 808l-742 741q-19 19-45 19t-45-19L109 808q-19-19-19-45.5t19-45.5l166-165q19-19 45-19t45 19l531 531 531-531q19-19 45-19t45 19l166 165q19 19 19 45.5t-19 45.5z"\/><\/svg>
|
|
|
520 |
<\/button>
|
|
|
521 |
';
|
|
|
522 |
root.insertBefore(search, root.firstChild);
|
|
|
523 |
|
|
|
524 |
var state = new SearchState();
|
|
|
525 |
var searchInput = search.querySelector('.sf-dump-search-input');
|
|
|
526 |
var counter = search.querySelector('.sf-dump-search-count');
|
|
|
527 |
var searchInputTimer = 0;
|
|
|
528 |
var previousSearchQuery = '';
|
|
|
529 |
|
|
|
530 |
addEventListener(searchInput, 'keyup', function (e) {
|
|
|
531 |
var searchQuery = e.target.value;
|
|
|
532 |
/* Don't perform anything if the pressed key didn't change the query */
|
|
|
533 |
if (searchQuery === previousSearchQuery) {
|
|
|
534 |
return;
|
|
|
535 |
}
|
|
|
536 |
previousSearchQuery = searchQuery;
|
|
|
537 |
clearTimeout(searchInputTimer);
|
|
|
538 |
searchInputTimer = setTimeout(function () {
|
|
|
539 |
state.reset();
|
|
|
540 |
collapseAll(root);
|
|
|
541 |
resetHighlightedNodes(root);
|
|
|
542 |
if ('' === searchQuery) {
|
|
|
543 |
counter.textContent = '0 of 0';
|
|
|
544 |
|
|
|
545 |
return;
|
|
|
546 |
}
|
|
|
547 |
|
|
|
548 |
var classMatches = [
|
|
|
549 |
"sf-dump-str",
|
|
|
550 |
"sf-dump-key",
|
|
|
551 |
"sf-dump-public",
|
|
|
552 |
"sf-dump-protected",
|
|
|
553 |
"sf-dump-private",
|
|
|
554 |
].map(xpathHasClass).join(' or ');
|
|
|
555 |
|
|
|
556 |
var xpathResult = doc.evaluate('.//span[' + classMatches + '][contains(translate(child::text(), ' + xpathString(searchQuery.toUpperCase()) + ', ' + xpathString(searchQuery.toLowerCase()) + '), ' + xpathString(searchQuery.toLowerCase()) + ')]', root, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
|
|
|
557 |
|
|
|
558 |
while (node = xpathResult.iterateNext()) state.nodes.push(node);
|
|
|
559 |
|
|
|
560 |
showCurrent(state);
|
|
|
561 |
}, 400);
|
|
|
562 |
});
|
|
|
563 |
|
|
|
564 |
Array.from(search.querySelectorAll('.sf-dump-search-input-next, .sf-dump-search-input-previous')).forEach(function (btn) {
|
|
|
565 |
addEventListener(btn, 'click', function (e) {
|
|
|
566 |
e.preventDefault();
|
|
|
567 |
-1 !== e.target.className.indexOf('next') ? state.next() : state.previous();
|
|
|
568 |
searchInput.focus();
|
|
|
569 |
collapseAll(root);
|
|
|
570 |
showCurrent(state);
|
|
|
571 |
})
|
|
|
572 |
});
|
|
|
573 |
|
|
|
574 |
addEventListener(root, 'keydown', function (e) {
|
|
|
575 |
var isSearchActive = !/\bsf-dump-search-hidden\b/.test(search.className);
|
|
|
576 |
if ((114 === e.keyCode && !isSearchActive) || (isCtrlKey(e) && 70 === e.keyCode)) {
|
|
|
577 |
/* F3 or CMD/CTRL + F */
|
|
|
578 |
if (70 === e.keyCode && document.activeElement === searchInput) {
|
|
|
579 |
/*
|
|
|
580 |
* If CMD/CTRL + F is hit while having focus on search input,
|
|
|
581 |
* the user probably meant to trigger browser search instead.
|
|
|
582 |
* Let the browser execute its behavior:
|
|
|
583 |
*/
|
|
|
584 |
return;
|
|
|
585 |
}
|
|
|
586 |
|
|
|
587 |
e.preventDefault();
|
|
|
588 |
search.className = search.className.replace(/\bsf-dump-search-hidden\b/, '');
|
|
|
589 |
searchInput.focus();
|
|
|
590 |
} else if (isSearchActive) {
|
|
|
591 |
if (27 === e.keyCode) {
|
|
|
592 |
/* ESC key */
|
|
|
593 |
search.className += ' sf-dump-search-hidden';
|
|
|
594 |
e.preventDefault();
|
|
|
595 |
resetHighlightedNodes(root);
|
|
|
596 |
searchInput.value = '';
|
|
|
597 |
} else if (
|
|
|
598 |
(isCtrlKey(e) && 71 === e.keyCode) /* CMD/CTRL + G */
|
|
|
599 |
|| 13 === e.keyCode /* Enter */
|
|
|
600 |
|| 114 === e.keyCode /* F3 */
|
|
|
601 |
) {
|
|
|
602 |
e.preventDefault();
|
|
|
603 |
e.shiftKey ? state.previous() : state.next();
|
|
|
604 |
collapseAll(root);
|
|
|
605 |
showCurrent(state);
|
|
|
606 |
}
|
|
|
607 |
}
|
|
|
608 |
});
|
|
|
609 |
}
|
|
|
610 |
|
|
|
611 |
if (0 >= options.maxStringLength) {
|
|
|
612 |
return;
|
|
|
613 |
}
|
|
|
614 |
try {
|
|
|
615 |
elt = root.querySelectorAll('.sf-dump-str');
|
|
|
616 |
len = elt.length;
|
|
|
617 |
i = 0;
|
|
|
618 |
t = [];
|
|
|
619 |
|
|
|
620 |
while (i < len) t.push(elt[i++]);
|
|
|
621 |
len = t.length;
|
|
|
622 |
|
|
|
623 |
for (i = 0; i < len; ++i) {
|
|
|
624 |
elt = t[i];
|
|
|
625 |
s = elt.innerText || elt.textContent;
|
|
|
626 |
x = s.length - options.maxStringLength;
|
|
|
627 |
if (0 < x) {
|
|
|
628 |
h = elt.innerHTML;
|
|
|
629 |
elt[elt.innerText ? 'innerText' : 'textContent'] = s.substring(0, options.maxStringLength);
|
|
|
630 |
elt.className += ' sf-dump-str-collapse';
|
|
|
631 |
elt.innerHTML = '<span class=sf-dump-str-collapse>'+h+'<a class="sf-dump-ref sf-dump-str-toggle" title="Collapse"> â—€</a></span>'+
|
|
|
632 |
'<span class=sf-dump-str-expand>'+elt.innerHTML+'<a class="sf-dump-ref sf-dump-str-toggle" title="'+x+' remaining characters"> â–¶</a></span>';
|
|
|
633 |
}
|
|
|
634 |
}
|
|
|
635 |
} catch (e) {
|
|
|
636 |
}
|
|
|
637 |
};
|
|
|
638 |
|
|
|
639 |
})(document);
|
|
|
640 |
</script><style>
|
|
|
641 |
pre.sf-dump {
|
|
|
642 |
display: block;
|
|
|
643 |
white-space: pre;
|
|
|
644 |
padding: 5px;
|
|
|
645 |
overflow: initial !important;
|
|
|
646 |
}
|
|
|
647 |
pre.sf-dump:after {
|
|
|
648 |
content: "";
|
|
|
649 |
visibility: hidden;
|
|
|
650 |
display: block;
|
|
|
651 |
height: 0;
|
|
|
652 |
clear: both;
|
|
|
653 |
}
|
|
|
654 |
pre.sf-dump span {
|
|
|
655 |
display: inline;
|
|
|
656 |
}
|
|
|
657 |
pre.sf-dump a {
|
|
|
658 |
text-decoration: none;
|
|
|
659 |
cursor: pointer;
|
|
|
660 |
border: 0;
|
|
|
661 |
outline: none;
|
|
|
662 |
color: inherit;
|
|
|
663 |
}
|
|
|
664 |
pre.sf-dump img {
|
|
|
665 |
max-width: 50em;
|
|
|
666 |
max-height: 50em;
|
|
|
667 |
margin: .5em 0 0 0;
|
|
|
668 |
padding: 0;
|
|
|
669 |
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAAAAAA6mKC9AAAAHUlEQVQY02O8zAABilCaiQEN0EeA8QuUcX9g3QEAAjcC5piyhyEAAAAASUVORK5CYII=) #D3D3D3;
|
|
|
670 |
}
|
|
|
671 |
pre.sf-dump .sf-dump-ellipsis {
|
|
|
672 |
display: inline-block;
|
|
|
673 |
overflow: visible;
|
|
|
674 |
text-overflow: ellipsis;
|
|
|
675 |
max-width: 5em;
|
|
|
676 |
white-space: nowrap;
|
|
|
677 |
overflow: hidden;
|
|
|
678 |
vertical-align: top;
|
|
|
679 |
}
|
|
|
680 |
pre.sf-dump .sf-dump-ellipsis+.sf-dump-ellipsis {
|
|
|
681 |
max-width: none;
|
|
|
682 |
}
|
|
|
683 |
pre.sf-dump code {
|
|
|
684 |
display:inline;
|
|
|
685 |
padding:0;
|
|
|
686 |
background:none;
|
|
|
687 |
}
|
|
|
688 |
.sf-dump-public.sf-dump-highlight,
|
|
|
689 |
.sf-dump-protected.sf-dump-highlight,
|
|
|
690 |
.sf-dump-private.sf-dump-highlight,
|
|
|
691 |
.sf-dump-str.sf-dump-highlight,
|
|
|
692 |
.sf-dump-key.sf-dump-highlight {
|
|
|
693 |
background: rgba(111, 172, 204, 0.3);
|
|
|
694 |
border: 1px solid #7DA0B1;
|
|
|
695 |
border-radius: 3px;
|
|
|
696 |
}
|
|
|
697 |
.sf-dump-public.sf-dump-highlight-active,
|
|
|
698 |
.sf-dump-protected.sf-dump-highlight-active,
|
|
|
699 |
.sf-dump-private.sf-dump-highlight-active,
|
|
|
700 |
.sf-dump-str.sf-dump-highlight-active,
|
|
|
701 |
.sf-dump-key.sf-dump-highlight-active {
|
|
|
702 |
background: rgba(253, 175, 0, 0.4);
|
|
|
703 |
border: 1px solid #ffa500;
|
|
|
704 |
border-radius: 3px;
|
|
|
705 |
}
|
|
|
706 |
pre.sf-dump .sf-dump-search-hidden {
|
|
|
707 |
display: none !important;
|
|
|
708 |
}
|
|
|
709 |
pre.sf-dump .sf-dump-search-wrapper {
|
|
|
710 |
font-size: 0;
|
|
|
711 |
white-space: nowrap;
|
|
|
712 |
margin-bottom: 5px;
|
|
|
713 |
display: flex;
|
|
|
714 |
position: -webkit-sticky;
|
|
|
715 |
position: sticky;
|
|
|
716 |
top: 5px;
|
|
|
717 |
}
|
|
|
718 |
pre.sf-dump .sf-dump-search-wrapper > * {
|
|
|
719 |
vertical-align: top;
|
|
|
720 |
box-sizing: border-box;
|
|
|
721 |
height: 21px;
|
|
|
722 |
font-weight: normal;
|
|
|
723 |
border-radius: 0;
|
|
|
724 |
background: #FFF;
|
|
|
725 |
color: #757575;
|
|
|
726 |
border: 1px solid #BBB;
|
|
|
727 |
}
|
|
|
728 |
pre.sf-dump .sf-dump-search-wrapper > input.sf-dump-search-input {
|
|
|
729 |
padding: 3px;
|
|
|
730 |
height: 21px;
|
|
|
731 |
font-size: 12px;
|
|
|
732 |
border-right: none;
|
|
|
733 |
border-top-left-radius: 3px;
|
|
|
734 |
border-bottom-left-radius: 3px;
|
|
|
735 |
color: #000;
|
|
|
736 |
min-width: 15px;
|
|
|
737 |
width: 100%;
|
|
|
738 |
}
|
|
|
739 |
pre.sf-dump .sf-dump-search-wrapper > .sf-dump-search-input-next,
|
|
|
740 |
pre.sf-dump .sf-dump-search-wrapper > .sf-dump-search-input-previous {
|
|
|
741 |
background: #F2F2F2;
|
|
|
742 |
outline: none;
|
|
|
743 |
border-left: none;
|
|
|
744 |
font-size: 0;
|
|
|
745 |
line-height: 0;
|
|
|
746 |
}
|
|
|
747 |
pre.sf-dump .sf-dump-search-wrapper > .sf-dump-search-input-next {
|
|
|
748 |
border-top-right-radius: 3px;
|
|
|
749 |
border-bottom-right-radius: 3px;
|
|
|
750 |
}
|
|
|
751 |
pre.sf-dump .sf-dump-search-wrapper > .sf-dump-search-input-next > svg,
|
|
|
752 |
pre.sf-dump .sf-dump-search-wrapper > .sf-dump-search-input-previous > svg {
|
|
|
753 |
pointer-events: none;
|
|
|
754 |
width: 12px;
|
|
|
755 |
height: 12px;
|
|
|
756 |
}
|
|
|
757 |
pre.sf-dump .sf-dump-search-wrapper > .sf-dump-search-count {
|
|
|
758 |
display: inline-block;
|
|
|
759 |
padding: 0 5px;
|
|
|
760 |
margin: 0;
|
|
|
761 |
border-left: none;
|
|
|
762 |
line-height: 21px;
|
|
|
763 |
font-size: 12px;
|
|
|
764 |
}
|
|
|
765 |
EOHTML
|
|
|
766 |
);
|
|
|
767 |
|
|
|
768 |
foreach ($this->styles as $class => $style) {
|
|
|
769 |
$line .= 'pre.sf-dump'.('default' === $class ? ', pre.sf-dump' : '').' .sf-dump-'.$class.'{'.$style.'}';
|
|
|
770 |
}
|
|
|
771 |
$line .= 'pre.sf-dump .sf-dump-ellipsis-note{'.$this->styles['note'].'}';
|
|
|
772 |
|
|
|
773 |
return $this->dumpHeader = preg_replace('/\s+/', ' ', $line).'</style>'.$this->dumpHeader;
|
|
|
774 |
}
|
|
|
775 |
|
|
|
776 |
public function dumpString(Cursor $cursor, string $str, bool $bin, int $cut)
|
|
|
777 |
{
|
|
|
778 |
if ('' === $str && isset($cursor->attr['img-data'], $cursor->attr['content-type'])) {
|
|
|
779 |
$this->dumpKey($cursor);
|
|
|
780 |
$this->line .= $this->style('default', $cursor->attr['img-size'] ?? '', []);
|
|
|
781 |
$this->line .= $cursor->depth >= $this->displayOptions['maxDepth'] ? ' <samp class=sf-dump-compact>' : ' <samp class=sf-dump-expanded>';
|
|
|
782 |
$this->endValue($cursor);
|
|
|
783 |
$this->line .= $this->indentPad;
|
|
|
784 |
$this->line .= sprintf('<img src="data:%s;base64,%s" /></samp>', $cursor->attr['content-type'], base64_encode($cursor->attr['img-data']));
|
|
|
785 |
$this->endValue($cursor);
|
|
|
786 |
} else {
|
|
|
787 |
parent::dumpString($cursor, $str, $bin, $cut);
|
|
|
788 |
}
|
|
|
789 |
}
|
|
|
790 |
|
|
|
791 |
public function enterHash(Cursor $cursor, int $type, string|int|null $class, bool $hasChild)
|
|
|
792 |
{
|
|
|
793 |
if (Cursor::HASH_OBJECT === $type) {
|
|
|
794 |
$cursor->attr['depth'] = $cursor->depth;
|
|
|
795 |
}
|
|
|
796 |
parent::enterHash($cursor, $type, $class, false);
|
|
|
797 |
|
|
|
798 |
if ($cursor->skipChildren || $cursor->depth >= $this->displayOptions['maxDepth']) {
|
|
|
799 |
$cursor->skipChildren = false;
|
|
|
800 |
$eol = ' class=sf-dump-compact>';
|
|
|
801 |
} else {
|
|
|
802 |
$this->expandNextHash = false;
|
|
|
803 |
$eol = ' class=sf-dump-expanded>';
|
|
|
804 |
}
|
|
|
805 |
|
|
|
806 |
if ($hasChild) {
|
|
|
807 |
$this->line .= '<samp data-depth='.($cursor->depth + 1);
|
|
|
808 |
if ($cursor->refIndex) {
|
|
|
809 |
$r = Cursor::HASH_OBJECT !== $type ? 1 - (Cursor::HASH_RESOURCE !== $type) : 2;
|
|
|
810 |
$r .= $r && 0 < $cursor->softRefHandle ? $cursor->softRefHandle : $cursor->refIndex;
|
|
|
811 |
|
|
|
812 |
$this->line .= sprintf(' id=%s-ref%s', $this->dumpId, $r);
|
|
|
813 |
}
|
|
|
814 |
$this->line .= $eol;
|
|
|
815 |
$this->dumpLine($cursor->depth);
|
|
|
816 |
}
|
|
|
817 |
}
|
|
|
818 |
|
|
|
819 |
public function leaveHash(Cursor $cursor, int $type, string|int|null $class, bool $hasChild, int $cut)
|
|
|
820 |
{
|
|
|
821 |
$this->dumpEllipsis($cursor, $hasChild, $cut);
|
|
|
822 |
if ($hasChild) {
|
|
|
823 |
$this->line .= '</samp>';
|
|
|
824 |
}
|
|
|
825 |
parent::leaveHash($cursor, $type, $class, $hasChild, 0);
|
|
|
826 |
}
|
|
|
827 |
|
|
|
828 |
protected function style(string $style, string $value, array $attr = []): string
|
|
|
829 |
{
|
|
|
830 |
if ('' === $value) {
|
|
|
831 |
return '';
|
|
|
832 |
}
|
|
|
833 |
|
|
|
834 |
$v = esc($value);
|
|
|
835 |
|
|
|
836 |
if ('ref' === $style) {
|
|
|
837 |
if (empty($attr['count'])) {
|
|
|
838 |
return sprintf('<a class=sf-dump-ref>%s</a>', $v);
|
|
|
839 |
}
|
|
|
840 |
$r = ('#' !== $v[0] ? 1 - ('@' !== $v[0]) : 2).substr($value, 1);
|
|
|
841 |
|
|
|
842 |
return sprintf('<a class=sf-dump-ref href=#%s-ref%s title="%d occurrences">%s</a>', $this->dumpId, $r, 1 + $attr['count'], $v);
|
|
|
843 |
}
|
|
|
844 |
|
|
|
845 |
if ('const' === $style && isset($attr['value'])) {
|
|
|
846 |
$style .= sprintf(' title="%s"', esc(\is_scalar($attr['value']) ? $attr['value'] : json_encode($attr['value'])));
|
|
|
847 |
} elseif ('public' === $style) {
|
|
|
848 |
$style .= sprintf(' title="%s"', empty($attr['dynamic']) ? 'Public property' : 'Runtime added dynamic property');
|
|
|
849 |
} elseif ('str' === $style && 1 < $attr['length']) {
|
|
|
850 |
$style .= sprintf(' title="%d%s characters"', $attr['length'], $attr['binary'] ? ' binary or non-UTF-8' : '');
|
|
|
851 |
} elseif ('note' === $style && 0 < ($attr['depth'] ?? 0) && false !== $c = strrpos($value, '\\')) {
|
|
|
852 |
$style .= ' title=""';
|
|
|
853 |
$attr += [
|
|
|
854 |
'ellipsis' => \strlen($value) - $c,
|
|
|
855 |
'ellipsis-type' => 'note',
|
|
|
856 |
'ellipsis-tail' => 1,
|
|
|
857 |
];
|
|
|
858 |
} elseif ('protected' === $style) {
|
|
|
859 |
$style .= ' title="Protected property"';
|
|
|
860 |
} elseif ('meta' === $style && isset($attr['title'])) {
|
|
|
861 |
$style .= sprintf(' title="%s"', esc($this->utf8Encode($attr['title'])));
|
|
|
862 |
} elseif ('private' === $style) {
|
|
|
863 |
$style .= sprintf(' title="Private property defined in class: `%s`"', esc($this->utf8Encode($attr['class'])));
|
|
|
864 |
}
|
|
|
865 |
$map = static::$controlCharsMap;
|
|
|
866 |
|
|
|
867 |
if (isset($attr['ellipsis'])) {
|
|
|
868 |
$class = 'sf-dump-ellipsis';
|
|
|
869 |
if (isset($attr['ellipsis-type'])) {
|
|
|
870 |
$class = sprintf('"%s sf-dump-ellipsis-%s"', $class, $attr['ellipsis-type']);
|
|
|
871 |
}
|
|
|
872 |
$label = esc(substr($value, -$attr['ellipsis']));
|
|
|
873 |
$style = str_replace(' title="', " title=\"$v\n", $style);
|
|
|
874 |
$v = sprintf('<span class=%s>%s</span>', $class, substr($v, 0, -\strlen($label)));
|
|
|
875 |
|
|
|
876 |
if (!empty($attr['ellipsis-tail'])) {
|
|
|
877 |
$tail = \strlen(esc(substr($value, -$attr['ellipsis'], $attr['ellipsis-tail'])));
|
|
|
878 |
$v .= sprintf('<span class=%s>%s</span>%s', $class, substr($label, 0, $tail), substr($label, $tail));
|
|
|
879 |
} else {
|
|
|
880 |
$v .= $label;
|
|
|
881 |
}
|
|
|
882 |
}
|
|
|
883 |
|
|
|
884 |
$v = "<span class=sf-dump-{$style}>".preg_replace_callback(static::$controlCharsRx, function ($c) use ($map) {
|
|
|
885 |
$s = $b = '<span class="sf-dump-default';
|
|
|
886 |
$c = $c[$i = 0];
|
|
|
887 |
if ($ns = "\r" === $c[$i] || "\n" === $c[$i]) {
|
|
|
888 |
$s .= ' sf-dump-ns';
|
|
|
889 |
}
|
|
|
890 |
$s .= '">';
|
|
|
891 |
do {
|
|
|
892 |
if (("\r" === $c[$i] || "\n" === $c[$i]) !== $ns) {
|
|
|
893 |
$s .= '</span>'.$b;
|
|
|
894 |
if ($ns = !$ns) {
|
|
|
895 |
$s .= ' sf-dump-ns';
|
|
|
896 |
}
|
|
|
897 |
$s .= '">';
|
|
|
898 |
}
|
|
|
899 |
|
|
|
900 |
$s .= $map[$c[$i]] ?? sprintf('\x%02X', \ord($c[$i]));
|
|
|
901 |
} while (isset($c[++$i]));
|
|
|
902 |
|
|
|
903 |
return $s.'</span>';
|
|
|
904 |
}, $v).'</span>';
|
|
|
905 |
|
|
|
906 |
if (isset($attr['file']) && $href = $this->getSourceLink($attr['file'], $attr['line'] ?? 0)) {
|
|
|
907 |
$attr['href'] = $href;
|
|
|
908 |
}
|
|
|
909 |
if (isset($attr['href'])) {
|
|
|
910 |
$target = isset($attr['file']) ? '' : ' target="_blank"';
|
|
|
911 |
$v = sprintf('<a href="%s"%s rel="noopener noreferrer">%s</a>', esc($this->utf8Encode($attr['href'])), $target, $v);
|
|
|
912 |
}
|
|
|
913 |
if (isset($attr['lang'])) {
|
|
|
914 |
$v = sprintf('<code class="%s">%s</code>', esc($attr['lang']), $v);
|
|
|
915 |
}
|
|
|
916 |
|
|
|
917 |
return $v;
|
|
|
918 |
}
|
|
|
919 |
|
|
|
920 |
protected function dumpLine(int $depth, bool $endOfValue = false)
|
|
|
921 |
{
|
|
|
922 |
if (-1 === $this->lastDepth) {
|
|
|
923 |
$this->line = sprintf($this->dumpPrefix, $this->dumpId, $this->indentPad).$this->line;
|
|
|
924 |
}
|
|
|
925 |
if ($this->headerIsDumped !== ($this->outputStream ?? $this->lineDumper)) {
|
|
|
926 |
$this->line = $this->getDumpHeader().$this->line;
|
|
|
927 |
}
|
|
|
928 |
|
|
|
929 |
if (-1 === $depth) {
|
|
|
930 |
$args = ['"'.$this->dumpId.'"'];
|
|
|
931 |
if ($this->extraDisplayOptions) {
|
|
|
932 |
$args[] = json_encode($this->extraDisplayOptions, \JSON_FORCE_OBJECT);
|
|
|
933 |
}
|
|
|
934 |
// Replace is for BC
|
|
|
935 |
$this->line .= sprintf(str_replace('"%s"', '%s', $this->dumpSuffix), implode(', ', $args));
|
|
|
936 |
}
|
|
|
937 |
$this->lastDepth = $depth;
|
|
|
938 |
|
|
|
939 |
$this->line = mb_encode_numericentity($this->line, [0x80, 0x10FFFF, 0, 0x1FFFFF], 'UTF-8');
|
|
|
940 |
|
|
|
941 |
if (-1 === $depth) {
|
|
|
942 |
AbstractDumper::dumpLine(0);
|
|
|
943 |
}
|
|
|
944 |
AbstractDumper::dumpLine($depth);
|
|
|
945 |
}
|
|
|
946 |
|
|
|
947 |
private function getSourceLink(string $file, int $line)
|
|
|
948 |
{
|
|
|
949 |
$options = $this->extraDisplayOptions + $this->displayOptions;
|
|
|
950 |
|
|
|
951 |
if ($fmt = $options['fileLinkFormat']) {
|
|
|
952 |
return \is_string($fmt) ? strtr($fmt, ['%f' => $file, '%l' => $line]) : $fmt->format($file, $line);
|
|
|
953 |
}
|
|
|
954 |
|
|
|
955 |
return false;
|
|
|
956 |
}
|
|
|
957 |
}
|
|
|
958 |
|
|
|
959 |
function esc(string $str)
|
|
|
960 |
{
|
|
|
961 |
return htmlspecialchars($str, \ENT_QUOTES, 'UTF-8');
|
|
|
962 |
}
|