| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfWebDebugPanelPropel extends sfWebDebugPanel |
|---|
| 20 |
{ |
|---|
| 21 |
|
|---|
| 22 |
* Constructor. |
|---|
| 23 |
* |
|---|
| 24 |
* @param sfWebDebug $webDebug The web debut toolbar instance |
|---|
| 25 |
*/ |
|---|
| 26 |
public function __construct(sfWebDebug $webDebug) |
|---|
| 27 |
{ |
|---|
| 28 |
parent::__construct($webDebug); |
|---|
| 29 |
|
|---|
| 30 |
$this->webDebug->getEventDispatcher()->connect('debug.web.filter_logs', array($this, 'filterLogs')); |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
public function getTitle() |
|---|
| 34 |
{ |
|---|
| 35 |
if ($sqlLogs = $this->getSqlLogs()) |
|---|
| 36 |
{ |
|---|
| 37 |
return '<img src="'.$this->webDebug->getOption('image_root_path').'/database.png" alt="SQL queries" /> '.count($sqlLogs); |
|---|
| 38 |
} |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
public function getPanelTitle() |
|---|
| 42 |
{ |
|---|
| 43 |
return 'SQL queries'; |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
public function getPanelContent() |
|---|
| 47 |
{ |
|---|
| 48 |
$logs = array(); |
|---|
| 49 |
foreach ($this->getSqlLogs() as $log) |
|---|
| 50 |
{ |
|---|
| 51 |
$logs[] = htmlspecialchars($log, ENT_QUOTES, sfConfig::get('sf_charset')); |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
return ' |
|---|
| 55 |
<div id="sfWebDebugDatabaseLogs"> |
|---|
| 56 |
<ol><li>'.implode("</li>\n<li>", $logs).'</li></ol> |
|---|
| 57 |
</div> |
|---|
| 58 |
'; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
public function filterLogs(sfEvent $event, $logs) |
|---|
| 62 |
{ |
|---|
| 63 |
$newLogs = array(); |
|---|
| 64 |
foreach ($logs as $log) |
|---|
| 65 |
{ |
|---|
| 66 |
if ('sfPropelLogger' != $log['type']) |
|---|
| 67 |
{ |
|---|
| 68 |
$newLogs[] = $log; |
|---|
| 69 |
} |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
return $newLogs; |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
static public function listenToAddPanelEvent(sfEvent $event) |
|---|
| 76 |
{ |
|---|
| 77 |
$event->getSubject()->setPanel('db', new self($event->getSubject())); |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
protected function getSqlLogs() |
|---|
| 81 |
{ |
|---|
| 82 |
$logs = array(); |
|---|
| 83 |
$bindings = array(); |
|---|
| 84 |
$i = 0; |
|---|
| 85 |
foreach ($this->webDebug->getLogger()->getLogs() as $log) |
|---|
| 86 |
{ |
|---|
| 87 |
if ('sfPropelLogger' != $log['type']) |
|---|
| 88 |
{ |
|---|
| 89 |
continue; |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
if (preg_match('/^(?:prepare|exec|query): (.*)$/s', $log['message'], $match)) |
|---|
| 93 |
{ |
|---|
| 94 |
$logs[$i++] = $match[1]; |
|---|
| 95 |
$bindings[$i - 1] = array(); |
|---|
| 96 |
} |
|---|
| 97 |
else if (preg_match('/Binding (.*) at position (.+?) w\//', $log['message'], $match)) |
|---|
| 98 |
{ |
|---|
| 99 |
$bindings[$i - 1][$match[2]] = $match[1]; |
|---|
| 100 |
} |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
foreach ($logs as $i => $log) |
|---|
| 104 |
{ |
|---|
| 105 |
if (count($bindings[$i])) |
|---|
| 106 |
{ |
|---|
| 107 |
$bindings[$i] = array_reverse($bindings[$i]); |
|---|
| 108 |
foreach ($bindings[$i] as $search => $replace) |
|---|
| 109 |
{ |
|---|
| 110 |
$logs[$i] = str_replace($search, $replace, $logs[$i]); |
|---|
| 111 |
} |
|---|
| 112 |
} |
|---|
| 113 |
} |
|---|
| 114 |
|
|---|
| 115 |
return $logs; |
|---|
| 116 |
} |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|