| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfDebug |
|---|
| 20 |
{ |
|---|
| 21 |
|
|---|
| 22 |
* Returns symfony information as an array. |
|---|
| 23 |
* |
|---|
| 24 |
* @return array An array of symfony information |
|---|
| 25 |
*/ |
|---|
| 26 |
public static function symfonyInfoAsArray() |
|---|
| 27 |
{ |
|---|
| 28 |
return array( |
|---|
| 29 |
'version' => SYMFONY_VERSION, |
|---|
| 30 |
'path' => sfConfig::get('sf_symfony_lib_dir'), |
|---|
| 31 |
); |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
* Returns PHP information as an array. |
|---|
| 36 |
* |
|---|
| 37 |
* @return array An array of php information |
|---|
| 38 |
*/ |
|---|
| 39 |
public static function phpInfoAsArray() |
|---|
| 40 |
{ |
|---|
| 41 |
$values = array( |
|---|
| 42 |
'php' => phpversion(), |
|---|
| 43 |
'os' => php_uname(), |
|---|
| 44 |
'extensions' => get_loaded_extensions(), |
|---|
| 45 |
); |
|---|
| 46 |
|
|---|
| 47 |
natcasesort($values['extensions']); |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
if ($values['extensions']) |
|---|
| 51 |
{ |
|---|
| 52 |
foreach($values['extensions'] as $key => $extension) |
|---|
| 53 |
{ |
|---|
| 54 |
$values['extensions'][$key] = phpversion($extension) ? sprintf('%s (%s)', $extension, phpversion($extension)) : $extension; |
|---|
| 55 |
} |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
return $values; |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
* Returns PHP globals variables as a sorted array. |
|---|
| 63 |
* |
|---|
| 64 |
* @return array PHP globals |
|---|
| 65 |
*/ |
|---|
| 66 |
public static function globalsAsArray() |
|---|
| 67 |
{ |
|---|
| 68 |
$values = array(); |
|---|
| 69 |
foreach (array('cookie', 'server', 'get', 'post', 'files', 'env', 'session') as $name) |
|---|
| 70 |
{ |
|---|
| 71 |
if (!isset($GLOBALS['_'.strtoupper($name)])) |
|---|
| 72 |
{ |
|---|
| 73 |
continue; |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
$values[$name] = array(); |
|---|
| 77 |
foreach ($GLOBALS['_'.strtoupper($name)] as $key => $value) |
|---|
| 78 |
{ |
|---|
| 79 |
$values[$name][$key] = $value; |
|---|
| 80 |
} |
|---|
| 81 |
ksort($values[$name]); |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
ksort($values); |
|---|
| 85 |
|
|---|
| 86 |
return $values; |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
* Returns sfConfig variables as a sorted array. |
|---|
| 91 |
* |
|---|
| 92 |
* @return array sfConfig variables |
|---|
| 93 |
*/ |
|---|
| 94 |
public static function settingsAsArray() |
|---|
| 95 |
{ |
|---|
| 96 |
$config = sfConfig::getAll(); |
|---|
| 97 |
|
|---|
| 98 |
ksort($config); |
|---|
| 99 |
|
|---|
| 100 |
return $config; |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
* Returns request parameter holders as an array. |
|---|
| 105 |
* |
|---|
| 106 |
* @param sfRequest $request A sfRequest instance |
|---|
| 107 |
* |
|---|
| 108 |
* @return array The request parameter holders |
|---|
| 109 |
*/ |
|---|
| 110 |
public static function requestAsArray(sfRequest $request = null) |
|---|
| 111 |
{ |
|---|
| 112 |
if (!$request) |
|---|
| 113 |
{ |
|---|
| 114 |
return array(); |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
return array( |
|---|
| 118 |
'options' => $request->getOptions(), |
|---|
| 119 |
'parameterHolder' => self::flattenParameterHolder($request->getParameterHolder(), true), |
|---|
| 120 |
'attributeHolder' => self::flattenParameterHolder($request->getAttributeHolder(), true), |
|---|
| 121 |
); |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
* Returns response parameters as an array. |
|---|
| 126 |
* |
|---|
| 127 |
* @param sfResponse $response A sfResponse instance |
|---|
| 128 |
* |
|---|
| 129 |
* @return array The response parameters |
|---|
| 130 |
*/ |
|---|
| 131 |
public static function responseAsArray(sfResponse $response = null) |
|---|
| 132 |
{ |
|---|
| 133 |
if (!$response) |
|---|
| 134 |
{ |
|---|
| 135 |
return array(); |
|---|
| 136 |
} |
|---|
| 137 |
|
|---|
| 138 |
return array( |
|---|
| 139 |
'status' => array('code' => $response->getStatusCode(), 'text' => $response->getStatusText()), |
|---|
| 140 |
'options' => $response->getOptions(), |
|---|
| 141 |
'cookies' => method_exists($response, 'getCookies') ? $response->getCookies() : array(), |
|---|
| 142 |
'httpHeaders' => method_exists($response, 'getHttpHeaders') ? $response->getHttpHeaders() : array(), |
|---|
| 143 |
'javascripts' => method_exists($response, 'getJavascripts') ? $response->getJavascripts('ALL') : array(), |
|---|
| 144 |
'stylesheets' => method_exists($response, 'getStylesheets') ? $response->getStylesheets('ALL') : array(), |
|---|
| 145 |
'metas' => method_exists($response, 'getMetas') ? $response->getMetas() : array(), |
|---|
| 146 |
'httpMetas' => method_exists($response, 'getHttpMetas') ? $response->getHttpMetas() : array(), |
|---|
| 147 |
); |
|---|
| 148 |
} |
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
* Returns user parameters as an array. |
|---|
| 152 |
* |
|---|
| 153 |
* @param sfUser $user A sfUser instance |
|---|
| 154 |
* |
|---|
| 155 |
* @return array The user parameters |
|---|
| 156 |
*/ |
|---|
| 157 |
public static function userAsArray(sfUser $user = null) |
|---|
| 158 |
{ |
|---|
| 159 |
if (!$user) |
|---|
| 160 |
{ |
|---|
| 161 |
return array(); |
|---|
| 162 |
} |
|---|
| 163 |
|
|---|
| 164 |
$data = array( |
|---|
| 165 |
'options' => $user->getOptions(), |
|---|
| 166 |
'attributeHolder' => self::flattenParameterHolder($user->getAttributeHolder(), true), |
|---|
| 167 |
'culture' => $user->getCulture(), |
|---|
| 168 |
); |
|---|
| 169 |
|
|---|
| 170 |
if ($user instanceof sfSecurityUser) |
|---|
| 171 |
{ |
|---|
| 172 |
$data = array_merge($data, array( |
|---|
| 173 |
'authenticated' => $user->isAuthenticated(), |
|---|
| 174 |
'credentials' => $user->getCredentials(), |
|---|
| 175 |
'lastRequest' => $user->getLastRequestTime(), |
|---|
| 176 |
)); |
|---|
| 177 |
} |
|---|
| 178 |
|
|---|
| 179 |
return $data; |
|---|
| 180 |
} |
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
* Returns a parameter holder as an array. |
|---|
| 184 |
* |
|---|
| 185 |
* @param sfParameterHolder $parameterHolder A sfParameterHolder instance |
|---|
| 186 |
* @param boolean $removeObjects when set to true, objects are removed. default is false for BC. |
|---|
| 187 |
* |
|---|
| 188 |
* @return array The parameter holder as an array |
|---|
| 189 |
*/ |
|---|
| 190 |
public static function flattenParameterHolder($parameterHolder, $removeObjects = false) |
|---|
| 191 |
{ |
|---|
| 192 |
$values = array(); |
|---|
| 193 |
if ($parameterHolder instanceof sfNamespacedParameterHolder) |
|---|
| 194 |
{ |
|---|
| 195 |
foreach ($parameterHolder->getNamespaces() as $ns) |
|---|
| 196 |
{ |
|---|
| 197 |
$values[$ns] = array(); |
|---|
| 198 |
foreach ($parameterHolder->getAll($ns) as $key => $value) |
|---|
| 199 |
{ |
|---|
| 200 |
$values[$ns][$key] = $value; |
|---|
| 201 |
} |
|---|
| 202 |
ksort($values[$ns]); |
|---|
| 203 |
} |
|---|
| 204 |
} |
|---|
| 205 |
else |
|---|
| 206 |
{ |
|---|
| 207 |
foreach ($parameterHolder->getAll() as $key => $value) |
|---|
| 208 |
{ |
|---|
| 209 |
$values[$key] = $value; |
|---|
| 210 |
} |
|---|
| 211 |
} |
|---|
| 212 |
|
|---|
| 213 |
if ($removeObjects) |
|---|
| 214 |
{ |
|---|
| 215 |
$values = self::removeObjects($values); |
|---|
| 216 |
} |
|---|
| 217 |
|
|---|
| 218 |
ksort($values); |
|---|
| 219 |
|
|---|
| 220 |
return $values; |
|---|
| 221 |
} |
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
* Removes objects from the array by replacing them with a String containing the class name. |
|---|
| 225 |
* |
|---|
| 226 |
* @param array $values an array |
|---|
| 227 |
* |
|---|
| 228 |
* @return array The array without objects |
|---|
| 229 |
*/ |
|---|
| 230 |
public static function removeObjects($values) |
|---|
| 231 |
{ |
|---|
| 232 |
$nvalues = array(); |
|---|
| 233 |
foreach ($values as $key => $value) |
|---|
| 234 |
{ |
|---|
| 235 |
if (is_array($value)) |
|---|
| 236 |
{ |
|---|
| 237 |
$nvalues[$key] = self::removeObjects($value); |
|---|
| 238 |
} |
|---|
| 239 |
else if (is_object($value)) |
|---|
| 240 |
{ |
|---|
| 241 |
$nvalues[$key] = sprintf('%s Object()', get_class($value)); |
|---|
| 242 |
} |
|---|
| 243 |
else |
|---|
| 244 |
{ |
|---|
| 245 |
$nvalues[$key] = $value; |
|---|
| 246 |
} |
|---|
| 247 |
} |
|---|
| 248 |
|
|---|
| 249 |
return $nvalues; |
|---|
| 250 |
} |
|---|
| 251 |
|
|---|
| 252 |
|
|---|
| 253 |
* Shortens a file path by replacing symfony directory constants. |
|---|
| 254 |
* |
|---|
| 255 |
* @param string $file |
|---|
| 256 |
* |
|---|
| 257 |
* @return string |
|---|
| 258 |
*/ |
|---|
| 259 |
static public function shortenFilePath($file) |
|---|
| 260 |
{ |
|---|
| 261 |
foreach (array('sf_root_dir', 'sf_symfony_lib_dir') as $key) |
|---|
| 262 |
{ |
|---|
| 263 |
if (0 === strpos($file, $value = sfConfig::get($key))) |
|---|
| 264 |
{ |
|---|
| 265 |
$file = str_replace($value, strtoupper($key), $file); |
|---|
| 266 |
break; |
|---|
| 267 |
} |
|---|
| 268 |
} |
|---|
| 269 |
|
|---|
| 270 |
return $file; |
|---|
| 271 |
} |
|---|
| 272 |
} |
|---|
| 273 |
|
|---|