/**
  * Gets content panel for the Debugbar
  *
  * @return string
  */
 public function getPanel()
 {
     $html = '<h4>Registered Instances</h4>';
     $this->_registry->ksort();
     foreach ($this->_registry as $k => $v) {
         if (is_object($v)) {
             $this->message->addRow(array($k, get_class($v)));
         } else {
             $this->message->addRow(array($k, $v));
         }
     }
 }
 public function stopQuery()
 {
     $executionMS = \microtime(true) - $this->_curQuery->startTime;
     $this->_totalMS += $executionMS;
     ++$this->_queryCount;
     $this->_message->addRow(array(number_format($executionMS, 5), $this->_curQuery->sql, $this->_curQuery->params));
     $this->updateLabel();
 }
Exemple #3
0
 public function stopQuery()
 {
     $elapsedTime = microtime(true) - $this->_currentQuery['startTime'];
     $this->_totalElapsedTime += $elapsedTime;
     ++$this->_queryCount;
     $this->_message->addRow(array(round($elapsedTime, 5), $this->_currentQuery['sql'], $this->_currentQuery['parameters']));
     $this->_updateMessageLabel();
 }
Exemple #4
0
 /**
  * Gets content panel for the Debugbar
  *
  * @return string
  */
 public function getPanel()
 {
     $username = '******';
     $role = 'Unknown Role';
     if ($this->_auth->hasIdentity()) {
         foreach ($this->_auth->getIdentity() as $property => $value) {
             $this->message->addRow(array((string) $property, (string) $value));
         }
     } else {
         //			$this->message->setMessage('Not authorized');
     }
     return '';
 }
 /**
  * dump
  *
  * @return string
  */
 public static function debug()
 {
     $backtrace = debug_backtrace();
     // get variable name
     $arrLines = file($backtrace[0]["file"]);
     $code = $arrLines[$backtrace[0]["line"] - 1];
     $arrMatches = array();
     // find call to Sys::dump
     preg_match('/\\b\\s*Core_Debug::debug\\s*\\(\\s*(.+)\\s*\\);\\s*/i', $code, $arrMatches);
     $varName = isset($arrMatches[1]) ? $arrMatches[1] : '???';
     $trace = array();
     foreach ($backtrace as $rec) {
         if (isset($rec['function'])) {
             $t['call'] = '';
             if (isset($rec['class'])) {
                 $t['call'] .= $rec['class'] . $rec['type'] . $rec['function'];
             } else {
                 $t['call'] .= $rec['function'];
             }
             $t['call'] .= '(';
             if (sizeof($rec['args'])) {
                 foreach ($rec['args'] as $arg) {
                     if (is_object($arg)) {
                         $t['call'] .= get_class($arg);
                     } else {
                         $arg = str_replace("\n", ' ', (string) $arg);
                         $t['call'] .= '"' . (strlen($arg) <= 30 ? $arg : substr($arg, 0, 25) . '[...]') . '"';
                     }
                     $t['call'] .= ', ';
                 }
                 $t['call'] = substr($t['call'], 0, -2);
             }
             $t['call'] .= ")";
         }
         $t['file'] = @$rec['file'] . ':' . @$rec['line'];
         $trace[] = $t;
     }
     $debug = new Zend_Wildfire_Plugin_FirePhp_TableMessage('Debug');
     $debug->setBuffered(true);
     $debug->setHeader(array('Value and BackTrace'));
     $debug->setOption('includeLineNumbers', false);
     foreach (func_get_args() as $var) {
         $debug->addRow(array($var));
     }
     $debug->addRow(array($trace));
     $where = basename($backtrace[0]["file"]) . ':' . $backtrace[0]["line"];
     $debug->setLabel("Debug: {$varName} ({$where})");
     Zend_Wildfire_Plugin_FirePhp::getInstance()->send($debug);
 }
 /**
  * Gets content panel for the Debugbar
  *
  * @return string
  */
 public function getPanel()
 {
     $this->_request = Zend_Controller_Front::getInstance()->getRequest();
     $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
     $viewVars = $viewRenderer->view->getVars();
     foreach ($viewVars as $k => $v) {
         $this->message->addRow(array($k . " - View", self::_cleanData($v)));
     }
     foreach ($this->_request->getParams() as $k => $v) {
         $this->message->addRow(array($k . " - Parameter", self::_cleanData($v)));
     }
     foreach ($this->_request->getCookie() as $k => $v) {
         $this->message->addRow(array($k . " - Cookie", self::_cleanData($v)));
     }
 }
 /**
  * Insert a record in the queries table
  *
  * @param Doctrine_Event $event the event to log
  *
  * @throws Zend_Db_Profiler_Exception
  *
  * @return void
  */
 public function recordEvent($event)
 {
     $this->message->setDestroy(false);
     // update time counter
     $this->totalElapsedTime += $event->getElapsedSecs();
     // add a row to the table
     $this->message->addRow(array((string) round($event->getElapsedSecs(), 5), $event->getQuery() ? $event->getQuery() : $event->getName(), ($params = $event->getParams()) ? $params : null));
     // increment number of queries
     $this->totalNumQueries++;
 }
Exemple #8
0
 /**
  * Gets content panel for the Debugbar
  *
  * @return string
  */
 public function getPanel()
 {
     $included = $this->_getIncludedFiles();
     $libraryFiles = array();
     foreach ($included as $file) {
         $file = str_replace($this->_basePath, '', $file);
         $this->message->addRow(array($file));
     }
     $this->message->addRow($libraryFiles);
 }
Exemple #9
0
 /**
  * Intercept the query end and log the profiling data.
  *
  * @param  integer $queryId
  * @throws Zend_Db_Profiler_Exception
  * @return void
  */
 public function queryEnd($queryId)
 {
     $state = parent::queryEnd($queryId);
     if (!$this->getEnabled() || $state == self::IGNORED) {
         return;
     }
     $this->_message->setDestroy(false);
     $profile = $this->getQueryProfile($queryId);
     $this->_totalElapsedTime += $profile->getElapsedSecs();
     $this->_message->addRow(array((string) round($profile->getElapsedSecs(), 5), $profile->getQuery(), ($params = $profile->getQueryParams()) ? $params : null));
     $this->updateMessageLabel();
 }
Exemple #10
0
 /**
  * method overloader
  * this method is used for invoking different listeners, for the full
  * list of availible listeners, see Doctrine_EventListener
  *
  * @param string $m     the name of the method
  * @param array $a      method arguments
  * @see Doctrine_EventListener
  * @return boolean
  */
 public function __call($methodName, $arguments)
 {
     if (!$arguments[0] instanceof Doctrine_Event) {
         throw new Doctrine_Connection_Profiler_Exception("Couldn't listen event. Event should be an instance of Doctrine_Event.");
     }
     if (substr($methodName, 0, 3) == 'pre') {
         $arguments[0]->start();
         if (!in_array($arguments[0], $this->_events, true)) {
             $this->_events[] = $arguments[0];
         }
     } else {
         // we need after-event listeners
         $arguments[0]->end();
         $this->_message->setDestroy(false);
         $this->_totalElapsedTime += $arguments[0]->getElapsedSecs();
         $row = array($arguments[0]->getName(), round($arguments[0]->getElapsedSecs(), 5), $arguments[0]->getQuery(), ($params = $arguments[0]->getParams()) ? $params : null);
         $this->_message->addRow($row);
         $this->updateMessageLabel();
     }
 }
Exemple #11
0
 public function stopQuery()
 {
     $elapsedTime = microtime(true) - $this->_currentQuery['executionMS'];
     $this->_totalElapsedTime += $elapsedTime;
     ++$this->_queryCount;
     $labelTime = round($elapsedTime, 5);
     $this->_message->addRow(array($labelTime, $this->_currentQuery['sql'], $this->_currentQuery['parameters']));
     $this->_updateMessageLabel();
     if (!is_null($this->_criticalQueriesLogger)) {
         if ($labelTime >= self::DURATION_LIMIT) {
             $query = $this->_currentQuery['sql'];
             $params = $this->_currentQuery['parameters'];
             $log = sprintf(PHP_EOL . 'TIME: %f' . PHP_EOL, $labelTime);
             if (count($params) > 0) {
                 $queryWithParams = '';
                 $queryPieces = explode('?', $query);
                 foreach ($queryPieces as $key => $queryPiece) {
                     if (isset($params[$key])) {
                         if (is_numeric($params[$key]) || is_bool($params[$key])) {
                             $queryWithParams .= $params[$key];
                         } else {
                             $params[$key] = str_replace("'", "''", $params[$key]);
                             $queryWithParams .= "'{$params[$key]}'";
                         }
                     }
                     $queryWithParams .= $queryPiece;
                 }
                 $log .= sprintf('QUERY (WITH BOUND PARAMETERS):' . PHP_EOL . '%s' . PHP_EOL . PHP_EOL . 'QUERY (ORIGINAL):' . PHP_EOL . '%s' . PHP_EOL . PHP_EOL . 'BOUND PARAMETERS:' . PHP_EOL . '%s', $queryWithParams, $query, print_r($params, true));
             } else {
                 $log .= sprintf('QUERY:' . PHP_EOL . '%s', $query);
             }
             $request = \Zend_Controller_Front::getInstance()->getRequest();
             $log .= PHP_EOL . 'ROUTE: ';
             $log .= $request->getModuleName();
             $log .= '/' . $request->getControllerName();
             $log .= '/' . $request->getActionName() . PHP_EOL;
             $log .= PHP_EOL . PHP_EOL . '_______________________________________________________________________________';
             $this->_criticalQueriesLogger->log($log, \Zend_Log::DEBUG);
         }
     }
 }
Exemple #12
0
 /**
  * Display profiling results and flush output buffer
  */
 public function display()
 {
     $firebugMessage = new Zend_Wildfire_Plugin_FirePhp_TableMessage($this->_renderCaption());
     $firebugMessage->setHeader(array_keys($this->_getColumns()));
     foreach ($this->_getTimers() as $timerId) {
         $row = array();
         foreach ($this->_getColumns() as $columnId) {
             $row[] = $this->_renderColumnValue($timerId, $columnId);
         }
         $firebugMessage->addRow($row);
     }
     Zend_Wildfire_Plugin_FirePhp::getInstance()->send($firebugMessage);
     // setup the wildfire channel
     $firebugChannel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
     $firebugChannel->setRequest($this->_request ? $this->_request : new Zend_Controller_Request_Http());
     $firebugChannel->setResponse($this->_response ? $this->_response : new Zend_Controller_Response_Http());
     // flush the wildfire headers into the response object
     $firebugChannel->flush();
     // send the response headers
     $firebugChannel->getResponse()->sendHeaders();
     ob_end_flush();
 }
Exemple #13
0
 public static function log($message, $levl = Zend_Log::INFO, $data = null)
 {
     if (Zend_Registry::isRegistered('logger')) {
         $logger = Zend_Registry::get('logger');
         /**
          * прислали что то на вардамп
          */
         if (null != $data) {
             /**
              * 
              * сделаем табличку
              * @var unknown_type
              */
             $_message = new Zend_Wildfire_Plugin_FirePhp_TableMessage($message);
             $_message->setHeader(array('Data'));
             $_message->addRow(array($data));
             $logger->log($_message, $levl);
         } else {
             $logger->log($message, $levl, $extras);
         }
     }
 }
Exemple #14
0
 /**
  * Display profiling results and flush output buffer
  *
  * @param Stat $stat
  * @return void
  */
 public function display(Stat $stat)
 {
     $firebugMessage = new \Zend_Wildfire_Plugin_FirePhp_TableMessage($this->_renderCaption());
     $firebugMessage->setHeader(array_keys($this->_columns));
     foreach ($this->_getTimerIds($stat) as $timerId) {
         $row = array();
         foreach ($this->_columns as $column) {
             $row[] = $this->_renderColumnValue($stat->fetch($timerId, $column), $column);
         }
         $firebugMessage->addRow($row);
     }
     \Zend_Wildfire_Plugin_FirePhp::send($firebugMessage);
     // setup the wildfire channel
     $firebugChannel = \Zend_Wildfire_Channel_HttpHeaders::getInstance();
     $firebugChannel->setRequest($this->getRequest());
     $firebugChannel->setResponse($this->getResponse());
     // flush the wildfire headers into the response object
     $firebugChannel->flush();
     // send the response headers
     $firebugChannel->getResponse()->sendHeaders();
     ob_end_flush();
 }
Exemple #15
0
 /**
  * getGenerateTime
  *
  * @param   string $aComment
  * @return  string time
  */
 public static function getGenerateTime($aComment = "")
 {
     if (!self::$_enabled) {
         return;
     }
     $back = debug_backtrace();
     $_time = microtime(true);
     list($mTotal, $mSec) = self::getMemoryUsage();
     if (!isset(self::$_time) && defined('START_TIMER')) {
         self::$_time["start"] = START_TIMER;
         self::$_time["section"] = START_TIMER;
     }
     if (!isset(self::$_time)) {
         self::$_time["start"] = $_time;
         self::$_time["section"] = $_time;
         self::$_timer->addRow(array(sprintf("%01.4f", 0), sprintf("%01.4f", 0), $mSec, $mTotal, $aComment, basename(@$back[0]["file"]) . ':' . @$back[0]["line"]));
     } else {
         $start = self::$_time["section"];
         self::$_time["section"] = $_time;
         self::$_timer->addRow(array(sprintf("%01.4f", round(self::$_time["section"] - $start, 4)), sprintf("%01.4f", round(self::$_time["section"] - self::$_time["start"], 4)), $mSec, $mTotal, $aComment, basename(@$back[0]["file"]) . ':' . @$back[0]["line"]));
     }
     self::updateMessageLabel();
     Zend_Wildfire_Plugin_FirePhp::getInstance()->send(self::$_timer);
 }
Exemple #16
0
 /**
  * Constructs and send the profiles table.
  *
  * @param Zend_Wildfire_Plugin_FirePhp_TableMessage $profiles
  * @return array Retrieves an array with the queries profiles
  */
 private function _setProfiles(Zend_Wildfire_Plugin_FirePhp_TableMessage $profiles)
 {
     // Get the profiles
     $db = Zend_Registry::get('db');
     $sth = $db->query(self::DONT_PROFILE . 'show profiles');
     $rows = $sth->fetchAll();
     $queryIds = array();
     foreach ($rows as $row) {
         // Profile only queries marked as profile
         if (!(strpos($row['Query'], self::DONT_PROFILE) === false)) {
             continue;
         }
         $queryIds[] = $row['Query_ID'];
         $values = array_values($row);
         $profiles->addRow($values);
     }
     return $queryIds;
 }
 /**
  * @group ZF-5742
  */
 public function testTableMessage()
 {
     $table = new Zend_Wildfire_Plugin_FirePhp_TableMessage('TestMessage');
     $this->assertEquals($table->getLabel(), 'TestMessage');
     try {
         $table->getLastRow();
         $this->fail('Should throw exception when no rows exist');
     } catch (Exception $e) {
         // success
     }
     $row = array('col1', 'col2');
     $this->assertEquals($table->getRowCount(), 0);
     try {
         $table->getRowAt(1);
         $this->fail('Should throw exception as no rows present');
     } catch (Exception $e) {
         // success
     }
     try {
         $table->setRowAt(1, array());
         $this->fail('Should throw exception as no rows present');
     } catch (Exception $e) {
         // success
     }
     $table->addRow($row);
     $this->assertEquals($table->getMessage(), array($row));
     $this->assertEquals($table->getLastRow(), $row);
     $this->assertEquals($table->getRowCount(), 1);
     $table->addRow($row);
     $this->assertEquals($table->getMessage(), array($row, $row));
     $this->assertEquals($table->getRowCount(), 2);
     $this->assertEquals($table->getLastRow(), $row);
     try {
         $table->getRowAt(2);
         $this->fail('Should throw exception as index is out of bounds');
     } catch (Exception $e) {
         // success
     }
     try {
         $table->setRowAt(2, array());
         $this->fail('Should throw exception as index is out of bounds');
     } catch (Exception $e) {
         // success
     }
     $rowOld = $table->getRowAt(1);
     $this->assertEquals($rowOld, $row);
     $rowOld[1] = 'Column2';
     $table->setRowAt(1, $rowOld);
     $this->assertEquals($table->getRowAt(1), $rowOld);
     $this->assertEquals($table->getLastRow(), $rowOld);
     $this->assertEquals($table->getMessage(), array($row, $rowOld));
     $header = array('hc1', 'hc2');
     $table->setHeader($header);
     $this->assertEquals($table->getMessage(), array($header, $row, $rowOld));
 }