8000 removed double-stringification of values in the profiler · symfony/symfony@dce66c9 · GitHub
[go: up one dir, main page]

Skip to content

Commit dce66c9

Browse files
committed
removed double-stringification of values in the profiler
1 parent 1cda2d4 commit dce66c9

File tree

9 files changed

+76
-18
lines changed

9 files changed

+76
-18
lines changed

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

Lines 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

Lines 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

Lines 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

Lines 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>
Lines 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

Lines 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

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, $depth = 0)
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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,10 @@ public function collect(Request $r F438 equest, 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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ 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 (only for internal usage)
23+
* @param integer $depth only for internal usage
24+
* @param Boolean $deep only for internal usage
2425
*
2526
* @return string The string representation of the given value
2627
*/

0 commit comments

Comments
 (0)
0