Development

/branches/1.4/lib/plugins/sfPropelPlugin/lib/debug/sfWebDebugPanelPropel.class.php

You must first sign up to be able to contribute.

root/branches/1.4/lib/plugins/sfPropelPlugin/lib/debug/sfWebDebugPanelPropel.class.php

Revision 27284, 3.8 kB (checked in by Kris.Wallsmith, 4 years ago)

[1.3, 1.4] fixed empty class attributes in WDT markup (closes #8196)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11
12
13 /**
14  * sfWebDebugPanelPropel adds a panel to the web debug toolbar with Propel information.
15  *
16  * @package    symfony
17  * @subpackage debug
18  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
19  * @version    SVN: $Id$
20  */
21 class sfWebDebugPanelPropel extends sfWebDebugPanel
22 {
23   /**
24    * Get the title/icon for the panel
25    *
26    * @return string $html
27    */
28   public function getTitle()
29   {
30     if ($sqlLogs = $this->getSqlLogs())
31     {
32       return '<img src="'.$this->webDebug->getOption('image_root_path').'/database.png" alt="SQL queries" /> '.count($sqlLogs);
33     }
34   }
35
36   /**
37    * Get the verbal title of the panel
38    *
39    * @return string $title
40    */
41   public function getPanelTitle()
42   {
43     return 'SQL queries';
44   }
45
46   /**
47    * Get the html content of the panel
48    *
49    * @return string $html
50    */
51   public function getPanelContent()
52   {
53     return '
54       <div id="sfWebDebugDatabaseLogs">
55         <h3>Propel Version: '.Propel::VERSION.'</h3>
56         <ol>'.implode("\n", $this->getSqlLogs()).'</ol>
57       </div>
58     ';
59   }
60
61   /**
62    * Listens to debug.web.load_panels and adds this panel.
63    */
64   static public function listenToAddPanelEvent(sfEvent $event)
65   {
66     $event->getSubject()->setPanel('db', new self($event->getSubject()));
67   }
68
69   /**
70    * Builds the sql logs and returns them as an array.
71    *
72    * @return array
73    */
74   protected function getSqlLogs()
75   {
76     $config    = $this->getPropelConfiguration();
77     $outerGlue = $config->getParameter('debugpdo.logging.outerglue', ' | ');
78     $innerGlue = $config->getParameter('debugpdo.logging.innerglue', ': ');
79     $flagSlow  = $config->getParameter('debugpdo.logging.details.slow.enabled', false);
80     $threshold = $config->getParameter('debugpdo.logging.details.slow.threshold', DebugPDO::DEFAULT_SLOW_THRESHOLD);
81
82     $html = array();
83     foreach ($this->webDebug->getLogger()->getLogs() as $log)
84     {
85       if ('sfPropelLogger' != $log['type'])
86       {
87         continue;
88       }
89
90       $details = array();
91       $slowQuery = false;
92
93       $parts = explode($outerGlue, $log['message']);
94       foreach ($parts as $i => $part)
95       {
96         // is this a key-glue-value fragment ?
97         if (preg_match('/^(\w+)'.preg_quote($innerGlue, '/').'(.*)/', $part, $match))
98         {
99           $details[] = $part;
100           unset($parts[$i]);
101
102           // check for slow query
103           if ('time' == $match[1])
104           {
105             if ($flagSlow && (float) $match[2] > $threshold)
106             {
107               $slowQuery = true;
108               if ($this->getStatus() > sfLogger::NOTICE)
109               {
110                 $this->setStatus(sfLogger::NOTICE);
111               }
112             }
113           }
114         }
115       }
116       // all stuff that has not been eaten by the loop should be the query string
117       $query = join($outerGlue, $parts);
118
119       $query = $this->formatSql(htmlspecialchars($query, ENT_QUOTES, sfConfig::get('sf_charset')));
120       $backtrace = isset($log['debug_backtrace']) && count($log['debug_backtrace']) ? '&nbsp;'.$this->getToggleableDebugStack($log['debug_backtrace']) : '';
121
122       $html[] = sprintf('
123         <li%s>
124           <p class="sfWebDebugDatabaseQuery">%s</p>
125           <div class="sfWebDebugDatabaseLogInfo">%s%s</div>
126         </li>',
127         $slowQuery ? ' class="sfWebDebugWarning"' : '',
128         $query,
129         implode(', ', $details),
130         $backtrace
131       );
132     }
133
134     return $html;
135   }
136
137   /**
138    * Returns the current PropelConfiguration.
139    *
140    * @return PropelConfiguration
141    */
142   protected function getPropelConfiguration()
143   {
144     return Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT);
145   }
146 }
147
Note: See TracBrowser for help on using the browser.