vendor/symfony/var-dumper/Dumper/HtmlDumper.php line 77

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