Updated Drupal to 8.6. This goes with the following updates because it's possible...
[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     function xpathHasClass(className) {
314         return "contains(concat(' ', normalize-space(@class), ' '), ' " + className +" ')";
315     }
316     addEventListener(root, 'mouseover', function (e) {
317         if ('' != refStyle.innerHTML) {
318             refStyle.innerHTML = '';
319         }
320     });
321     a('mouseover', function (a, e, c) {
322         if (c) {
323             e.target.style.cursor = "pointer";
324         } else if (a = idRx.exec(a.className)) {
325             try {
326                 refStyle.innerHTML = 'pre.sf-dump .'+a[0]+'{background-color: #B729D9; color: #FFF !important; border-radius: 2px}';
327             } catch (e) {
328             }
329         }
330     });
331     a('click', function (a, e, c) {
332         if (/\bsf-dump-toggle\b/.test(a.className)) {
333             e.preventDefault();
334             if (!toggle(a, isCtrlKey(e))) {
335                 var r = doc.getElementById(a.getAttribute('href').substr(1)),
336                     s = r.previousSibling,
337                     f = r.parentNode,
338                     t = a.parentNode;
339                 t.replaceChild(r, a);
340                 f.replaceChild(a, s);
341                 t.insertBefore(s, r);
342                 f = f.firstChild.nodeValue.match(indentRx);
343                 t = t.firstChild.nodeValue.match(indentRx);
344                 if (f && t && f[0] !== t[0]) {
345                     r.innerHTML = r.innerHTML.replace(new RegExp('^'+f[0].replace(rxEsc, '\\$1'), 'mg'), t[0]);
346                 }
347                 if (/\bsf-dump-compact\b/.test(r.className)) {
348                     toggle(s, isCtrlKey(e));
349                 }
350             }
351
352             if (c) {
353             } else if (doc.getSelection) {
354                 try {
355                     doc.getSelection().removeAllRanges();
356                 } catch (e) {
357                     doc.getSelection().empty();
358                 }
359             } else {
360                 doc.selection.empty();
361             }
362         } else if (/\bsf-dump-str-toggle\b/.test(a.className)) {
363             e.preventDefault();
364             e = a.parentNode.parentNode;
365             e.className = e.className.replace(/\bsf-dump-str-(expand|collapse)\b/, a.parentNode.className);
366         }
367     });
368
369     elt = root.getElementsByTagName('SAMP');
370     len = elt.length;
371     i = 0;
372
373     while (i < len) t.push(elt[i++]);
374     len = t.length;
375
376     for (i = 0; i < len; ++i) {
377         elt = t[i];
378         if ('SAMP' == elt.tagName) {
379             a = elt.previousSibling || {};
380             if ('A' != a.tagName) {
381                 a = doc.createElement('A');
382                 a.className = 'sf-dump-ref';
383                 elt.parentNode.insertBefore(a, elt);
384             } else {
385                 a.innerHTML += ' ';
386             }
387             a.title = (a.title ? a.title+'\n[' : '[')+keyHint+'+click] Expand all children';
388             a.innerHTML += '<span>▼</span>';
389             a.className += ' sf-dump-toggle';
390
391             x = 1;
392             if ('sf-dump' != elt.parentNode.className) {
393                 x += elt.parentNode.getAttribute('data-depth')/1;
394             }
395             elt.setAttribute('data-depth', x);
396             var className = elt.className;
397             elt.className = 'sf-dump-expanded';
398             if (className ? 'sf-dump-expanded' !== className : (x > options.maxDepth)) {
399                 toggle(a);
400             }
401         } else if (/\bsf-dump-ref\b/.test(elt.className) && (a = elt.getAttribute('href'))) {
402             a = a.substr(1);
403             elt.className += ' '+a;
404
405             if (/[\[{]$/.test(elt.previousSibling.nodeValue)) {
406                 a = a != elt.nextSibling.id && doc.getElementById(a);
407                 try {
408                     s = a.nextSibling;
409                     elt.appendChild(a);
410                     s.parentNode.insertBefore(a, s);
411                     if (/^[@#]/.test(elt.innerHTML)) {
412                         elt.innerHTML += ' <span>▶</span>';
413                     } else {
414                         elt.innerHTML = '<span>▶</span>';
415                         elt.className = 'sf-dump-ref';
416                     }
417                     elt.className += ' sf-dump-toggle';
418                 } catch (e) {
419                     if ('&' == elt.innerHTML.charAt(0)) {
420                         elt.innerHTML = '…';
421                         elt.className = 'sf-dump-ref';
422                     }
423                 }
424             }
425         }
426     }
427
428     if (doc.evaluate && Array.from && root.children.length > 1) {
429         root.setAttribute('tabindex', 0);
430
431         SearchState = function () {
432             this.nodes = [];
433             this.idx = 0;
434         };
435         SearchState.prototype = {
436             next: function () {
437                 if (this.isEmpty()) {
438                     return this.current();
439                 }
440                 this.idx = this.idx < (this.nodes.length - 1) ? this.idx + 1 : 0;
441         
442                 return this.current();
443             },
444             previous: function () {
445                 if (this.isEmpty()) {
446                     return this.current();
447                 }
448                 this.idx = this.idx > 0 ? this.idx - 1 : (this.nodes.length - 1);
449         
450                 return this.current();
451             },
452             isEmpty: function () {
453                 return 0 === this.count();
454             },
455             current: function () {
456                 if (this.isEmpty()) {
457                     return null;
458                 }
459                 return this.nodes[this.idx];
460             },
461             reset: function () {
462                 this.nodes = [];
463                 this.idx = 0;
464             },
465             count: function () {
466                 return this.nodes.length;
467             },
468         };
469
470         function showCurrent(state)
471         {
472             var currentNode = state.current();
473             if (currentNode) {
474                 reveal(currentNode);
475                 highlight(root, currentNode, state.nodes);
476             }
477             counter.textContent = (state.isEmpty() ? 0 : state.idx + 1) + ' of ' + state.count();
478         }
479
480         var search = doc.createElement('div');
481         search.className = 'sf-dump-search-wrapper sf-dump-search-hidden';
482         search.innerHTML = '
483             <input type="text" class="sf-dump-search-input">
484             <span class="sf-dump-search-count">0 of 0<\/span>
485             <button type="button" class="sf-dump-search-input-previous" tabindex="-1">
486                 <svg viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg">
487                     <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"\/>
488                 <\/svg>
489             <\/button>
490             <button type="button" class="sf-dump-search-input-next" tabindex="-1">
491                 <svg viewBox="0 0 1792 1792" xmlns="http://www.w3.org/2000/svg">
492                     <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"\/>
493                 <\/svg>
494             <\/button>
495         ';
496         root.insertBefore(search, root.firstChild);
497
498         var state = new SearchState();
499         var searchInput = search.querySelector('.sf-dump-search-input');
500         var counter = search.querySelector('.sf-dump-search-count');
501         var searchInputTimer = 0;
502         var previousSearchQuery = '';
503
504         addEventListener(searchInput, 'keyup', function (e) {
505             var searchQuery = e.target.value;
506             /* Don't perform anything if the pressed key didn't change the query */
507             if (searchQuery === previousSearchQuery) {
508                 return;
509             }
510             previousSearchQuery = searchQuery;
511             clearTimeout(searchInputTimer);
512             searchInputTimer = setTimeout(function () {
513                 state.reset();
514                 collapseAll(root);
515                 resetHighlightedNodes(root);
516                 if ('' === searchQuery) {
517                     counter.textContent = '0 of 0';
518
519                     return;
520                 }
521
522                 var classMatches = [
523                     "sf-dump-str",
524                     "sf-dump-key",
525                     "sf-dump-public",
526                     "sf-dump-protected",
527                     "sf-dump-private",
528                 ].map(xpathHasClass).join(' or ');
529                 
530                 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);
531
532                 while (node = xpathResult.iterateNext()) state.nodes.push(node);
533                 
534                 showCurrent(state);
535             }, 400);
536         });
537
538         Array.from(search.querySelectorAll('.sf-dump-search-input-next, .sf-dump-search-input-previous')).forEach(function (btn) {
539             addEventListener(btn, 'click', function (e) {
540                 e.preventDefault();
541                 -1 !== e.target.className.indexOf('next') ? state.next() : state.previous();
542                 searchInput.focus();
543                 collapseAll(root);
544                 showCurrent(state);
545             })
546         });
547
548         addEventListener(root, 'keydown', function (e) {
549             var isSearchActive = !/\bsf-dump-search-hidden\b/.test(search.className);
550             if ((114 === e.keyCode && !isSearchActive) || (isCtrlKey(e) && 70 === e.keyCode)) {
551                 /* F3 or CMD/CTRL + F */
552                 e.preventDefault();
553                 search.className = search.className.replace(/\bsf-dump-search-hidden\b/, '');
554                 searchInput.focus();
555             } else if (isSearchActive) {
556                 if (27 === e.keyCode) {
557                     /* ESC key */
558                     search.className += ' sf-dump-search-hidden';
559                     e.preventDefault();
560                     resetHighlightedNodes(root);
561                     searchInput.value = '';
562                 } else if (
563                     (isCtrlKey(e) && 71 === e.keyCode) /* CMD/CTRL + G */
564                     || 13 === e.keyCode /* Enter */
565                     || 114 === e.keyCode /* F3 */
566                 ) {
567                     e.preventDefault();
568                     e.shiftKey ? state.previous() : state.next();
569                     collapseAll(root);
570                     showCurrent(state);
571                 }
572             }
573         });
574     }
575
576     if (0 >= options.maxStringLength) {
577         return;
578     }
579     try {
580         elt = root.querySelectorAll('.sf-dump-str');
581         len = elt.length;
582         i = 0;
583         t = [];
584
585         while (i < len) t.push(elt[i++]);
586         len = t.length;
587
588         for (i = 0; i < len; ++i) {
589             elt = t[i];
590             s = elt.innerText || elt.textContent;
591             x = s.length - options.maxStringLength;
592             if (0 < x) {
593                 h = elt.innerHTML;
594                 elt[elt.innerText ? 'innerText' : 'textContent'] = s.substring(0, options.maxStringLength);
595                 elt.className += ' sf-dump-str-collapse';
596                 elt.innerHTML = '<span class=sf-dump-str-collapse>'+h+'<a class="sf-dump-ref sf-dump-str-toggle" title="Collapse"> ◀</a></span>'+
597                     '<span class=sf-dump-str-expand>'+elt.innerHTML+'<a class="sf-dump-ref sf-dump-str-toggle" title="'+x+' remaining characters"> ▶</a></span>';
598             }
599         }
600     } catch (e) {
601     }
602 };
603
604 })(document);
605 </script><style>
606 pre.sf-dump {
607     display: block;
608     white-space: pre;
609     padding: 5px;
610 }
611 pre.sf-dump:after {
612    content: "";
613    visibility: hidden;
614    display: block;
615    height: 0;
616    clear: both;
617 }
618 pre.sf-dump span {
619     display: inline;
620 }
621 pre.sf-dump .sf-dump-compact {
622     display: none;
623 }
624 pre.sf-dump abbr {
625     text-decoration: none;
626     border: none;
627     cursor: help;
628 }
629 pre.sf-dump a {
630     text-decoration: none;
631     cursor: pointer;
632     border: 0;
633     outline: none;
634     color: inherit;
635 }
636 pre.sf-dump .sf-dump-ellipsis {
637     display: inline-block;
638     overflow: visible;
639     text-overflow: ellipsis;
640     max-width: 5em;
641     white-space: nowrap;
642     overflow: hidden;
643     vertical-align: top;
644 }
645 pre.sf-dump .sf-dump-ellipsis+.sf-dump-ellipsis {
646     max-width: none;
647 }
648 pre.sf-dump code {
649     display:inline;
650     padding:0;
651     background:none;
652 }
653 .sf-dump-str-collapse .sf-dump-str-collapse {
654     display: none;
655 }
656 .sf-dump-str-expand .sf-dump-str-expand {
657     display: none;
658 }
659 .sf-dump-public.sf-dump-highlight,
660 .sf-dump-protected.sf-dump-highlight,
661 .sf-dump-private.sf-dump-highlight,
662 .sf-dump-str.sf-dump-highlight,
663 .sf-dump-key.sf-dump-highlight {
664     background: rgba(111, 172, 204, 0.3);
665     border: 1px solid #7DA0B1;
666     border-radius: 3px;
667 }
668 .sf-dump-public.sf-dump-highlight-active,
669 .sf-dump-protected.sf-dump-highlight-active,
670 .sf-dump-private.sf-dump-highlight-active,
671 .sf-dump-str.sf-dump-highlight-active,
672 .sf-dump-key.sf-dump-highlight-active {
673     background: rgba(253, 175, 0, 0.4);
674     border: 1px solid #ffa500;
675     border-radius: 3px;
676 }
677 pre.sf-dump .sf-dump-search-hidden {
678     display: none;
679 }
680 pre.sf-dump .sf-dump-search-wrapper {
681     float: right;
682     font-size: 0;
683     white-space: nowrap;
684     max-width: 100%;
685     text-align: right;
686 }
687 pre.sf-dump .sf-dump-search-wrapper > * {
688     vertical-align: top;
689     box-sizing: border-box;
690     height: 21px;
691     font-weight: normal;
692     border-radius: 0;
693     background: #FFF;
694     color: #757575;
695     border: 1px solid #BBB;
696 }
697 pre.sf-dump .sf-dump-search-wrapper > input.sf-dump-search-input {
698     padding: 3px;
699     height: 21px;
700     font-size: 12px;
701     border-right: none;
702     width: 140px;
703     border-top-left-radius: 3px;
704     border-bottom-left-radius: 3px;
705     color: #000;
706 }
707 pre.sf-dump .sf-dump-search-wrapper > .sf-dump-search-input-next,
708 pre.sf-dump .sf-dump-search-wrapper > .sf-dump-search-input-previous {
709     background: #F2F2F2;
710     outline: none;
711     border-left: none;
712     font-size: 0;
713     line-height: 0;
714 }
715 pre.sf-dump .sf-dump-search-wrapper > .sf-dump-search-input-next {
716     border-top-right-radius: 3px;
717     border-bottom-right-radius: 3px;
718 }
719 pre.sf-dump .sf-dump-search-wrapper > .sf-dump-search-input-next > svg,
720 pre.sf-dump .sf-dump-search-wrapper > .sf-dump-search-input-previous > svg {
721     pointer-events: none;
722     width: 12px;
723     height: 12px;
724 }
725 pre.sf-dump .sf-dump-search-wrapper > .sf-dump-search-count {
726     display: inline-block;
727     padding: 0 5px;
728     margin: 0;
729     border-left: none;
730     line-height: 21px;
731     font-size: 12px;
732 }
733 EOHTML
734         );
735
736         foreach ($this->styles as $class => $style) {
737             $line .= 'pre.sf-dump'.('default' === $class ? ', pre.sf-dump' : '').' .sf-dump-'.$class.'{'.$style.'}';
738         }
739
740         return $this->dumpHeader = preg_replace('/\s+/', ' ', $line).'</style>'.$this->dumpHeader;
741     }
742
743     /**
744      * {@inheritdoc}
745      */
746     public function enterHash(Cursor $cursor, $type, $class, $hasChild)
747     {
748         parent::enterHash($cursor, $type, $class, false);
749
750         if ($cursor->skipChildren) {
751             $cursor->skipChildren = false;
752             $eol = ' class=sf-dump-compact>';
753         } elseif ($this->expandNextHash) {
754             $this->expandNextHash = false;
755             $eol = ' class=sf-dump-expanded>';
756         } else {
757             $eol = '>';
758         }
759
760         if ($hasChild) {
761             $this->line .= '<samp';
762             if ($cursor->refIndex) {
763                 $r = Cursor::HASH_OBJECT !== $type ? 1 - (Cursor::HASH_RESOURCE !== $type) : 2;
764                 $r .= $r && 0 < $cursor->softRefHandle ? $cursor->softRefHandle : $cursor->refIndex;
765
766                 $this->line .= sprintf(' id=%s-ref%s', $this->dumpId, $r);
767             }
768             $this->line .= $eol;
769             $this->dumpLine($cursor->depth);
770         }
771     }
772
773     /**
774      * {@inheritdoc}
775      */
776     public function leaveHash(Cursor $cursor, $type, $class, $hasChild, $cut)
777     {
778         $this->dumpEllipsis($cursor, $hasChild, $cut);
779         if ($hasChild) {
780             $this->line .= '</samp>';
781         }
782         parent::leaveHash($cursor, $type, $class, $hasChild, 0);
783     }
784
785     /**
786      * {@inheritdoc}
787      */
788     protected function style($style, $value, $attr = array())
789     {
790         if ('' === $value) {
791             return '';
792         }
793
794         $v = esc($value);
795
796         if ('ref' === $style) {
797             if (empty($attr['count'])) {
798                 return sprintf('<a class=sf-dump-ref>%s</a>', $v);
799             }
800             $r = ('#' !== $v[0] ? 1 - ('@' !== $v[0]) : 2).substr($value, 1);
801
802             return sprintf('<a class=sf-dump-ref href=#%s-ref%s title="%d occurrences">%s</a>', $this->dumpId, $r, 1 + $attr['count'], $v);
803         }
804
805         if ('const' === $style && isset($attr['value'])) {
806             $style .= sprintf(' title="%s"', esc(is_scalar($attr['value']) ? $attr['value'] : json_encode($attr['value'])));
807         } elseif ('public' === $style) {
808             $style .= sprintf(' title="%s"', empty($attr['dynamic']) ? 'Public property' : 'Runtime added dynamic property');
809         } elseif ('str' === $style && 1 < $attr['length']) {
810             $style .= sprintf(' title="%d%s characters"', $attr['length'], $attr['binary'] ? ' binary or non-UTF-8' : '');
811         } elseif ('note' === $style && false !== $c = strrpos($v, '\\')) {
812             return sprintf('<abbr title="%s" class=sf-dump-%s>%s</abbr>', $v, $style, substr($v, $c + 1));
813         } elseif ('protected' === $style) {
814             $style .= ' title="Protected property"';
815         } elseif ('meta' === $style && isset($attr['title'])) {
816             $style .= sprintf(' title="%s"', esc($this->utf8Encode($attr['title'])));
817         } elseif ('private' === $style) {
818             $style .= sprintf(' title="Private property defined in class:&#10;`%s`"', esc($this->utf8Encode($attr['class'])));
819         }
820         $map = static::$controlCharsMap;
821
822         if (isset($attr['ellipsis'])) {
823             $class = 'sf-dump-ellipsis';
824             if (isset($attr['ellipsis-type'])) {
825                 $class = sprintf('"%s sf-dump-ellipsis-%s"', $class, $attr['ellipsis-type']);
826             }
827             $label = esc(substr($value, -$attr['ellipsis']));
828             $style = str_replace(' title="', " title=\"$v\n", $style);
829             $v = sprintf('<span class=%s>%s</span>', $class, substr($v, 0, -\strlen($label)));
830
831             if (!empty($attr['ellipsis-tail'])) {
832                 $tail = \strlen(esc(substr($value, -$attr['ellipsis'], $attr['ellipsis-tail'])));
833                 $v .= sprintf('<span class=sf-dump-ellipsis>%s</span>%s', substr($label, 0, $tail), substr($label, $tail));
834             } else {
835                 $v .= $label;
836             }
837         }
838
839         $v = "<span class=sf-dump-{$style}>".preg_replace_callback(static::$controlCharsRx, function ($c) use ($map) {
840             $s = '<span class=sf-dump-default>';
841             $c = $c[$i = 0];
842             do {
843                 $s .= isset($map[$c[$i]]) ? $map[$c[$i]] : sprintf('\x%02X', \ord($c[$i]));
844             } while (isset($c[++$i]));
845
846             return $s.'</span>';
847         }, $v).'</span>';
848
849         if (isset($attr['file']) && $href = $this->getSourceLink($attr['file'], isset($attr['line']) ? $attr['line'] : 0)) {
850             $attr['href'] = $href;
851         }
852         if (isset($attr['href'])) {
853             $target = isset($attr['file']) ? '' : ' target="_blank"';
854             $v = sprintf('<a href="%s"%s rel="noopener noreferrer">%s</a>', esc($this->utf8Encode($attr['href'])), $target, $v);
855         }
856         if (isset($attr['lang'])) {
857             $v = sprintf('<code class="%s">%s</code>', esc($attr['lang']), $v);
858         }
859
860         return $v;
861     }
862
863     /**
864      * {@inheritdoc}
865      */
866     protected function dumpLine($depth, $endOfValue = false)
867     {
868         if (-1 === $this->lastDepth) {
869             $this->line = sprintf($this->dumpPrefix, $this->dumpId, $this->indentPad).$this->line;
870         }
871         if ($this->headerIsDumped !== (null !== $this->outputStream ? $this->outputStream : $this->lineDumper)) {
872             $this->line = $this->getDumpHeader().$this->line;
873         }
874
875         if (-1 === $depth) {
876             $args = array('"'.$this->dumpId.'"');
877             if ($this->extraDisplayOptions) {
878                 $args[] = json_encode($this->extraDisplayOptions, JSON_FORCE_OBJECT);
879             }
880             // Replace is for BC
881             $this->line .= sprintf(str_replace('"%s"', '%s', $this->dumpSuffix), implode(', ', $args));
882         }
883         $this->lastDepth = $depth;
884
885         $this->line = mb_convert_encoding($this->line, 'HTML-ENTITIES', 'UTF-8');
886
887         if (-1 === $depth) {
888             AbstractDumper::dumpLine(0);
889         }
890         AbstractDumper::dumpLine($depth);
891     }
892
893     private function getSourceLink($file, $line)
894     {
895         $options = $this->extraDisplayOptions + $this->displayOptions;
896
897         if ($fmt = $options['fileLinkFormat']) {
898             return \is_string($fmt) ? strtr($fmt, array('%f' => $file, '%l' => $line)) : $fmt->format($file, $line);
899         }
900
901         return false;
902     }
903 }
904
905 function esc($str)
906 {
907     return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
908 }