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 12namespace Symfony\Component\VarDumper\Dumper; 13 14use Symfony\Component\VarDumper\Cloner\Cursor; 15use Symfony\Component\VarDumper\Cloner\Data; 16 17/** 18 * HtmlDumper dumps variables as HTML. 19 * 20 * @author Nicolas Grekas <p@tchwork.com> 21 */ 22class 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 = [ 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 = [ 50 'maxDepth' => 1, 51 'maxStringLength' => 160, 52 'fileLinkFormat' => null, 53 ]; 54 private $extraDisplayOptions = []; 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 = []) 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> 133Sfdump = window.Sfdump || (function (doc) { 134 135var 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 145if (!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 155function 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 194function 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 206function 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 218function 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 230function 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 248function 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 262function 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 269return 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"><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> 487 <\/button> 488 <button type="button" class="sf-dump-search-input-next" tabindex="-1"> 489 <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> 490 <\/button> 491 '; 492 root.insertBefore(search, root.firstChild); 493 494 var state = new SearchState(); 495 var searchInput = search.querySelector('.sf-dump-search-input'); 496 var counter = search.querySelector('.sf-dump-search-count'); 497 var searchInputTimer = 0; 498 var previousSearchQuery = ''; 499 500 addEventListener(searchInput, 'keyup', function (e) { 501 var searchQuery = e.target.value; 502 /* Don't perform anything if the pressed key didn't change the query */ 503 if (searchQuery === previousSearchQuery) { 504 return; 505 } 506 previousSearchQuery = searchQuery; 507 clearTimeout(searchInputTimer); 508 searchInputTimer = setTimeout(function () { 509 state.reset(); 510 collapseAll(root); 511 resetHighlightedNodes(root); 512 if ('' === searchQuery) { 513 counter.textContent = '0 of 0'; 514 515 return; 516 } 517 518 var classMatches = [ 519 "sf-dump-str", 520 "sf-dump-key", 521 "sf-dump-public", 522 "sf-dump-protected", 523 "sf-dump-private", 524 ].map(xpathHasClass).join(' or '); 525 526 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); 527 528 while (node = xpathResult.iterateNext()) state.nodes.push(node); 529 530 showCurrent(state); 531 }, 400); 532 }); 533 534 Array.from(search.querySelectorAll('.sf-dump-search-input-next, .sf-dump-search-input-previous')).forEach(function (btn) { 535 addEventListener(btn, 'click', function (e) { 536 e.preventDefault(); 537 -1 !== e.target.className.indexOf('next') ? state.next() : state.previous(); 538 searchInput.focus(); 539 collapseAll(root); 540 showCurrent(state); 541 }) 542 }); 543 544 addEventListener(root, 'keydown', function (e) { 545 var isSearchActive = !/\bsf-dump-search-hidden\b/.test(search.className); 546 if ((114 === e.keyCode && !isSearchActive) || (isCtrlKey(e) && 70 === e.keyCode)) { 547 /* F3 or CMD/CTRL + F */ 548 e.preventDefault(); 549 search.className = search.className.replace(/\bsf-dump-search-hidden\b/, ''); 550 searchInput.focus(); 551 } else if (isSearchActive) { 552 if (27 === e.keyCode) { 553 /* ESC key */ 554 search.className += ' sf-dump-search-hidden'; 555 e.preventDefault(); 556 resetHighlightedNodes(root); 557 searchInput.value = ''; 558 } else if ( 559 (isCtrlKey(e) && 71 === e.keyCode) /* CMD/CTRL + G */ 560 || 13 === e.keyCode /* Enter */ 561 || 114 === e.keyCode /* F3 */ 562 ) { 563 e.preventDefault(); 564 e.shiftKey ? state.previous() : state.next(); 565 collapseAll(root); 566 showCurrent(state); 567 } 568 } 569 }); 570 } 571 572 if (0 >= options.maxStringLength) { 573 return; 574 } 575 try { 576 elt = root.querySelectorAll('.sf-dump-str'); 577 len = elt.length; 578 i = 0; 579 t = []; 580 581 while (i < len) t.push(elt[i++]); 582 len = t.length; 583 584 for (i = 0; i < len; ++i) { 585 elt = t[i]; 586 s = elt.innerText || elt.textContent; 587 x = s.length - options.maxStringLength; 588 if (0 < x) { 589 h = elt.innerHTML; 590 elt[elt.innerText ? 'innerText' : 'textContent'] = s.substring(0, options.maxStringLength); 591 elt.className += ' sf-dump-str-collapse'; 592 elt.innerHTML = '<span class=sf-dump-str-collapse>'+h+'<a class="sf-dump-ref sf-dump-str-toggle" title="Collapse"> ◀</a></span>'+ 593 '<span class=sf-dump-str-expand>'+elt.innerHTML+'<a class="sf-dump-ref sf-dump-str-toggle" title="'+x+' remaining characters"> ▶</a></span>'; 594 } 595 } 596 } catch (e) { 597 } 598}; 599 600})(document); 601</script><style> 602pre.sf-dump { 603 display: block; 604 white-space: pre; 605 padding: 5px; 606} 607pre.sf-dump:after { 608 content: ""; 609 visibility: hidden; 610 display: block; 611 height: 0; 612 clear: both; 613} 614pre.sf-dump span { 615 display: inline; 616} 617pre.sf-dump .sf-dump-compact { 618 display: none; 619} 620pre.sf-dump abbr { 621 text-decoration: none; 622 border: none; 623 cursor: help; 624} 625pre.sf-dump a { 626 text-decoration: none; 627 cursor: pointer; 628 border: 0; 629 outline: none; 630 color: inherit; 631} 632pre.sf-dump .sf-dump-ellipsis { 633 display: inline-block; 634 overflow: visible; 635 text-overflow: ellipsis; 636 max-width: 5em; 637 white-space: nowrap; 638 overflow: hidden; 639 vertical-align: top; 640} 641pre.sf-dump .sf-dump-ellipsis+.sf-dump-ellipsis { 642 max-width: none; 643} 644pre.sf-dump code { 645 display:inline; 646 padding:0; 647 background:none; 648} 649.sf-dump-str-collapse .sf-dump-str-collapse { 650 display: none; 651} 652.sf-dump-str-expand .sf-dump-str-expand { 653 display: none; 654} 655.sf-dump-public.sf-dump-highlight, 656.sf-dump-protected.sf-dump-highlight, 657.sf-dump-private.sf-dump-highlight, 658.sf-dump-str.sf-dump-highlight, 659.sf-dump-key.sf-dump-highlight { 660 background: rgba(111, 172, 204, 0.3); 661 border: 1px solid #7DA0B1; 662 border-radius: 3px; 663} 664.sf-dump-public.sf-dump-highlight-active, 665.sf-dump-protected.sf-dump-highlight-active, 666.sf-dump-private.sf-dump-highlight-active, 667.sf-dump-str.sf-dump-highlight-active, 668.sf-dump-key.sf-dump-highlight-active { 669 background: rgba(253, 175, 0, 0.4); 670 border: 1px solid #ffa500; 671 border-radius: 3px; 672} 673pre.sf-dump .sf-dump-search-hidden { 674 display: none; 675} 676pre.sf-dump .sf-dump-search-wrapper { 677 float: right; 678 font-size: 0; 679 white-space: nowrap; 680 max-width: 100%; 681 text-align: right; 682} 683pre.sf-dump .sf-dump-search-wrapper > * { 684 vertical-align: top; 685 box-sizing: border-box; 686 height: 21px; 687 font-weight: normal; 688 border-radius: 0; 689 background: #FFF; 690 color: #757575; 691 border: 1px solid #BBB; 692} 693pre.sf-dump .sf-dump-search-wrapper > input.sf-dump-search-input { 694 padding: 3px; 695 height: 21px; 696 font-size: 12px; 697 border-right: none; 698 width: 140px; 699 border-top-left-radius: 3px; 700 border-bottom-left-radius: 3px; 701 color: #000; 702} 703pre.sf-dump .sf-dump-search-wrapper > .sf-dump-search-input-next, 704pre.sf-dump .sf-dump-search-wrapper > .sf-dump-search-input-previous { 705 background: #F2F2F2; 706 outline: none; 707 border-left: none; 708 font-size: 0; 709 line-height: 0; 710} 711pre.sf-dump .sf-dump-search-wrapper > .sf-dump-search-input-next { 712 border-top-right-radius: 3px; 713 border-bottom-right-radius: 3px; 714} 715pre.sf-dump .sf-dump-search-wrapper > .sf-dump-search-input-next > svg, 716pre.sf-dump .sf-dump-search-wrapper > .sf-dump-search-input-previous > svg { 717 pointer-events: none; 718 width: 12px; 719 height: 12px; 720} 721pre.sf-dump .sf-dump-search-wrapper > .sf-dump-search-count { 722 display: inline-block; 723 padding: 0 5px; 724 margin: 0; 725 border-left: none; 726 line-height: 21px; 727 font-size: 12px; 728} 729EOHTML 730 ); 731 732 foreach ($this->styles as $class => $style) { 733 $line .= 'pre.sf-dump'.('default' === $class ? ', pre.sf-dump' : '').' .sf-dump-'.$class.'{'.$style.'}'; 734 } 735 736 return $this->dumpHeader = preg_replace('/\s+/', ' ', $line).'</style>'.$this->dumpHeader; 737 } 738 739 /** 740 * {@inheritdoc} 741 */ 742 public function enterHash(Cursor $cursor, $type, $class, $hasChild) 743 { 744 parent::enterHash($cursor, $type, $class, false); 745 746 if ($cursor->skipChildren) { 747 $cursor->skipChildren = false; 748 $eol = ' class=sf-dump-compact>'; 749 } elseif ($this->expandNextHash) { 750 $this->expandNextHash = false; 751 $eol = ' class=sf-dump-expanded>'; 752 } else { 753 $eol = '>'; 754 } 755 756 if ($hasChild) { 757 $this->line .= '<samp'; 758 if ($cursor->refIndex) { 759 $r = Cursor::HASH_OBJECT !== $type ? 1 - (Cursor::HASH_RESOURCE !== $type) : 2; 760 $r .= $r && 0 < $cursor->softRefHandle ? $cursor->softRefHandle : $cursor->refIndex; 761 762 $this->line .= sprintf(' id=%s-ref%s', $this->dumpId, $r); 763 } 764 $this->line .= $eol; 765 $this->dumpLine($cursor->depth); 766 } 767 } 768 769 /** 770 * {@inheritdoc} 771 */ 772 public function leaveHash(Cursor $cursor, $type, $class, $hasChild, $cut) 773 { 774 $this->dumpEllipsis($cursor, $hasChild, $cut); 775 if ($hasChild) { 776 $this->line .= '</samp>'; 777 } 778 parent::leaveHash($cursor, $type, $class, $hasChild, 0); 779 } 780 781 /** 782 * {@inheritdoc} 783 */ 784 protected function style($style, $value, $attr = []) 785 { 786 if ('' === $value) { 787 return ''; 788 } 789 790 $v = esc($value); 791 792 if ('ref' === $style) { 793 if (empty($attr['count'])) { 794 return sprintf('<a class=sf-dump-ref>%s</a>', $v); 795 } 796 $r = ('#' !== $v[0] ? 1 - ('@' !== $v[0]) : 2).substr($value, 1); 797 798 return sprintf('<a class=sf-dump-ref href=#%s-ref%s title="%d occurrences">%s</a>', $this->dumpId, $r, 1 + $attr['count'], $v); 799 } 800 801 if ('const' === $style && isset($attr['value'])) { 802 $style .= sprintf(' title="%s"', esc(is_scalar($attr['value']) ? $attr['value'] : json_encode($attr['value']))); 803 } elseif ('public' === $style) { 804 $style .= sprintf(' title="%s"', empty($attr['dynamic']) ? 'Public property' : 'Runtime added dynamic property'); 805 } elseif ('str' === $style && 1 < $attr['length']) { 806 $style .= sprintf(' title="%d%s characters"', $attr['length'], $attr['binary'] ? ' binary or non-UTF-8' : ''); 807 } elseif ('note' === $style && false !== $c = strrpos($v, '\\')) { 808 return sprintf('<abbr title="%s" class=sf-dump-%s>%s</abbr>', $v, $style, substr($v, $c + 1)); 809 } elseif ('protected' === $style) { 810 $style .= ' title="Protected property"'; 811 } elseif ('meta' === $style && isset($attr['title'])) { 812 $style .= sprintf(' title="%s"', esc($this->utf8Encode($attr['title']))); 813 } elseif ('private' === $style) { 814 $style .= sprintf(' title="Private property defined in class: `%s`"', esc($this->utf8Encode($attr['class']))); 815 } 816 $map = static::$controlCharsMap; 817 818 if (isset($attr['ellipsis'])) { 819 $class = 'sf-dump-ellipsis'; 820 if (isset($attr['ellipsis-type'])) { 821 $class = sprintf('"%s sf-dump-ellipsis-%s"', $class, $attr['ellipsis-type']); 822 } 823 $label = esc(substr($value, -$attr['ellipsis'])); 824 $style = str_replace(' title="', " title=\"$v\n", $style); 825 $v = sprintf('<span class=%s>%s</span>', $class, substr($v, 0, -\strlen($label))); 826 827 if (!empty($attr['ellipsis-tail'])) { 828 $tail = \strlen(esc(substr($value, -$attr['ellipsis'], $attr['ellipsis-tail']))); 829 $v .= sprintf('<span class=sf-dump-ellipsis>%s</span>%s', substr($label, 0, $tail), substr($label, $tail)); 830 } else { 831 $v .= $label; 832 } 833 } 834 835 $v = "<span class=sf-dump-{$style}>".preg_replace_callback(static::$controlCharsRx, function ($c) use ($map) { 836 $s = '<span class=sf-dump-default>'; 837 $c = $c[$i = 0]; 838 do { 839 $s .= isset($map[$c[$i]]) ? $map[$c[$i]] : sprintf('\x%02X', \ord($c[$i])); 840 } while (isset($c[++$i])); 841 842 return $s.'</span>'; 843 }, $v).'</span>'; 844 845 if (isset($attr['file']) && $href = $this->getSourceLink($attr['file'], isset($attr['line']) ? $attr['line'] : 0)) { 846 $attr['href'] = $href; 847 } 848 if (isset($attr['href'])) { 849 $target = isset($attr['file']) ? '' : ' target="_blank"'; 850 $v = sprintf('<a href="%s"%s rel="noopener noreferrer">%s</a>', esc($this->utf8Encode($attr['href'])), $target, $v); 851 } 852 if (isset($attr['lang'])) { 853 $v = sprintf('<code class="%s">%s</code>', esc($attr['lang']), $v); 854 } 855 856 return $v; 857 } 858 859 /** 860 * {@inheritdoc} 861 */ 862 protected function dumpLine($depth, $endOfValue = false) 863 { 864 if (-1 === $this->lastDepth) { 865 $this->line = sprintf($this->dumpPrefix, $this->dumpId, $this->indentPad).$this->line; 866 } 867 if ($this->headerIsDumped !== (null !== $this->outputStream ? $this->outputStream : $this->lineDumper)) { 868 $this->line = $this->getDumpHeader().$this->line; 869 } 870 871 if (-1 === $depth) { 872 $args = ['"'.$this->dumpId.'"']; 873 if ($this->extraDisplayOptions) { 874 $args[] = json_encode($this->extraDisplayOptions, \JSON_FORCE_OBJECT); 875 } 876 // Replace is for BC 877 $this->line .= sprintf(str_replace('"%s"', '%s', $this->dumpSuffix), implode(', ', $args)); 878 } 879 $this->lastDepth = $depth; 880 881 $this->line = mb_convert_encoding($this->line, 'HTML-ENTITIES', 'UTF-8'); 882 883 if (-1 === $depth) { 884 AbstractDumper::dumpLine(0); 885 } 886 AbstractDumper::dumpLine($depth); 887 } 888 889 private function getSourceLink($file, $line) 890 { 891 $options = $this->extraDisplayOptions + $this->displayOptions; 892 893 if ($fmt = $options['fileLinkFormat']) { 894 return \is_string($fmt) ? strtr($fmt, ['%f' => $file, '%l' => $line]) : $fmt->format($file, $line); 895 } 896 897 return false; 898 } 899} 900 901function esc($str) 902{ 903 return htmlspecialchars($str, \ENT_QUOTES, 'UTF-8'); 904} 905