PageRenderTime 56ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/src/lib/Magento/Profiler/Output/Firebug.php

https://bitbucket.org/mkrasuski/magento-ce
PHP | 116 lines | 43 code | 13 blank | 60 comment | 0 complexity | 500e760937c461c20e3f93c570da0a84 MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magento.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magento.com for more information.
  20. *
  21. * @category Magento
  22. * @package Magento_Profiler
  23. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Class that outputs profiling results to Firebug
  28. */
  29. class Magento_Profiler_Output_Firebug extends Magento_Profiler_OutputAbstract
  30. {
  31. /**
  32. * @var Zend_Controller_Request_Abstract
  33. */
  34. private $_request;
  35. /**
  36. * @var Zend_Controller_Response_Abstract
  37. */
  38. private $_response;
  39. /**
  40. * Start output buffering
  41. *
  42. * @param string|null $filter Pattern to filter timers by their identifiers (SQL LIKE syntax)
  43. */
  44. public function __construct($filter = null)
  45. {
  46. parent::__construct($filter);
  47. ob_start();
  48. }
  49. /**
  50. * Request setter
  51. *
  52. * @param Zend_Controller_Request_Abstract $request
  53. */
  54. public function setRequest(Zend_Controller_Request_Abstract $request)
  55. {
  56. $this->_request = $request;
  57. }
  58. /**
  59. * Response setter
  60. *
  61. * @param Zend_Controller_Response_Abstract $response
  62. */
  63. public function setResponse(Zend_Controller_Response_Abstract $response)
  64. {
  65. $this->_response = $response;
  66. }
  67. /**
  68. * Display profiling results and flush output buffer
  69. */
  70. public function display()
  71. {
  72. $firebugMessage = new Zend_Wildfire_Plugin_FirePhp_TableMessage($this->_renderCaption());
  73. $firebugMessage->setHeader(array_keys($this->_getColumns()));
  74. foreach ($this->_getTimers() as $timerId) {
  75. $row = array();
  76. foreach ($this->_getColumns() as $columnId) {
  77. $row[] = $this->_renderColumnValue($timerId, $columnId);
  78. }
  79. $firebugMessage->addRow($row);
  80. }
  81. Zend_Wildfire_Plugin_FirePhp::getInstance()->send($firebugMessage);
  82. // setup the wildfire channel
  83. $firebugChannel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
  84. $firebugChannel->setRequest($this->_request ? $this->_request : new Zend_Controller_Request_Http());
  85. $firebugChannel->setResponse($this->_response ? $this->_response : new Zend_Controller_Response_Http());
  86. // flush the wildfire headers into the response object
  87. $firebugChannel->flush();
  88. // send the response headers
  89. $firebugChannel->getResponse()->sendHeaders();
  90. ob_end_flush();
  91. }
  92. /**
  93. * Render timer id column value
  94. *
  95. * @param string $timerId
  96. * @return string
  97. */
  98. protected function _renderTimerId($timerId)
  99. {
  100. $nestingSep = preg_quote(Magento_Profiler::NESTING_SEPARATOR, '/');
  101. return preg_replace('/.+?' . $nestingSep . '/', '. ', $timerId);
  102. }
  103. }