Skip to content

Commit 97fd8de

Browse files
wouterjnicolas-grekas
authored andcommitted
[HttpKernel] Use VarDumper in the profiler
1 parent b835ab1 commit 97fd8de

File tree

27 files changed

+380
-234
lines changed

27 files changed

+380
-234
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
Validator
4551
---------

UPGRADE-4.0.md

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

135+
* The `DataCollector::varToString()` method has been removed in favor of `cloneVar()`.
136+
135137
Serializer
136138
----------
137139

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: 11 additions & 11 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>
@@ -152,7 +152,7 @@
152152
{% if collector.accessDecisionLog|default([]) is not empty %}
153153
<h2>Access decision log</h2>
154154

155-
<table class="decision-log">
155+
<table class="decision-log dump-inline">
156156
<col style="width: 30px">
157157
<col style="width: 120px">
158158
<col style="width: 25%">

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: 1 addition & 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.1,>=3.1.2",
21-
"symfony/http-kernel": "~3.1",
21+
"symfony/http-kernel": "~3.2",
2222
"symfony/polyfill-php70": "~1.0"
2323
},
2424
"require-dev": {

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

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@
474474
</a>
475475
</h3>
476476

477-
<table id="{{ data.id }}-errors">
477+
<table id="{{ data.id }}-errors" class="dump-inline">
478478
<thead>
479479
<tr>
480480
<th>Message</th>
@@ -496,29 +496,12 @@
496496
{% endif %}
497497
</td>
498498
<td>
499-
{% for trace in error.trace %}
500-
{% if not loop.first %}
501-
<span class="newline">Caused by:</span>
502-
{% endif %}
503-
504-
{% if trace.root is defined %}
505-
<strong class="newline">{{ trace.class }}</strong>
506-
<pre>
507-
{{- trace.root -}}
508-
{%- if trace.path is not empty -%}
509-
{%- if trace.path|first != '[' %}.{% endif -%}
510-
{{- trace.path -}}
511-
{%- endif %} = {{ trace.value -}}
512-
</pre>
513-
{% elseif trace.message is defined %}
514-
<strong class="newline">{{ trace.class }}</strong>
515-
<pre>{{ trace.message }}</pre>
516-
{% else %}
517-
<pre>{{ trace }}</pre>
518-
{% endif %}
499+
{% if error.trace %}
500+
<span class="newline">Caused by:</span>
501+
{{ profiler_dump(trace, maxDepth=2) }}
519502
{% else %}
520503
<em>Unknown.</em>
521-
{% endfor %}
504+
{% endif %}
522505
</td>
523506
</tr>
524507
{% endfor %}
@@ -535,7 +518,7 @@
535518
</h3>
536519

537520
<div id="{{ data.id }}-default_data">
538-
<table>
521+
<table class="dump-inline">
539522
<thead>
540523
<tr>
541524
<th width="180">Property</th>
@@ -547,21 +530,21 @@
547530
<th class="font-normal" scope="row">Model Format</th>
548531
<td>
549532
{% if data.default_data.model is defined %}
550-
{{ data.default_data.model }}
533+
{{ profiler_dump(data.default_data.model) }}
551534
{% else %}
552535
<em class="font-normal text-muted">same as normalized format</em>
553536
{% endif %}
554537
</td>
555538
</tr>
556539
<tr>
557540
<th class="font-normal" scope="row">Normalized Format</th>
558-
<td>{{ data.default_data.norm }}</td>
541+
<td>{{ profiler_dump(data.default_data.norm) }}</td>
559542
</tr>
560543
<tr>
561544
<th class="font-normal" scope="row">View Format</th>
562545
<td>
563546
{% if data.default_data.view is defined %}
564-
{{ data.default_data.view }}
547+
{{ profiler_dump(data.default_data.view) }}
565548
{% else %}
566549
<em class="font-normal text-muted">same as normalized format</em>
567550
{% endif %}
@@ -581,7 +564,7 @@
581564

582565
<div id="{{ data.id }}-submitted_data">
583566
{% if data.submitted_data.norm is defined %}
584-
<table>
567+
<table class="dump-inline">
585568
<thead>
586569
<tr>
587570
<th width="180">Property</th>
@@ -593,21 +576,21 @@
593576
<th class="font-normal" scope="row">View Format</th>
594577
<td>
595578
{% if data.submitted_data.view is defined %}
596-
{{ data.submitted_data.view }}
579+
{{ profiler_dump(data.submitted_data.view) }}
597580
{% else %}
598581
<em class="font-normal text-muted">same as normalized format</em>
599582
{% endif %}
600583
</td>
601584
</tr>
602585
<tr>
603586
<th class="font-normal" scope="row">Normalized Format</th>
604-
<td>{{ data.submitted_data.norm }}</td>
587+
<td>{{ profiler_dump(data.submitted_data.norm) }}</td>
605588
</tr>
606589
<tr>
607590
<th class="font-normal" scope="row">Model Format</th>
608591
<td>
609592
{% if data.submitted_data.model is defined %}
610-
{{ data.submitted_data.model }}
593+
{{ profiler_dump(data.submitted_data.model) }}
611594
{% else %}
612595
<em class="font-normal text-muted">same as normalized format</em>
613596
{% endif %}
@@ -632,7 +615,7 @@
632615

633616
<div id="{{ data.id }}-passed_options">
634617
{% if data.passed_options|length %}
635-
<table>
618+
<table class="dump-inline">
636619
<thead>
637620
<tr>
638621
<th width="180">Option</th>
@@ -644,12 +627,12 @@
644627
{% for option, value in data.passed_options %}
645628
<tr>
646629
<th>{{ option }}</th>
647-
<td>{{ value }}</td>
630+
<td>{{ profiler_dump(value) }}</td>
648631
<td>
649-
{% if data.resolved_options[option] is same as(value) %}
632+
{% if data.resolved_options[option] == value %}
650633
<em class="font-normal text-muted">same as passed value</em>
651634
{% else %}
652-
{{ data.resolved_options[option] }}
635+
{{ profiler_dump(data.resolved_options[option]) }}
653636
{% endif %}
654637
</td>
655638
</tr>
@@ -672,7 +655,7 @@
672655
</h3>
673656

674657
<div id="{{ data.id }}-resolved_options" class="hidden">
675-
<table>
658+
<table class="dump-inline">
676659
<thead>
677660
<tr>
678661
<th width="180">Option</th>
@@ -683,7 +666,7 @@
683666
{% for option, value in data.resolved_options %}
684667
<tr>
685668
<th scope="row">{{ option }}</th>
686-
<td>{{ value }}</td>
669+
<td>{{ profiler_dump(value) }}</td>
687670
</tr>
688671
{% endfor %}
689672
</tbody>
@@ -699,7 +682,7 @@
699682
</h3>
700683

701684
<div id="{{ data.id }}-view_vars" class="hidden">
702-
<table>
685+
<table class="dump-inline">
703686
<thead>
704687
<tr>
705688
<th width="180">Variable</th>
@@ -710,7 +693,7 @@
710693
{% for variable, value in data.view_vars %}
711694
<tr>
712695
<th scope="row">{{ variable }}</th>
713-
<td>{{ value }}</td>
696+
<td>{{ profiler_dump(value) }}</td>
714697
</tr>
715698
{% endfor %}
716699
</tbody>

0 commit comments

Comments
 (0)