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