@@ -89,7 +89,8 @@ discard block |
||
89 | 89 | { |
90 | 90 | $d = $this->makeDumper(); |
91 | 91 | |
92 | - $result = $d->dump(new class() { |
|
92 | + $result = $d->dump(new class() |
|
93 | + { |
|
93 | 94 | private $name = 'Test'; |
94 | 95 | }, Dumper::RETURN); |
95 | 96 | |
@@ -151,7 +152,8 @@ discard block |
||
151 | 152 | public function testDebugInfo(): void |
152 | 153 | { |
153 | 154 | $d = $this->makeDumper(); |
154 | - $result = $d->dump(new class() { |
|
155 | + $result = $d->dump(new class() |
|
156 | + { |
|
155 | 157 | protected $inner = '_kk_'; |
156 | 158 | |
157 | 159 | public function __debugInfo() |
@@ -171,7 +173,8 @@ discard block |
||
171 | 173 | public function testinternal(): void |
172 | 174 | { |
173 | 175 | $d = $this->makeDumper(); |
174 | - $result = $d->dump(new class() { |
|
176 | + $result = $d->dump(new class() |
|
177 | + { |
|
175 | 178 | protected $visible = '_kk_'; |
176 | 179 | |
177 | 180 | /** @internal */ |
@@ -198,7 +201,8 @@ discard block |
||
198 | 201 | $d = $this->makeDumper(); |
199 | 202 | $d->setRenderer(Dumper::RETURN, new HtmlRenderer()); |
200 | 203 | |
201 | - $result = $d->dump(new class() { |
|
204 | + $result = $d->dump(new class() |
|
205 | + { |
|
202 | 206 | protected static $static = 'yes'; |
203 | 207 | |
204 | 208 | private $value = 123; |
@@ -222,7 +226,8 @@ discard block |
||
222 | 226 | $d->setRenderer(Dumper::RETURN, new HtmlRenderer(HtmlRenderer::INVERTED)); |
223 | 227 | $d->setMaxLevel(5); |
224 | 228 | |
225 | - $result = $d->dump(new class() { |
|
229 | + $result = $d->dump(new class() |
|
230 | + { |
|
226 | 231 | private $value = 123; |
227 | 232 | |
228 | 233 | protected $visible = '_kk_'; |
@@ -246,7 +251,8 @@ discard block |
||
246 | 251 | $d->setRenderer(Dumper::RETURN, new ConsoleRenderer()); |
247 | 252 | $d->setMaxLevel(5); |
248 | 253 | |
249 | - $result = $d->dump(new class() { |
|
254 | + $result = $d->dump(new class() |
|
255 | + { |
|
250 | 256 | private $value = 123; |
251 | 257 | |
252 | 258 | protected $visible = '_kk_'; |
@@ -24,12 +24,14 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public static function isCLI(): bool |
26 | 26 | { |
27 | - if (!empty(getenv('RR'))) { |
|
27 | + if (!empty(getenv('RR'))) |
|
28 | + { |
|
28 | 29 | // Do not treat RoadRunner as CLI. |
29 | 30 | return false; |
30 | 31 | } |
31 | 32 | |
32 | - if (php_sapi_name() === 'cli') { |
|
33 | + if (php_sapi_name() === 'cli') |
|
34 | + { |
|
33 | 35 | return true; |
34 | 36 | } |
35 | 37 | |
@@ -46,12 +48,15 @@ discard block |
||
46 | 48 | */ |
47 | 49 | public static function isColorsSupported($stream = STDOUT): bool |
48 | 50 | { |
49 | - if ('Hyper' === getenv('TERM_PROGRAM')) { |
|
51 | + if ('Hyper' === getenv('TERM_PROGRAM')) |
|
52 | + { |
|
50 | 53 | return true; |
51 | 54 | } |
52 | 55 | |
53 | - try { |
|
54 | - if (\DIRECTORY_SEPARATOR === '\\') { |
|
56 | + try |
|
57 | + { |
|
58 | + if (\DIRECTORY_SEPARATOR === '\\') |
|
59 | + { |
|
55 | 60 | return ( |
56 | 61 | function_exists('sapi_windows_vt100_support') |
57 | 62 | && @sapi_windows_vt100_support($stream) |
@@ -60,11 +65,13 @@ discard block |
||
60 | 65 | || getenv('TERM') == 'xterm'; |
61 | 66 | } |
62 | 67 | |
63 | - if (\function_exists('stream_isatty')) { |
|
68 | + if (\function_exists('stream_isatty')) |
|
69 | + { |
|
64 | 70 | return @stream_isatty($stream); |
65 | 71 | } |
66 | 72 | |
67 | - if (\function_exists('posix_isatty')) { |
|
73 | + if (\function_exists('posix_isatty')) |
|
74 | + { |
|
68 | 75 | return @posix_isatty($stream); |
69 | 76 | } |
70 | 77 | |
@@ -72,7 +79,9 @@ discard block |
||
72 | 79 | |
73 | 80 | // Check if formatted mode is S_IFCHR |
74 | 81 | return $stat ? 0020000 === ($stat['mode'] & 0170000) : false; |
75 | - } catch (\Throwable $e) { |
|
82 | + } |
|
83 | + catch (\Throwable $e) |
|
84 | + { |
|
76 | 85 | return false; |
77 | 86 | } |
78 | 87 | } |
@@ -11,7 +11,8 @@ discard block |
||
11 | 11 | |
12 | 12 | use Spiral\Debug\Dumper; |
13 | 13 | |
14 | -if (! function_exists('dump')) { |
|
14 | +if (! function_exists('dump')) |
|
15 | +{ |
|
15 | 16 | /** |
16 | 17 | * Dump value. |
17 | 18 | * |
@@ -22,12 +23,14 @@ discard block |
||
22 | 23 | */ |
23 | 24 | function dump($value, int $output = Dumper::OUTPUT): ?string |
24 | 25 | { |
25 | - if (! class_exists(\Spiral\Core\ContainerScope::class)) { |
|
26 | + if (! class_exists(\Spiral\Core\ContainerScope::class)) |
|
27 | + { |
|
26 | 28 | return (new Dumper())->dump($value, $output); |
27 | 29 | } |
28 | 30 | |
29 | 31 | $container = \Spiral\Core\ContainerScope::getContainer(); |
30 | - if (is_null($container) || ! $container->has(Dumper::class)) { |
|
32 | + if (is_null($container) || ! $container->has(Dumper::class)) |
|
33 | + { |
|
31 | 34 | $dumper = new Dumper(); |
32 | 35 | |
33 | 36 | return $dumper->dump($value, $output); |
@@ -58,7 +58,8 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function __construct(LoggerInterface $logger = null) |
60 | 60 | { |
61 | - if (!empty($logger)) { |
|
61 | + if (!empty($logger)) |
|
62 | + { |
|
62 | 63 | $this->setLogger($logger); |
63 | 64 | } |
64 | 65 | } |
@@ -86,7 +87,8 @@ discard block |
||
86 | 87 | $r = $this->getRenderer($target); |
87 | 88 | $dump = $r->wrapContent($this->renderValue($r, $value)); |
88 | 89 | |
89 | - switch ($target) { |
|
90 | + switch ($target) |
|
91 | + { |
|
90 | 92 | case self::OUTPUT: |
91 | 93 | echo $dump; |
92 | 94 | break; |
@@ -95,7 +97,8 @@ discard block |
||
95 | 97 | return $dump; |
96 | 98 | |
97 | 99 | case self::LOGGER: |
98 | - if ($this->logger == null) { |
|
100 | + if ($this->logger == null) |
|
101 | + { |
|
99 | 102 | throw new DumperException('Unable to dump value to log, no associated LoggerInterface'); |
100 | 103 | } |
101 | 104 | $this->logger->debug($dump); |
@@ -119,7 +122,8 @@ discard block |
||
119 | 122 | */ |
120 | 123 | public function setRenderer(int $target, RendererInterface $renderer): Dumper |
121 | 124 | { |
122 | - if (!isset($this->targets[$target])) { |
|
125 | + if (!isset($this->targets[$target])) |
|
126 | + { |
|
123 | 127 | throw new DumperException(sprintf('Undefined dump target %d', $target)); |
124 | 128 | } |
125 | 129 | |
@@ -138,19 +142,25 @@ discard block |
||
138 | 142 | */ |
139 | 143 | private function getRenderer(int $target): RendererInterface |
140 | 144 | { |
141 | - if ($target == self::OUTPUT && System::isCLI()) { |
|
142 | - if (System::isColorsSupported(STDOUT)) { |
|
145 | + if ($target == self::OUTPUT && System::isCLI()) |
|
146 | + { |
|
147 | + if (System::isColorsSupported(STDOUT)) |
|
148 | + { |
|
143 | 149 | $target = self::OUTPUT_CLI_COLORS; |
144 | - } else { |
|
150 | + } |
|
151 | + else |
|
152 | + { |
|
145 | 153 | $target = self::OUTPUT_CLI; |
146 | 154 | } |
147 | 155 | } |
148 | 156 | |
149 | - if (!isset($this->targets[$target])) { |
|
157 | + if (!isset($this->targets[$target])) |
|
158 | + { |
|
150 | 159 | throw new DumperException(sprintf('Undefined dump target %d', $target)); |
151 | 160 | } |
152 | 161 | |
153 | - if (is_string($this->targets[$target])) { |
|
162 | + if (is_string($this->targets[$target])) |
|
163 | + { |
|
154 | 164 | $this->targets[$target] = new $this->targets[$target](); |
155 | 165 | } |
156 | 166 | |
@@ -175,28 +185,35 @@ discard block |
||
175 | 185 | int $level = 0, |
176 | 186 | bool $hideHeader = false |
177 | 187 | ): string { |
178 | - if (!$hideHeader && !empty($name)) { |
|
188 | + if (!$hideHeader && !empty($name)) |
|
189 | + { |
|
179 | 190 | $header = $r->indent($level) . $r->apply($name, 'name') . $r->apply(' = ', 'syntax', '='); |
180 | - } else { |
|
191 | + } |
|
192 | + else |
|
193 | + { |
|
181 | 194 | $header = $r->indent($level); |
182 | 195 | } |
183 | 196 | |
184 | - if ($level > $this->maxLevel) { |
|
197 | + if ($level > $this->maxLevel) |
|
198 | + { |
|
185 | 199 | //Renderer is not reference based, we can't dump too deep values |
186 | 200 | return $r->indent($level) . $r->apply('-too deep-', 'maxLevel') . "\n"; |
187 | 201 | } |
188 | 202 | |
189 | 203 | $type = strtolower(gettype($value)); |
190 | 204 | |
191 | - if ($type == 'array') { |
|
205 | + if ($type == 'array') |
|
206 | + { |
|
192 | 207 | return $header . $this->renderArray($r, $value, $level, $hideHeader); |
193 | 208 | } |
194 | 209 | |
195 | - if ($type == 'object') { |
|
210 | + if ($type == 'object') |
|
211 | + { |
|
196 | 212 | return $header . $this->renderObject($r, $value, $level, $hideHeader); |
197 | 213 | } |
198 | 214 | |
199 | - if ($type == 'resource') { |
|
215 | + if ($type == 'resource') |
|
216 | + { |
|
200 | 217 | //No need to dump resource value |
201 | 218 | $element = get_resource_type($value) . ' resource '; |
202 | 219 | |
@@ -210,7 +227,8 @@ discard block |
||
210 | 227 | $header .= $r->apply("{$type}({$length})", 'type', $type); |
211 | 228 | |
212 | 229 | $element = null; |
213 | - switch ($type) { |
|
230 | + switch ($type) |
|
231 | + { |
|
214 | 232 | case 'string': |
215 | 233 | $element = $r->escapeStrings() ? htmlspecialchars($value) : $value; |
216 | 234 | break; |
@@ -220,7 +238,8 @@ discard block |
||
220 | 238 | break; |
221 | 239 | |
222 | 240 | default: |
223 | - if ($value !== null) { |
|
241 | + if ($value !== null) |
|
242 | + { |
|
224 | 243 | //Not showing null value, type is enough |
225 | 244 | $element = var_export($value, true); |
226 | 245 | } |
@@ -240,19 +259,25 @@ discard block |
||
240 | 259 | */ |
241 | 260 | private function renderArray(RendererInterface $r, array $array, int $level, bool $hideHeader = false): string |
242 | 261 | { |
243 | - if (!$hideHeader) { |
|
262 | + if (!$hideHeader) |
|
263 | + { |
|
244 | 264 | $count = count($array); |
245 | 265 | |
246 | 266 | //Array size and scope |
247 | 267 | $output = $r->apply("array({$count})", 'type', 'array') . "\n"; |
248 | 268 | $output .= $r->indent($level) . $r->apply('[', 'syntax', '[') . "\n"; |
249 | - } else { |
|
269 | + } |
|
270 | + else |
|
271 | + { |
|
250 | 272 | $output = ''; |
251 | 273 | } |
252 | 274 | |
253 | - foreach ($array as $key => $value) { |
|
254 | - if (!is_numeric($key)) { |
|
255 | - if (is_string($key) && $r->escapeStrings()) { |
|
275 | + foreach ($array as $key => $value) |
|
276 | + { |
|
277 | + if (!is_numeric($key)) |
|
278 | + { |
|
279 | + if (is_string($key) && $r->escapeStrings()) |
|
280 | + { |
|
256 | 281 | $key = htmlspecialchars($key); |
257 | 282 | } |
258 | 283 | |
@@ -262,7 +287,8 @@ discard block |
||
262 | 287 | $output .= $this->renderValue($r, $value, "[{$key}]", $level + 1); |
263 | 288 | } |
264 | 289 | |
265 | - if (!$hideHeader) { |
|
290 | + if (!$hideHeader) |
|
291 | + { |
|
266 | 292 | //Closing array scope |
267 | 293 | $output .= $r->indent($level) . $r->apply(']', 'syntax', ']') . "\n"; |
268 | 294 | } |
@@ -286,29 +312,38 @@ discard block |
||
286 | 312 | bool $hideHeader = false, |
287 | 313 | string $class = '' |
288 | 314 | ): string { |
289 | - if (!$hideHeader) { |
|
315 | + if (!$hideHeader) |
|
316 | + { |
|
290 | 317 | $type = ($class ?: get_class($value)) . ' object '; |
291 | 318 | |
292 | 319 | $header = $r->apply($type, 'type', 'object') . "\n"; |
293 | 320 | $header .= $r->indent($level) . $r->apply('(', 'syntax', '(') . "\n"; |
294 | - } else { |
|
321 | + } |
|
322 | + else |
|
323 | + { |
|
295 | 324 | $header = ''; |
296 | 325 | } |
297 | 326 | |
298 | 327 | //Let's use method specifically created for dumping |
299 | - if (method_exists($value, '__debugInfo') || $value instanceof \Closure) { |
|
300 | - if ($value instanceof \Closure) { |
|
328 | + if (method_exists($value, '__debugInfo') || $value instanceof \Closure) |
|
329 | + { |
|
330 | + if ($value instanceof \Closure) |
|
331 | + { |
|
301 | 332 | $debugInfo = $this->describeClosure($value); |
302 | - } else { |
|
333 | + } |
|
334 | + else |
|
335 | + { |
|
303 | 336 | $debugInfo = $value->__debugInfo(); |
304 | 337 | } |
305 | 338 | |
306 | - if (is_array($debugInfo)) { |
|
339 | + if (is_array($debugInfo)) |
|
340 | + { |
|
307 | 341 | //Pretty view |
308 | 342 | $debugInfo = (object)$debugInfo; |
309 | 343 | } |
310 | 344 | |
311 | - if (is_object($debugInfo)) { |
|
345 | + if (is_object($debugInfo)) |
|
346 | + { |
|
312 | 347 | //We are not including syntax elements here |
313 | 348 | return $this->renderObject($r, $debugInfo, $level, false, get_class($value)); |
314 | 349 | } |
@@ -321,7 +356,8 @@ discard block |
||
321 | 356 | $refection = new \ReflectionObject($value); |
322 | 357 | |
323 | 358 | $output = ''; |
324 | - foreach ($refection->getProperties() as $property) { |
|
359 | + foreach ($refection->getProperties() as $property) |
|
360 | + { |
|
325 | 361 | $output .= $this->renderProperty($r, $value, $property, $level); |
326 | 362 | } |
327 | 363 | |
@@ -339,7 +375,8 @@ discard block |
||
339 | 375 | */ |
340 | 376 | private function renderProperty(RendererInterface $r, $value, \ReflectionProperty $p, int $level): string |
341 | 377 | { |
342 | - if ($p->isStatic()) { |
|
378 | + if ($p->isStatic()) |
|
379 | + { |
|
343 | 380 | return ''; |
344 | 381 | } |
345 | 382 | |
@@ -359,9 +396,12 @@ discard block |
||
359 | 396 | //To read private and protected properties |
360 | 397 | $p->setAccessible(true); |
361 | 398 | |
362 | - if ($value instanceof \stdClass) { |
|
399 | + if ($value instanceof \stdClass) |
|
400 | + { |
|
363 | 401 | $name = $r->apply($p->getName(), 'dynamic'); |
364 | - } else { |
|
402 | + } |
|
403 | + else |
|
404 | + { |
|
365 | 405 | //Property name includes access level |
366 | 406 | $name = $p->getName() . $r->apply(':' . $access, 'access', $access); |
367 | 407 | } |
@@ -377,9 +417,12 @@ discard block |
||
377 | 417 | */ |
378 | 418 | private function describeClosure(\Closure $closure): array |
379 | 419 | { |
380 | - try { |
|
420 | + try |
|
421 | + { |
|
381 | 422 | $r = new \ReflectionFunction($closure); |
382 | - } catch (\ReflectionException $e) { |
|
423 | + } |
|
424 | + catch (\ReflectionException $e) |
|
425 | + { |
|
383 | 426 | return ['closure' => 'unable to resolve']; |
384 | 427 | } |
385 | 428 | |
@@ -399,9 +442,12 @@ discard block |
||
399 | 442 | */ |
400 | 443 | private function getAccess(\ReflectionProperty $p): string |
401 | 444 | { |
402 | - if ($p->isPrivate()) { |
|
445 | + if ($p->isPrivate()) |
|
446 | + { |
|
403 | 447 | return 'private'; |
404 | - } elseif ($p->isProtected()) { |
|
448 | + } |
|
449 | + elseif ($p->isProtected()) |
|
450 | + { |
|
405 | 451 | return 'protected'; |
406 | 452 | } |
407 | 453 |
@@ -62,7 +62,8 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function apply($element, string $type, string $context = ''): string |
64 | 64 | { |
65 | - if (!empty($style = $this->getStyle($type, $context))) { |
|
65 | + if (!empty($style = $this->getStyle($type, $context))) |
|
66 | + { |
|
66 | 67 | return sprintf($this->element, $style, $element); |
67 | 68 | } |
68 | 69 | |
@@ -87,15 +88,18 @@ discard block |
||
87 | 88 | */ |
88 | 89 | private function getStyle(string $type, string $context): string |
89 | 90 | { |
90 | - if (isset($this->styles[$type][$context])) { |
|
91 | + if (isset($this->styles[$type][$context])) |
|
92 | + { |
|
91 | 93 | return $this->styles[$type][$context]; |
92 | 94 | } |
93 | 95 | |
94 | - if (isset($this->styles[$type]['common'])) { |
|
96 | + if (isset($this->styles[$type]['common'])) |
|
97 | + { |
|
95 | 98 | return $this->styles[$type]['common']; |
96 | 99 | } |
97 | 100 | |
98 | - if (isset($this->styles[$type]) && is_string($this->styles[$type])) { |
|
101 | + if (isset($this->styles[$type]) && is_string($this->styles[$type])) |
|
102 | + { |
|
99 | 103 | return $this->styles[$type]; |
100 | 104 | } |
101 | 105 |
@@ -42,7 +42,8 @@ |
||
42 | 42 | */ |
43 | 43 | public function indent(int $level): string |
44 | 44 | { |
45 | - if ($level == 0) { |
|
45 | + if ($level == 0) |
|
46 | + { |
|
46 | 47 | return ''; |
47 | 48 | } |
48 | 49 |
@@ -116,8 +116,10 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function apply($element, string $type, string $context = ''): string |
118 | 118 | { |
119 | - if (!empty($style = $this->getStyle($type, $context))) { |
|
120 | - if (!empty($style = $this->getStyle($type, $context))) { |
|
119 | + if (!empty($style = $this->getStyle($type, $context))) |
|
120 | + { |
|
121 | + if (!empty($style = $this->getStyle($type, $context))) |
|
122 | + { |
|
121 | 123 | return sprintf($this->style['element'], $style, $element); |
122 | 124 | } |
123 | 125 | } |
@@ -138,7 +140,8 @@ discard block |
||
138 | 140 | */ |
139 | 141 | public function indent(int $level): string |
140 | 142 | { |
141 | - if ($level == 0) { |
|
143 | + if ($level == 0) |
|
144 | + { |
|
142 | 145 | return ''; |
143 | 146 | } |
144 | 147 | |
@@ -163,15 +166,18 @@ discard block |
||
163 | 166 | */ |
164 | 167 | private function getStyle(string $type, string $context): string |
165 | 168 | { |
166 | - if (isset($this->style[$type][$context])) { |
|
169 | + if (isset($this->style[$type][$context])) |
|
170 | + { |
|
167 | 171 | return $this->style[$type][$context]; |
168 | 172 | } |
169 | 173 | |
170 | - if (isset($this->style[$type]['common'])) { |
|
174 | + if (isset($this->style[$type]['common'])) |
|
175 | + { |
|
171 | 176 | return $this->style[$type]['common']; |
172 | 177 | } |
173 | 178 | |
174 | - if (isset($this->style[$type]) && is_string($this->style[$type])) { |
|
179 | + if (isset($this->style[$type]) && is_string($this->style[$type])) |
|
180 | + { |
|
175 | 181 | return $this->style[$type]; |
176 | 182 | } |
177 | 183 |