File indexing completed on 2025-01-19 05:21:02
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Db 0017 * @subpackage Profiler 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** Zend_Db_Profiler */ 0024 // require_once 'Zend/Db/Profiler.php'; 0025 0026 /** Zend_Wildfire_Plugin_FirePhp */ 0027 // require_once 'Zend/Wildfire/Plugin/FirePhp.php'; 0028 0029 /** Zend_Wildfire_Plugin_FirePhp_TableMessage */ 0030 // require_once 'Zend/Wildfire/Plugin/FirePhp/TableMessage.php'; 0031 0032 /** 0033 * Writes DB events as log messages to the Firebug Console via FirePHP. 0034 * 0035 * @category Zend 0036 * @package Zend_Db 0037 * @subpackage Profiler 0038 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0039 * @license http://framework.zend.com/license/new-bsd New BSD License 0040 */ 0041 class Zend_Db_Profiler_Firebug extends Zend_Db_Profiler 0042 { 0043 /** 0044 * The original label for this profiler. 0045 * @var string 0046 */ 0047 protected $_label = null; 0048 0049 /** 0050 * The label template for this profiler 0051 * @var string 0052 */ 0053 protected $_label_template = '%label% (%totalCount% @ %totalDuration% sec)'; 0054 0055 /** 0056 * The message envelope holding the profiling summary 0057 * @var Zend_Wildfire_Plugin_FirePhp_TableMessage 0058 */ 0059 protected $_message = null; 0060 0061 /** 0062 * The total time taken for all profiled queries. 0063 * @var float 0064 */ 0065 protected $_totalElapsedTime = 0; 0066 0067 /** 0068 * Constructor 0069 * 0070 * @param string $label OPTIONAL Label for the profiling info. 0071 * @return void 0072 */ 0073 public function __construct($label = null) 0074 { 0075 $this->_label = $label; 0076 if(!$this->_label) { 0077 $this->_label = 'Zend_Db_Profiler_Firebug'; 0078 } 0079 } 0080 0081 /** 0082 * Enable or disable the profiler. If $enable is false, the profiler 0083 * is disabled and will not log any queries sent to it. 0084 * 0085 * @param boolean $enable 0086 * @return Zend_Db_Profiler Provides a fluent interface 0087 */ 0088 public function setEnabled($enable) 0089 { 0090 parent::setEnabled($enable); 0091 0092 if ($this->getEnabled()) { 0093 0094 if (!$this->_message) { 0095 $this->_message = new Zend_Wildfire_Plugin_FirePhp_TableMessage($this->_label); 0096 $this->_message->setBuffered(true); 0097 $this->_message->setHeader(array('Time','Event','Parameters')); 0098 $this->_message->setDestroy(true); 0099 $this->_message->setOption('includeLineNumbers', false); 0100 Zend_Wildfire_Plugin_FirePhp::getInstance()->send($this->_message); 0101 } 0102 0103 } else { 0104 0105 if ($this->_message) { 0106 $this->_message->setDestroy(true); 0107 $this->_message = null; 0108 } 0109 0110 } 0111 0112 return $this; 0113 } 0114 0115 /** 0116 * Intercept the query end and log the profiling data. 0117 * 0118 * @param integer $queryId 0119 * @throws Zend_Db_Profiler_Exception 0120 * @return void 0121 */ 0122 public function queryEnd($queryId) 0123 { 0124 $state = parent::queryEnd($queryId); 0125 0126 if (!$this->getEnabled() || $state == self::IGNORED) { 0127 return; 0128 } 0129 0130 $this->_message->setDestroy(false); 0131 0132 $profile = $this->getQueryProfile($queryId); 0133 0134 $this->_totalElapsedTime += $profile->getElapsedSecs(); 0135 0136 $this->_message->addRow(array((string)round($profile->getElapsedSecs(),5), 0137 $profile->getQuery(), 0138 ($params=$profile->getQueryParams())?$params:null)); 0139 0140 $this->updateMessageLabel(); 0141 } 0142 0143 /** 0144 * Update the label of the message holding the profile info. 0145 * 0146 * @return void 0147 */ 0148 protected function updateMessageLabel() 0149 { 0150 if (!$this->_message) { 0151 return; 0152 } 0153 $this->_message->setLabel(str_replace(array('%label%', 0154 '%totalCount%', 0155 '%totalDuration%'), 0156 array($this->_label, 0157 $this->getTotalNumQueries(), 0158 (string)round($this->_totalElapsedTime,5)), 0159 $this->_label_template)); 0160 } 0161 }