diff --git a/library/ZFDebug/Controller/Plugin/Debug/Plugin/Database.php b/library/ZFDebug/Controller/Plugin/Debug/Plugin/Database.php index 5ad1e86..8b8bf01 100644 --- a/library/ZFDebug/Controller/Plugin/Debug/Plugin/Database.php +++ b/library/ZFDebug/Controller/Plugin/Debug/Plugin/Database.php @@ -101,6 +101,7 @@ public function getTab() if (!$this->_db) return 'No adapter'; + $adapterInfo = array(); foreach ($this->_db as $adapter) { $profiler = $adapter->getProfiler(); $adapterInfo[] = $profiler->getTotalNumQueries() . ' in ' @@ -141,7 +142,7 @@ public function getProfile() if ($profiles = $adapter->getProfiler()->getQueryProfiles()) { $adapter->getProfiler()->setEnabled(false); if (1 < count($this->_db)) { - $html .= '

Adapter '.$name.'

'; + $queries .= '

Adapter '.$name.'

'; } $queries .=''; foreach ($profiles as $profile) { diff --git a/library/ZFDebug/Controller/Plugin/Debug/Plugin/Doctrine2.php b/library/ZFDebug/Controller/Plugin/Debug/Plugin/Doctrine2.php new file mode 100644 index 0000000..ecf1321 --- /dev/null +++ b/library/ZFDebug/Controller/Plugin/Debug/Plugin/Doctrine2.php @@ -0,0 +1,163 @@ +_em = $options['entityManagers']; + } + } + + /** + * Gets icon + * @return string + */ + public function getIconData() + { + return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAidJREFUeNqUk9tLFHEUxz+/mdnZnV1Tt5ttWVC+pBG+9RAYRNBDICT5D1hgL/VQWRAVEfVoCGURhCBFEj6IRkRFF7BAxPZlIbvZBTQq0q677u5c9tdvZyPaS1QHZh7OnPM93/me8xWC4rAnR6WbuAdSYjRvwWzaVFpSFEZpwvvwGnu4GwJB5OwMfwutNKHXrQFrASJcjTM+RPJMh/wvALOpRVh7+pC6gahegjMxQvLsTvnPAHkN5NxbhB5AfptDy4OMD5PsrQwiRElz5uoJvKdjaMsb0FesxX3yEBGsQiY/YWxopWpvv/gjg8zgSXJvEojapVid5wl3DRLc3qWYfCz8ztgQqf6DsiJA5vZFmZuKIyI1kPyC9zJOvjLYuh9zx2Hk5/doNXU4Dwawpx7JMgA3cVe9VT4YRl/djHOnDzd+vQDSdgiz7QAy9RUcG29ytPwOcrPTiEX1RI7fQqhJeDbSdRVmTn30CLUfhfnvZEdOI7PpChoYAVWo5rmOz0R6XoER4ueTx/IKsv8m/S8G+sp1OK8ukzq1DS1cS85OY+3qwWhs8W8ic+UIzv1LSqMoWjRWziCwsV1dkQWKnjf9WIm3z2/OR1Y12zcvqHWG0RbG0GIN5QDm+s3C3LrbXxmBECK6rLCdgWN+M5a6hew8oc7eIoOJUqulr/VI+8Y5pJP2p+VmnkEogrZ4FaGO7jJ3ikpezV+k93wC790L31R6faNPu5K1fwgwAMKf1kgHZKePAAAAAElFTkSuQmCC'; + } + + /** + * Gets identifier for this plugin + * + * @return string + */ + public function getIdentifier() + { + return $this->_identifier; + } + + /** + * Gets menu tab for the Debugbar + * + * @return string + */ + public function getTab() + { + if (!$this->_em) + return 'No entitymanagers available'; + $adapterInfo = array(); + + foreach ($this->_em as $em) { + if ($logger = $em->getConnection()->getConfiguration()->getSqlLogger()) { + $totalTime = 0; + foreach($logger->queries as $query) { + $totalTime += $query['executionMS']; + } + $adapterInfo[] = count($logger->queries) . ' in ' . round($totalTime * 1000, 2) . ' ms'; + } + } + $html = implode(' / ', $adapterInfo); + + return $html; + } + + /** + * Gets content panel for the Debug bar + * + * @return string + */ + public function getPanel() + { + if (!$this->_em) + return ''; + + $html = '

Doctrine2 queries - Doctrine2 (Common v' . Doctrine\Common\Version::VERSION . + ' | DBAL v' . Doctrine\DBAL\Version::VERSION . + ' | ORM v' . Doctrine\ORM\Version::VERSION . + ')

'; + + foreach ($this->_em as $name => $em) { + $html .= '

EntityManager ' . $name . '

'; + if ($logger = $em->getConnection()->getConfiguration()->getSqlLogger()) { + $html .= $this->getProfile($logger); + } else { + $html .= "No logger enabled!"; + } + } + + return $html; + } + + /** + * Gets sql queries from the logger + * @param $logger + * @return string + */ + protected function getProfile($logger) + { + $queries = '
'; + foreach($logger->queries as $query) { + + $queries .= "\n\n\n\n"; + } + $queries .= "
\n" + . sprintf('%0.2f', round($query['executionMS']*1000, 2)) + . "ms"; + $params = array(); + if(!empty($query['params'])) { + $params = $query['params']; + array_walk($params, array($this, '_addQuotes')); + } + $paramCount = count($params); + if ($paramCount) { + $queries .= htmlspecialchars(preg_replace(array_fill(0, $paramCount, '/\?/'), $params, $query['sql'], 1)); + } else { + $queries .= htmlspecialchars($query['sql']); + } + $queries .= "
\n"; + return $queries; + } + + /** + * Add quotes to query params + * @param mixed $value + * @param mixed $key + * @return void + */ + protected function _addQuotes(&$value, $key) + { + $value = "'" . $value . "'"; + } + +} \ No newline at end of file