Permalink
Browse files

removed double-stringification of values in the profiler

  • Loading branch information...
1 parent 1cda2d4 commit dce66c9d79c7de7dde4ba9ad95382d0761f87109 @fabpot fabpot committed Feb 28, 2014
@@ -8,6 +8,7 @@
<parameter key="web_profiler.controller.profiler.class">Symfony\Bundle\WebProfilerBundle\Controller\ProfilerController</parameter>
<parameter key="web_profiler.controller.router.class">Symfony\Bundle\WebProfilerBundle\Controller\RouterController</parameter>
<parameter key="web_profiler.controller.exception.class">Symfony\Bundle\WebProfilerBundle\Controller\ExceptionController</parameter>
+ <parameter key="twig.extension.webprofiler.class">Symfony\Bundle\WebProfilerBundle\Twig\WebProfilerExtension</parameter>
</parameters>
<services>
@@ -30,5 +31,9 @@
<argument type="service" id="twig" />
<argument>%kernel.debug%</argument>
</service>
+
+ <service id="twig.extension.webprofiler" class="%twig.extension.webprofiler.class%" public="false">
+ <tag name="twig.extension" />
+ </service>
</services>
</container>
@@ -1,16 +1,15 @@
<table {% if class is defined %}class='{{ class }}'{% endif %} >
<thead>
<tr>
- <th scope="col">Key</th>
- <th scope="col">Value</th>
+ <th scope="col" style="width: 25%">Key</th>
+ <th scope="col" style="width: 75%">Value</th>
</tr>
</thead>
<tbody>
{% for key in bag.keys|sort %}
<tr>
<th>{{ key }}</th>
- {# JSON_UNESCAPED_SLASHES = 64, JSON_UNESCAPED_UNICODE = 256 #}
- <td>{{ bag.get(key)|json_encode(64 b-or 256) }}</td>
+ <td><pre>{{ profiler_dump(bag.get(key)) }}</pre></td>
</tr>
{% endfor %}
</tbody>
@@ -170,6 +170,10 @@ pre, code {
margin-left: 250px;
padding: 30px 40px 40px;
}
+#collector-content pre {
+ white-space: pre-wrap;
+ word-break: break-all;
+}
#navigation {
float: left;
width: 250px;
@@ -1,16 +1,15 @@
<table {% if class is defined %}class='{{ class }}'{% endif %} >
<thead>
<tr>
- <th scope="col">Key</th>
- <th scope="col">Value</th>
+ <th scope="col" style="width: 25%">Key</th>
+ <th scope="col" style="width: 75%">Value</th>
</tr>
</thead>
<tbody>
{% for key in data|keys|sort %}
<tr>
<th>{{ key }}</th>
- {# JSON_UNESCAPED_SLASHES = 64, JSON_UNESCAPED_UNICODE = 256 #}
- <td>{{ data[key]|json_encode(64 b-or 256) }}</td>
+ <td><pre>{{ profiler_dump(data[key]) }}</pre></td>
</tr>
{% endfor %}
</tbody>
@@ -0,0 +1,54 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Bundle\WebProfilerBundle\Twig;
+
+use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
+
+/**
+ * Twig extension for the profiler
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+class WebProfilerExtension extends \Twig_Extension
+{
+ /**
+ * @var ValueExporter
+ */
+ private $valueExporter;
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getFunctions()
+ {
+ return array(
+ new \Twig_SimpleFunction('profiler_dump', array($this, 'dumpValue')),
+ );
+ }
+
+ public function dumpValue($value)
+ {
+ if (null === $this->valueExporter) {
+ $this->valueExporter = new ValueExporter();
+ }
+
+ return $this->valueExporter->exportValue($value);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getName()
+ {
+ return 'profiler';
+ }
+}
@@ -17,7 +17,7 @@
],
"require": {
"php": ">=5.3.3",
- "symfony/http-kernel": "~2.2",
+ "symfony/http-kernel": "~2.3",
"symfony/routing": "~2.2",
"symfony/twig-bridge": "~2.2"
},
@@ -25,7 +25,7 @@ class FormDataExtractorTest_SimpleValueExporter extends ValueExporter
/**
* {@inheritdoc}
*/
- public function exportValue($value, $depth = 0)
+ public function exportValue($value, $depth = 1, $deep = false)
{
return is_object($value) ? sprintf('object(%s)', get_class($value)) : var_export($value, true);
}
@@ -51,14 +51,10 @@ public function collect(Request $request, Response $response, \Exception $except
$attributes = array();
foreach ($request->attributes->all() as $key => $value) {
if ('_route' === $key && is_object($value)) {
- $attributes['_route'] = $this->varToString($value->getPath());
- } elseif ('_route_params' === $key) {
- foreach ($value as $key => $v) {
- $attributes['_route_params'][$key] = $this->varToString($v);
- }
- } else {
- $attributes[$key] = $this->varToString($value);
+ $value = $value->getPath();
}
+
+ $attributes[$key] = $value;
}
$content = null;
@@ -20,7 +20,8 @@ class ValueExporter
* Converts a PHP value to a string.
*
* @param mixed $value The PHP value
- * @param integer $depth The depth of the value to export (only for internal usage)
+ * @param integer $depth only for internal usage
+ * @param Boolean $deep only for internal usage
*
* @return string The string representation of the given value
*/

0 comments on commit dce66c9

Please sign in to comment.