danceric / zfdebugdoctrine
- Source
- Commits
- Network (2)
- Issues (0)
- Downloads (1)
- Wiki (1)
- Graphs
-
Tree:
eed7c9b
commit eed7c9beebec626b66f646812b75061c9c6a198f
tree ee96f322a47b288cbff30a431cfd377ddc04ccc3
parent 591e7ad2fa4494b9d6b442ebdecd95fbba13ac20
tree ee96f322a47b288cbff30a431cfd377ddc04ccc3
parent 591e7ad2fa4494b9d6b442ebdecd95fbba13ac20
| 4749cbda » | danceric | 2009-06-06 | 1 | <?php | |
| 2 | /** | ||||
| 3 | * ZFDebug Doctrine ORM plugin | ||||
| 4 | * | ||||
| 5 | * @category Danceric | ||||
| 6 | * @package Danceric_Controller | ||||
| 7 | * @subpackage Plugins | ||||
| 8 | */ | ||||
| 9 | |||||
| 10 | /** | ||||
| 11 | * @category Danceric | ||||
| 12 | * @package Danceric_Controller | ||||
| 13 | * @subpackage Plugins | ||||
| 14 | */ | ||||
| 15 | class Danceric_Controller_Plugin_Debug_Plugin_Doctrine extends ZFDebug_Controller_Plugin_Debug_Plugin implements ZFDebug_Controller_Plugin_Debug_Plugin_Interface | ||||
| 16 | { | ||||
| 17 | /** | ||||
| 18 | * Contains plugin identifier name | ||||
| 19 | * | ||||
| 20 | * @var string | ||||
| 21 | */ | ||||
| 2c335d96 » | danceric | 2009-06-14 | 22 | protected $_identifier = 'doctrine'; | |
| 4749cbda » | danceric | 2009-06-06 | 23 | ||
| 24 | /** | ||||
| 25 | * @var array Doctrine connection profiler that will listen to events | ||||
| 26 | */ | ||||
| 27 | protected $_profilers = array(); | ||||
| 28 | |||||
| 29 | /** | ||||
| 30 | * Create ZFDebug_Controller_Plugin_Debug_Plugin_Variables | ||||
| 31 | * | ||||
| 32 | * @param Doctrine_Manager|array $options | ||||
| 33 | * @return void | ||||
| 34 | */ | ||||
| 35 | public function __construct(array $options = array()) | ||||
| 36 | { | ||||
| 37 | if(!isset($options['manager']) || !count($options['manager'])) { | ||||
| 38 | if (Doctrine_Manager::getInstance()) { | ||||
| 39 | $options['manager'] = Doctrine_Manager::getInstance(); | ||||
| 40 | } | ||||
| 41 | } | ||||
| 42 | |||||
| 43 | foreach ($options['manager']->getIterator() as $connection) { | ||||
| 44 | $this->_profilers[$connection->getName()] = new Doctrine_Connection_Profiler(); | ||||
| 45 | $connection->setListener($this->_profilers[$connection->getName()]); | ||||
| 46 | } | ||||
| 47 | } | ||||
| 48 | |||||
| 49 | /** | ||||
| 50 | * Gets identifier for this plugin | ||||
| 51 | * | ||||
| 52 | * @return string | ||||
| 53 | */ | ||||
| 54 | public function getIdentifier() | ||||
| 55 | { | ||||
| 56 | return $this->_identifier; | ||||
| 57 | } | ||||
| 58 | |||||
| 59 | /** | ||||
| 60 | * Gets menu tab for the Debugbar | ||||
| 61 | * | ||||
| 62 | * @return string | ||||
| 63 | */ | ||||
| 64 | public function getTab() | ||||
| 65 | { | ||||
| 66 | if (!$this->_profilers) | ||||
| 67 | return 'No Profiler'; | ||||
| 68 | |||||
| 69 | foreach ($this->_profilers as $profiler) { | ||||
| 70 | $time = 0; | ||||
| 71 | foreach ($profiler as $event) { | ||||
| 72 | $time += $event->getElapsedSecs(); | ||||
| 73 | } | ||||
| 74 | $profilerInfo[] = $profiler->count() . ' in ' . round($time*1000, 2) . ' ms'; | ||||
| 75 | } | ||||
| 76 | $html = implode(' / ', $profilerInfo); | ||||
| 77 | |||||
| 78 | return $html; | ||||
| 79 | } | ||||
| 80 | |||||
| 81 | /** | ||||
| 82 | * Gets content panel for the Debugbar | ||||
| 83 | * | ||||
| 84 | * @return string | ||||
| 85 | */ | ||||
| 86 | public function getPanel() | ||||
| 87 | { | ||||
| 88 | if (!$this->_profilers) | ||||
| 89 | return ''; | ||||
| 90 | |||||
| 91 | $html = '<h4>Database queries</h4>'; | ||||
| 92 | |||||
| 93 | foreach ($this->_profilers as $name => $profiler) { | ||||
| 94 | $html .= '<h4>Connection '.$name.'</h4><ol>'; | ||||
| 95 | foreach ($profiler as $event) { | ||||
| aad3cfd4 » | danceric | 2009-06-14 | 96 | if (in_array($event->getName(), array('query', 'execute', 'exec'))) { | |
| 97 | $info = htmlspecialchars($event->getQuery()); | ||||
| 4749cbda » | danceric | 2009-06-06 | 98 | } else { | |
| aad3cfd4 » | danceric | 2009-06-14 | 99 | $info = '<em>' . htmlspecialchars($event->getName()) . '</em>'; | |
| 4749cbda » | danceric | 2009-06-06 | 100 | } | |
| aad3cfd4 » | danceric | 2009-06-14 | 101 | ||
| 4749cbda » | danceric | 2009-06-06 | 102 | $html .= '<li><strong>[' . round($event->getElapsedSecs()*1000, 2) . ' ms]</strong> '; | |
| aad3cfd4 » | danceric | 2009-06-14 | 103 | $html .= $info; | |
| 104 | |||||
| 4749cbda » | danceric | 2009-06-06 | 105 | $params = $event->getParams(); | |
| aad3cfd4 » | danceric | 2009-06-14 | 106 | if(!empty($params)) { | |
| 107 | $html .= '<ul><em>bindings:</em> <li>'. implode('</li><li>', $params) . '</li></ul>'; | ||||
| 4749cbda » | danceric | 2009-06-06 | 108 | } | |
| aad3cfd4 » | danceric | 2009-06-14 | 109 | $html .= '</li>'; | |
| 4749cbda » | danceric | 2009-06-06 | 110 | } | |
| 111 | $html .= '</ol>'; | ||||
| 112 | } | ||||
| 113 | |||||
| 114 | return $html; | ||||
| 115 | } | ||||
| 116 | |||||
| 117 | } | ||||
