| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
abstract class sfWebDebugPanel |
|---|
| 20 |
{ |
|---|
| 21 |
protected |
|---|
| 22 |
$webDebug = null, |
|---|
| 23 |
$status = sfLogger::INFO; |
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
* Constructor. |
|---|
| 27 |
* |
|---|
| 28 |
* @param sfWebDebug $webDebug The web debug toolbar instance |
|---|
| 29 |
*/ |
|---|
| 30 |
public function __construct(sfWebDebug $webDebug) |
|---|
| 31 |
{ |
|---|
| 32 |
$this->webDebug = $webDebug; |
|---|
| 33 |
} |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
* Gets the link URL for the link. |
|---|
| 37 |
* |
|---|
| 38 |
* @return string The URL link |
|---|
| 39 |
*/ |
|---|
| 40 |
public function getTitleUrl() |
|---|
| 41 |
{ |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
* Gets the text for the link. |
|---|
| 46 |
* |
|---|
| 47 |
* @return string The link text |
|---|
| 48 |
*/ |
|---|
| 49 |
abstract public function getTitle(); |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
* Gets the title of the panel. |
|---|
| 53 |
* |
|---|
| 54 |
* @return string The panel title |
|---|
| 55 |
*/ |
|---|
| 56 |
abstract public function getPanelTitle(); |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
* Gets the panel HTML content. |
|---|
| 60 |
* |
|---|
| 61 |
* @return string The panel HTML content |
|---|
| 62 |
*/ |
|---|
| 63 |
abstract public function getPanelContent(); |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
* Returns the current status. |
|---|
| 67 |
* |
|---|
| 68 |
* @return integer A {@link sfLogger} priority constant |
|---|
| 69 |
*/ |
|---|
| 70 |
public function getStatus() |
|---|
| 71 |
{ |
|---|
| 72 |
return $this->status; |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
* Sets the current panel's status. |
|---|
| 77 |
* |
|---|
| 78 |
* @param integer $status A {@link sfLogger} priority constant |
|---|
| 79 |
*/ |
|---|
| 80 |
public function setStatus($status) |
|---|
| 81 |
{ |
|---|
| 82 |
$this->status = $status; |
|---|
| 83 |
} |
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
* Returns a toggler element. |
|---|
| 87 |
* |
|---|
| 88 |
* @param string $element The value of an element's DOM id attribute |
|---|
| 89 |
* @param string $title A title attribute |
|---|
| 90 |
* |
|---|
| 91 |
* @return string |
|---|
| 92 |
*/ |
|---|
| 93 |
public function getToggler($element, $title = 'Toggle details') |
|---|
| 94 |
{ |
|---|
| 95 |
return '<a href="#" onclick="sfWebDebugToggle(\''.$element.'\'); return false;" title="'.$title.'"><img src="'.$this->webDebug->getOption('image_root_path').'/toggle.gif" alt="'.$title.'"/></a>'; |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
* Returns a toggleable presentation of a debug stack. |
|---|
| 100 |
* |
|---|
| 101 |
* @param array $debugStack |
|---|
| 102 |
* |
|---|
| 103 |
* @return string |
|---|
| 104 |
*/ |
|---|
| 105 |
public function getToggleableDebugStack($debugStack) |
|---|
| 106 |
{ |
|---|
| 107 |
static $i = 1; |
|---|
| 108 |
|
|---|
| 109 |
if (!$debugStack) |
|---|
| 110 |
{ |
|---|
| 111 |
return ''; |
|---|
| 112 |
} |
|---|
| 113 |
|
|---|
| 114 |
$element = get_class($this).'Debug'.$i++; |
|---|
| 115 |
$keys = array_reverse(array_keys($debugStack)); |
|---|
| 116 |
|
|---|
| 117 |
$html = $this->getToggler($element, 'Toggle debug stack'); |
|---|
| 118 |
$html .= '<div class="sfWebDebugDebugInfo" id="'.$element.'" style="display:none">'; |
|---|
| 119 |
foreach ($debugStack as $j => $trace) |
|---|
| 120 |
{ |
|---|
| 121 |
$file = isset($trace['file']) ? $trace['file'] : null; |
|---|
| 122 |
$line = isset($trace['line']) ? $trace['line'] : null; |
|---|
| 123 |
|
|---|
| 124 |
$isProjectFile = $file && 0 === strpos($file, sfConfig::get('sf_root_dir')) && !preg_match('/(cache|plugins|vendor)/', $file); |
|---|
| 125 |
|
|---|
| 126 |
$html .= sprintf('<span%s>#%s » ', $isProjectFile ? ' class="sfWebDebugHighlight"' : '', $keys[$j] + 1); |
|---|
| 127 |
|
|---|
| 128 |
if (isset($trace['function'])) |
|---|
| 129 |
{ |
|---|
| 130 |
$html .= sprintf('in <span class="sfWebDebugLogInfo">%s%s%s()</span> ', |
|---|
| 131 |
isset($trace['class']) ? $trace['class'] : '', |
|---|
| 132 |
isset($trace['type']) ? $trace['type'] : '', |
|---|
| 133 |
$trace['function'] |
|---|
| 134 |
); |
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
$html .= sprintf('from %s line %s', $this->formatFileLink($file, $line), $line); |
|---|
| 138 |
$html .= '</span><br/>'; |
|---|
| 139 |
} |
|---|
| 140 |
$html .= "</div>\n"; |
|---|
| 141 |
|
|---|
| 142 |
return $html; |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
* Formats a file link. |
|---|
| 147 |
* |
|---|
| 148 |
* @param string $file A file path or class name |
|---|
| 149 |
* @param integer $line |
|---|
| 150 |
* @param string $text Text to use for the link |
|---|
| 151 |
* |
|---|
| 152 |
* @return string |
|---|
| 153 |
*/ |
|---|
| 154 |
public function formatFileLink($file, $line = null, $text = null) |
|---|
| 155 |
{ |
|---|
| 156 |
|
|---|
| 157 |
if ($file && !sfToolkit::isPathAbsolute($file)) |
|---|
| 158 |
{ |
|---|
| 159 |
if (null === $text) |
|---|
| 160 |
{ |
|---|
| 161 |
$text = $file; |
|---|
| 162 |
} |
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 |
$r = new ReflectionClass($file); |
|---|
| 166 |
$file = $r->getFileName(); |
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
$shortFile = sfDebug::shortenFilePath($file); |
|---|
| 170 |
|
|---|
| 171 |
if ($linkFormat = sfConfig::get('sf_file_link_format', ini_get('xdebug.file_link_format'))) |
|---|
| 172 |
{ |
|---|
| 173 |
|
|---|
| 174 |
return sprintf( |
|---|
| 175 |
'<a href="%s" class="sfWebDebugFileLink" title="%s">%s</a>', |
|---|
| 176 |
htmlspecialchars(strtr($linkFormat, array('%f' => $file, '%l' => $line)), ENT_QUOTES, sfConfig::get('sf_charset')), |
|---|
| 177 |
htmlspecialchars($shortFile, ENT_QUOTES, sfConfig::get('sf_charset')), |
|---|
| 178 |
null === $text ? $shortFile : $text); |
|---|
| 179 |
} |
|---|
| 180 |
else if (null === $text) |
|---|
| 181 |
{ |
|---|
| 182 |
|
|---|
| 183 |
return $shortFile; |
|---|
| 184 |
} |
|---|
| 185 |
else |
|---|
| 186 |
{ |
|---|
| 187 |
|
|---|
| 188 |
return sprintf('<span title="%s">%s</span>', $shortFile, $text); |
|---|
| 189 |
} |
|---|
| 190 |
} |
|---|
| 191 |
|
|---|
| 192 |
|
|---|
| 193 |
* Format a SQL string with some colors on SQL keywords to make it more readable. |
|---|
| 194 |
* |
|---|
| 195 |
* @param string $sql SQL string to format |
|---|
| 196 |
* |
|---|
| 197 |
* @return string $newSql The new formatted SQL string |
|---|
| 198 |
*/ |
|---|
| 199 |
public function formatSql($sql) |
|---|
| 200 |
{ |
|---|
| 201 |
return preg_replace('/\b(UPDATE|SET|SELECT|FROM|AS|LIMIT|ASC|COUNT|DESC|WHERE|LEFT JOIN|INNER JOIN|RIGHT JOIN|ORDER BY|GROUP BY|IN|LIKE|DISTINCT|DELETE|INSERT|INTO|VALUES)\b/', '<span class="sfWebDebugLogInfo">\\1</span>', $sql); |
|---|
| 202 |
} |
|---|
| 203 |
} |
|---|
| 204 |
|
|---|