8000 feature #19614 [HttpKernel] Use VarDumper in the profiler (wouterj, n… · symfony/symfony@bfe0af5 · GitHub
[go: up one dir, main page]

Skip to content

Commit bfe0af5

Browse files
committed
feature #19614 [HttpKernel] Use VarDumper in the profiler (wouterj, nicolas-grekas)
This PR was merged into the 3.2-dev branch. Discussion ---------- [HttpKernel] Use VarDumper in the profiler | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | part of #18149 | License | MIT | Doc PR | - /cc @javiereguiluz @nicolas-grekas As you're the main maintainers of the changed features. Summary --- * The `varToString()` method is deprecated in favor of `cloneVar()` (using the VarCloner) and `dump()` (using the VarDumper). This allows to show more detailed and better formatted data in the profiler. * The `Data` class of VarDumper is made serializable, to reduce the size of the stored profiler data. Screenshots --- ![sf-profiler-dumper](https://cloud.githubusercontent.com/assets/749025/17651142/9bcddc14-6260-11e6-80f6-81b84c82c0a3.png) Further Improvements --- * Change the dump colors (I've now implemented a very basic light theme, but my colorskills are close to zero, so a proper designer should look at it) Commits ------- eddecbd [HttpKernel] Use VarDumper in the Logs&Events panels of the profiler 41a7649 [HttpKernel] Use VarDumper in the profiler
2 parents c21bed7 + eddecbd commit bfe0af5

File tree

35 files changed

+605
-509
lines changed

35 files changed

+605
-509
lines changed

UPGRADE-3.2.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ Form
3838
FrameworkBundle
3939
---------------
4040

41-
* The service `serializer.mapping.cache.doctrine.apc` is deprecated. APCu should now
42-
be automatically used when available.
41+
* The service `serializer.mapping.cache.doctrine.apc` is deprecated. APCu should now
42+
be automatically used when available.
43+
44+
HttpKernel
45+
----------
46+
47+
* `DataCollector::varToString()` is deprecated and will be removed in Symfony
48+
4.0. Use the `cloneVar()` method instead.
4349

4450
HttpFoundation
4551
---------------

UPGRADE-4.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ HttpKernel
155155
have your own `ControllerResolverInterface` implementation, you should
156156
inject an `ArgumentResolverInterface` instance.
157157

158+
* The `DataCollector::varToString()` method has been removed in favor of `cloneVar()`.
159+
158160
Serializer
159161
----------
160162

src/Symfony/Bundle/DebugBundle/Resources/views/Profiler/dump.html.twig

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
{% for dump in collector.getDumps('html') %}
4747
<div class="sf-dump sf-reset">
48-
<h3>In
48+
<span class="metadata">In
4949
{% if dump.line %}
5050
{% set link = dump.file|file_link(dump.line) %}
5151
{% if link %}
@@ -56,10 +56,8 @@
5656
{% else %}
5757
{{ dump.name }}
5858
{% endif %}
59-
<small>line {{ dump.line }}</small>
60-
61-
<a class="text-small sf-toggle" data-toggle-selector="#sf-trace-{{ loop.index0 }}" data-toggle-alt-content="Hide code">Show code</a>
62-
</h3>
59+
line <a class="text-small sf-toggle" data-toggle-selector="#sf-trace-{{ loop.index0 }}">{{ dump.line }}</a>:
60+
</span>
6361

6462
<div class="sf-dump-compact hidden" id="sf-trace-{{ loop.index0 }}">
6563
<div class="trace">

src/Symfony/Bundle/FrameworkBundle/Resources/config/form_debug.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<service id="data_collector.form" class="Symfony\Component\Form\Extension\DataCollector\FormDataCollector">
2525
<tag name="data_collector" template="@WebProfiler/Collector/form.html.twig" id="form" priority="310" />
2626
<argument type="service" id="data_collector.form.extractor" />
27+
<argument>false</argument>
2728
</service>
2829
</services>
2930
</container>

src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator;
2121
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
2222
use Symfony\Component\Security\Core\Authorization\DebugAccessDecisionManager;
23+
use Symfony\Component\VarDumper\Cloner\Data;
2324

2425
/**
2526
* SecurityDataCollector.
@@ -58,6 +59,7 @@ public function collect(Request $request, Response $response, \Exception $except
5859
$this->data = array(
5960
'enabled' => false,
6061
'authenticated' => false,
62+
'token' => null,
6163
'token_class' => null,
6264
'logout_url' => null,
6365
'user' => '',
@@ -69,6 +71,7 @@ public function collect(Request $request, Response $response, \Exception $except
6971
$this->data = array(
7072
'enabled' => true,
7173
'authenticated' => false,
74+
'token' => null,
7275
'token_class' => null,
7376
'logout_url' => null,
7477
'user' => '',
@@ -101,18 +104,24 @@ public function collect(Request $request, Response $response, \Exception $except
101104
$this->data = array(
102105
'enabled' => true,
103106
'authenticated' => $token->isAuthenticated(),
107+
'token' => $this->cloneVar($token),
104108
'token_class' => get_class($token),
105109
'logout_url' => $logoutUrl,
106110
'user' => $token->getUsername(),
107-
'roles' => array_map(function (RoleInterface $role) { return $role->getRole();}, $assignedRoles),
108-
'inherited_roles' => array_map(function (RoleInterface $role) { return $role->getRole(); }, $inheritedRoles),
111+
'roles' => $this->cloneVar(array_map(function (RoleInterface $role) { return $role->getRole();}, $assignedRoles)),
112+
'inherited_roles' => $this->cloneVar(array_map(function (RoleInterface $role) { return $role->getRole(); }, $inheritedRoles)),
109113
'supports_role_hierarchy' => null !== $this->roleHierarchy,
110114
);
111115
}
112116

113117
// collect voters and access decision manager information
114118
if ($this->accessDecisionManager instanceof DebugAccessDecisionManager) {
115-
$this->data['access_decision_log'] = $this->accessDecisionManager->getDecisionLog();
119+
$this->data['access_decision_log'] = array_map(function ($decision) {
120+
$decision['object'] = $this->cloneVar($decision['object']);
121+
122+
return $decision;
123+
}, $this->accessDecisionManager->getDecisionLog());
124+
116125
$this->data['voter_strategy'] = $this->accessDecisionManager->getStrategy();
117126

118127
foreach ($this->accessDecisionManager->getVoters() as $voter) {
@@ -196,6 +205,16 @@ public function getTokenClass()
196205
return $this->data['token_class'];
197206
}
198207

208+
/**
209+
* Get the full security token class as Data object.
210+
*
211+
* @return Data
212+
*/
213+
public function getToken()
214+
{
215+
return $this->data['token'];
216+
}
217+
199218
/**
200219
* Get the provider key (i.e. the name of the active firewall).
201220
*

src/Symfony/Bundle/SecurityBundle/Resources/views/Collector/security.html.twig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{% block page_title 'Security' %}
44

55
{% block toolbar %}
6-
{% if collector.tokenClass %}
6+
{% if collector.token %}
77
{% set is_authenticated = collector.enabled and collector.authenticated %}
88
{% set color_code = is_authenticated ? '' : 'yellow' %}
99
{% else %}
@@ -16,7 +16,7 @@
1616
{% endset %}
1717

1818
{% set text %}
19-
{% if collector.tokenClass %}
19+
{% if collector.token %}
2020
<div class="sf-toolbar-info-piece">
2121
<b>Logged in as</b>
2222
<span>{{ collector.user }}</span>
@@ -27,7 +27,7 @@
2727
<span class="sf-toolbar-status sf-toolbar-status-{{ is_authenticated ? 'green' : 'red' }}">{{ is_authenticated ? 'Yes' : 'No' }}</span>
2828
</div>
2929

30-
{% if collector.tokenClass != null %}
30+
{% if collector.token != null %}
3131
<div class="sf-toolbar-info-piece">
3232
<b>Token class</b>
3333
<span>{{ collector.tokenClass|abbr_class }}</span>
@@ -54,7 +54,7 @@
5454
{% endblock %}
5555

5656
{% block menu %}
57-
<span class="label {{ not collector.enabled or not collector.tokenClass ? 'disabled' }}">
57+
<span class="label {{ not collector.enabled or not collector.token ? 'disabled' }}">
5858
<span class="icon">{{ include('@Security/Collector/icon.svg') }}</span>
5959
<strong>Security</strong>
6060
</span>
@@ -63,7 +63,7 @@
6363
{% block panel %}
6464
<h2>Security Token</h2>
6565

66-
{% if collector.tokenClass %}
66+
{% if collector.token %}
6767
<div class="metrics">
6868
<div class="metric">
6969
<span class="value">{{ collector.user == 'anon.' ? 'Anonymous' : collector.user }}</span>
@@ -87,7 +87,7 @@
8787
<tr>
8888
<th>Roles</th>
8989
<td>
90-
{{ collector.roles is empty ? 'none' : collector.roles|yaml_encode }}
90+
{{ collector.roles is empty ? 'none' : profiler_dump(collector.roles, maxDepth=1) }}
9191

9292
{% if not collector.authenticated and collector.roles is empty %}
9393
<p class="help">User is not authenticated probably because they have no roles.</p>
@@ -98,14 +98,14 @@
9898
{% if collector.supportsRoleHierarchy %}
9999
<tr>
100100
<th>Inherited Roles</th>
101-
<td>{{ collector.inheritedRoles is empty ? 'none' : collector.inheritedRoles|yaml_encode }}</td>
101+
<td>{{ collector.inheritedRoles is empty ? 'none' : profiler_dump(collector.inheritedRoles, maxDepth=1) }}</td>
102102
</tr>
103103
{% endif %}
104104

105-
{% if collector.tokenClass %}
105+
{% if collector.token %}
106106
<tr>
107-
<th>Token class</th>
108-
<td>{{ collector.tokenClass }}</td>
107+
<th>Token</th>
108+
<td>{{ profiler_dump(collector.token) }}</td>
109109
</tr>
110110
{% endif %}
111111
</tbody>

src/Symfony/Bundle/SecurityBundle/Tests/DataCollector/SecurityDataCollectorTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ public function testCollectAuthenticationTokenAndRoles(array $roles, array $norm
6262
$this->assertTrue($collector->isAuthenticated());
6363
$this->assertSame('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $collector->getTokenClass());
6464
$this->assertTrue($collector->supportsRoleHierarchy());
65-
$this->assertSame($normalizedRoles, $collector->getRoles());
66-
$this->assertSame($inheritedRoles, $collector->getInheritedRoles());
65+
$this->assertSame($normalizedRoles, $collector->getRoles()->getRawData()[1]);
66+
if ($inheritedRoles) {
67+
$this->assertSame($inheritedRoles, $collector->getInheritedRoles()->getRawData()[1]);
68+
} else {
69+
$this->assertSame($inheritedRoles, $collector->getInheritedRoles()->getRawData()[0][0]);
70+
}
6771
$this->assertSame('hhamon', $collector->getUser());
6872
}
6973

src/Symfony/Bundle/SecurityBundle/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=5.5.9",
2020
"symfony/security": "~3.2",
21-
"symfony/http-kernel": "~3.1",
21+
"symfony/http-kernel": "~3.2",
2222
"symfony/polyfill-php70": "~1.0"
2323
},
2424
"require-dev": {
@@ -34,6 +34,7 @@
3434
"symfony/twig-bridge": "~2.8|~3.0",
3535
"symfony/process": "~2.8|~3.0",
3636
"symfony/validator": "~2.8|~3.0",
37+
"symfony/var-dumper": "~3.2",
3738
"symfony/yaml": "~2.8|~3.0",
3839
"symfony/expression-language": "~2.8|~3.0",
3940
"doctrine/doctrine-bundle": "~1.4",

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/events.html.twig

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -75,38 +75,7 @@
7575

7676
<tr>
7777
<td class="text-right">{{ listener.priority|default('-') }}</td>
78-
<td class="font-normal">
79-
{% if listener.type == 'Closure' %}
80-
81-
Closure
82-
<span class="text-muted text-small">(there is no class or file information)</span>
83-
84-
{% elseif listener.type == 'Function' %}
85-
86-
{% set link = listener.file|file_link(listener.line) %}
87-
{% if link %}
88-
<a href="{{ link }}">{{ listener.function }}()</a>
89-
<span class="text-muted text-small">({{ listener.file }})</span>
90-
{% else %}
91-
{{ listener.function }}()
92-
<span class="text-muted newline text-small">{{ listener.file }} (line {{ listener.line }})</span>
93-
{% endif %}
94-
95-
{% elseif listener.type == "Method" %}
96-
97-
{% set link = listener.file|file_link(listener.line) %}
98-
{% set class_namespace = listener.class|split('\\', -1)|join('\\') %}
99-
100-
{% if link %}
101-
<a href="{{ link }}"><strong>{{ listener.class|abbr_class|striptags }}</strong>::{{ listener.method }}()</a>
102-
<span class="text-muted text-small">({{ listener.class }})</span>
103-
{% else %}
104-
<span>{{ class_namespace }}\</span><strong>{{ listener.class|abbr_class|striptags }}</strong>::{{ listener.method }}()
105-
<span class="text-muted newline text-small">{{ listener.file }} (line {{ listener.line }})</span>
106-
{% endif %}
107-
108-
{% endif %}
109-
</td>
78+
<td class="font-normal">{{ profiler_dump(listener.data) }}</td>
11079
</tr>
11180

11281
{% if loop.last %}

0 commit comments

Comments
 (0)
0