Html.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Class that represents profiler output in HTML format
  4. *
  5. * Copyright © Magento, Inc. All rights reserved.
  6. * See COPYING.txt for license details.
  7. */
  8. namespace Magento\Framework\Profiler\Driver\Standard\Output;
  9. use Magento\Framework\Profiler;
  10. use Magento\Framework\Profiler\Driver\Standard\AbstractOutput;
  11. use Magento\Framework\Profiler\Driver\Standard\Stat;
  12. class Html extends AbstractOutput
  13. {
  14. /**
  15. * Display profiling results
  16. *
  17. * @param Stat $stat
  18. * @return void
  19. */
  20. public function display(Stat $stat)
  21. {
  22. $out = [];
  23. $out[] = '<table border="1" cellspacing="0" cellpadding="2">';
  24. $out[] = '<caption>' . $this->_renderCaption() . '</caption>';
  25. $out[] = '<tr>';
  26. foreach (array_keys($this->_columns) as $columnLabel) {
  27. $out[] = '<th>' . $columnLabel . '</th>';
  28. }
  29. $out[] = '</tr>';
  30. foreach ($this->_getTimerIds($stat) as $timerId) {
  31. $out[] = '<tr>';
  32. foreach ($this->_columns as $column) {
  33. $out[] = '<td title="' . $timerId . '">' . $this->_renderColumnValue(
  34. $stat->fetch($timerId, $column),
  35. $column
  36. ) . '</td>';
  37. }
  38. $out[] = '</tr>';
  39. }
  40. $out[] = '</table>';
  41. $out[] = '';
  42. $out = implode("\n", $out);
  43. echo $out;
  44. }
  45. /**
  46. * Render timer id column value
  47. *
  48. * @param string $timerId
  49. * @return string
  50. */
  51. protected function _renderTimerId($timerId)
  52. {
  53. $nestingSep = preg_quote(Profiler::NESTING_SEPARATOR, '/');
  54. return preg_replace('/.+?' . $nestingSep . '/', '&middot;&nbsp;&nbsp;', $timerId);
  55. }
  56. }