Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 65c9aca

Browse filesBrowse files
committed
feature #10352 [DataCollector] Improves the readability of the collected arrays in the profiler (fabpot)
This PR was merged into the 2.5-dev branch. Discussion ---------- [DataCollector] Improves the readability of the collected arrays in the profiler | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT This PR is based on #10155. Original description: It simply improves the readability of the collected arrays in the profiler: __before__: ``` Array(date => Array(year => , month => , day => ), time => Array(hour => )) ``` __after__: ``` [ date => [ year => , month => , day => ], time => [ hour => ] ] ``` Commits ------- dce66c9 removed double-stringification of values in the profiler 1cda2d4 [HttpKernel] tweaked value exporter 3f297ea Improves the readability of the collected arrays in the profiler.
2 parents eede330 + dce66c9 commit 65c9aca
Copy full SHA for 65c9aca

File tree

Expand file treeCollapse file tree

9 files changed

+93
-21
lines changed
Filter options
Expand file treeCollapse file tree

9 files changed

+93
-21
lines changed

‎src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Resources/config/profiler.xml
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<parameter key="web_profiler.controller.profiler.class">Symfony\Bundle\WebProfilerBundle\Controller\ProfilerController</parameter>
99
<parameter key="web_profiler.controller.router.class">Symfony\Bundle\WebProfilerBundle\Controller\RouterController</parameter>
1010
<parameter key="web_profiler.controller.exception.class">Symfony\Bundle\WebProfilerBundle\Controller\ExceptionController</parameter>
11+
<parameter key="twig.extension.webprofiler.class">Symfony\Bundle\WebProfilerBundle\Twig\WebProfilerExtension</parameter>
1112
</parameters>
1213

1314
<services>
@@ -30,5 +31,9 @@
3031
<argument type="service" id="twig" />
3132
<argument>%kernel.debug%</argument>
3233
</service>
34+
35+
<service id="twig.extension.webprofiler" class="%twig.extension.webprofiler.class%" public="false">
36+
<tag name="twig.extension" />
37+
</service>
3338
</services>
3439
</container>

‎src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/bag.html.twig

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/bag.html.twig
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<table {% if class is defined %}class='{{ class }}'{% endif %} >
22
<thead>
33
<tr>
4-
<th scope="col">Key</th>
5-
<th scope="col">Value</th>
4+
<th scope="col" style="width: 25%">Key</th>
5+
<th scope="col" style="width: 75%">Value</th>
66
</tr>
77
</thead>
88
<tbody>
99
{% for key in bag.keys|sort %}
1010
<tr>
1111
<th>{{ key }}</th>
12-
{# JSON_UNESCAPED_SLASHES = 64, JSON_UNESCAPED_UNICODE = 256 #}
13-
<td>{{ bag.get(key)|json_encode(64 b-or 256) }}</td>
12+
<td><pre>{{ profiler_dump(bag.get(key)) }}</pre></td>
1413
</tr>
1514
{% endfor %}
1615
</tbody>

‎src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/profiler.css.twig

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/profiler.css.twig
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ pre, code {
170170
margin-left: 250px;
171171
padding: 30px 40px 40px;
172172
}
173+
#collector-content pre {
174+
white-space: pre-wrap;
175+
word-break: break-all;
176+
}
173177
#navigation {
174178
float: left;
175179
width: 250px;

‎src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/table.html.twig

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/table.html.twig
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
<table {% if class is defined %}class='{{ class }}'{% endif %} >
22
<thead>
33
<tr>
4-
<th scope="col">Key</th>
5-
<th scope="col">Value</th>
4+
<th scope="col" style="width: 25%">Key</th>
5+
<th scope="col" style="width: 75%">Value</th>
66
</tr>
77
</thead>
88
<tbody>
99
{% for key in data|keys|sort %}
1010
<tr>
1111
<th>{{ key }}</th>
12-
{# JSON_UNESCAPED_SLASHES = 64, JSON_UNESCAPED_UNICODE = 256 #}
13-
<td>{{ data[key]|json_encode(64 b-or 256) }}</td>
12+
<td><pre>{{ profiler_dump(data[key]) }}</pre></td>
1413
</tr>
1514
{% endfor %}
1615
</tbody>
+54Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\WebProfilerBundle\Twig;
13+
14+
use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
15+
16+
/**
17+
* Twig extension for the profiler
18+
*
19+
* @author Fabien Potencier <fabien@symfony.com>
20+
*/
21+
class WebProfilerExtension extends \Twig_Extension
22+
{
23+
/**
24+
* @var ValueExporter
25+
*/
26+
private $valueExporter;
27+
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public function getFunctions()
32+
{
33+
return array(
34+
new \Twig_SimpleFunction('profiler_dump', array($this, 'dumpValue')),
35+
);
36+
}
37+
38+
public function dumpValue($value)
39+
{
40+
if (null === $this->valueExporter) {
41+
$this->valueExporter = new ValueExporter();
42+
}
43+
44+
return $this->valueExporter->exportValue($value);
45+
}
46+
47+
/**
48+
* {@inheritdoc}
49+
*/
50+
public function getName()
51+
{
52+
return 'profiler';
53+
}
54+
}

‎src/Symfony/Bundle/WebProfilerBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.3",
20-
"symfony/http-kernel": "~2.2",
20+
"symfony/http-kernel": "~2.3",
2121
"symfony/routing": "~2.2",
2222
"symfony/twig-bridge": "~2.2"
2323
},

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/DataCollector/FormDataExtractorTest.php
+1-1Lines 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 = 1, $deep = false)
2929
{
3030
return is_object($value) ? sprintf('object(%s)', get_class($value)) : var_export($value, true);
3131
}

‎src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php
+3-7Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,10 @@ public function collect(Request $request, Response $response, \Exception $except
5151
$attributes = array();
5252
foreach ($request->attributes->all() as $key => $value) {
5353
if ('_route' === $key && is_object($value)) {
54-
$attributes['_route'] = $this->varToString($value->getPath());
55-
} elseif ('_route_params' === $key) {
56-
foreach ($value as $key => $v) {
57-
$attributes['_route_params'][$key] = $this->varToString($v);
58-
}
59-
} else {
60-
$attributes[$key] = $this->varToString($value);
54+
$value = $value->getPath();
6155
}
56+
57+
$attributes[$key] = $value;
6258
}
6359

6460
$content = null;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/DataCollector/Util/ValueExporter.php
+19-4Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,38 @@ class ValueExporter
1919
/**
2020
* Converts a PHP value to a string.
2121
*
22-
* @param mixed $value The PHP value
22+
* @param mixed $value The PHP value
23+
* @param integer $depth only for internal usage
24+
* @param Boolean $deep only for internal usage
2325
*
2426
* @return string The string representation of the given value
2527
*/
26-
public function exportValue($value)
28+
public function exportValue($value, $depth = 1, $deep = false)
2729
{
2830
if (is_object($value)) {
2931
return sprintf('Object(%s)', get_class($value));
3032
}
3133

3234
if (is_array($value)) {
35+
if (empty($value)) {
36+
return '[]';
37+
}
38+
39+
$indent = str_repeat(' ', $depth);
40+
3341
$a = array();
3442
foreach ($value as $k => $v) {
35-
$a[] = sprintf('%s => %s', $k, $this->exportValue($v));
43+
if (is_array($v)) {
44+
$deep = true;
45+
}
46+
$a[] = sprintf('%s => %s', $k, $this->exportValue($v, $depth + 1, $deep));
47+
}
48+
49+
if ($deep) {
50+
return sprintf("[\n%s%s\n%s]", $indent, implode(sprintf(", \n%s", $indent), $a), str_repeat(' ', $depth - 1));
3651
}
3752

38-
return sprintf("Array(%s)", implode(', ', $a));
53+
return sprintf("[%s]", implode(', ', $a));
3954
}
4055

4156
if (is_resource($value)) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.