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