8000 Improves the readability of the collected arrays in the profiler. · symfony/symfony@3f297ea · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f297ea

Browse files
Quentin Schulerfabpot
Quentin Schuler
authored andcommitted
Improves the readability of the collected arrays in the profiler.
1 parent 7baeaa2 commit 3f297ea

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/Symfony/Component/Form/Tests/Extension/DataCollector/FormDataExtractorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class FormDataExtractorTest_SimpleValueExporter extends ValueExporter
2525
/**
2626
* {@inheritdoc}
2727
*/
28-
public function exportValue($value)
28+
public function exportValue($value, $depth = 0)
2929
{
3030
return is_object($value) ? sprintf('object(%s)', get_class($value)) : var_export($value, true);
3131
}

src/Symfony/Component/HttpKernel/DataCollector/Util/ValueExporter.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,29 @@ class ValueExporter
2020
* Converts a PHP value to a string.
2121
*
2222
* @param mixed $value The PHP value
23+
* @param integer $depth The depth of the value to export
2324
*
2425
* @return string The string representation of the given value
2526
*/
26-
public function exportValue($value)
27+
public function exportValue($value, $depth = 0)
2728
{
2829
if (is_object($value)) {
2930
return sprintf('Object(%s)', get_class($value));
3031
}
3132

3233
if (is_array($value)) {
34+
if (empty($value)) {
35+
return '[]';
36+
}
37+
38+
$indent = str_repeat(' ', $depth);
39+
3340
$a = array();
3441
foreach ($value as $k => $v) {
35-
$a[] = sprintf('%s => %s', $k, $this->exportValue($v));
42+
$a[] = sprintf('%s %s => %s', $indent, $k, $this->exportValue($v, $depth + 1));
3643
}
3744

38-
return sprintf("Array(%s)", implode(', ', $a));
45+
return sprintf("[\n%s%s\n%s]", $indent, implode(sprintf(", \n%s", $indent), $a), $indent);
3946
}
4047

4148
if (is_resource($value)) {

0 commit comments

Comments
 (0)
0