danceric / zfdebugdoctrine

Doctrine ORM & Zend Framework & ZFDebug

This URL has Read+Write access

danceric (author)
Thu Oct 29 17:39:10 -0700 2009
commit  eed7c9beebec626b66f646812b75061c9c6a198f
tree    ee96f322a47b288cbff30a431cfd377ddc04ccc3
parent  591e7ad2fa4494b9d6b442ebdecd95fbba13ac20
4749cbda » danceric 2009-06-06 initial import 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 corrected plugin idenfifier 22 protected $_identifier = 'doctrine';
4749cbda » danceric 2009-06-06 initial import 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 cleaned up log output 96 if (in_array($event->getName(), array('query', 'execute', 'exec'))) {
97 $info = htmlspecialchars($event->getQuery());
4749cbda » danceric 2009-06-06 initial import 98 } else {
aad3cfd4 » danceric 2009-06-14 cleaned up log output 99 $info = '<em>' . htmlspecialchars($event->getName()) . '</em>';
4749cbda » danceric 2009-06-06 initial import 100 }
aad3cfd4 » danceric 2009-06-14 cleaned up log output 101
4749cbda » danceric 2009-06-06 initial import 102 $html .= '<li><strong>[' . round($event->getElapsedSecs()*1000, 2) . ' ms]</strong> ';
aad3cfd4 » danceric 2009-06-14 cleaned up log output 103 $html .= $info;
104
4749cbda » danceric 2009-06-06 initial import 105 $params = $event->getParams();
aad3cfd4 » danceric 2009-06-14 cleaned up log output 106 if(!empty($params)) {
107 $html .= '<ul><em>bindings:</em> <li>'. implode('</li><li>', $params) . '</li></ul>';
4749cbda » danceric 2009-06-06 initial import 108 }
aad3cfd4 » danceric 2009-06-14 cleaned up log output 109 $html .= '</li>';
4749cbda » danceric 2009-06-06 initial import 110 }
111 $html .= '</ol>';
112 }
113
114 return $html;
115 }
116
117 }