8000 [HttpKernel] Use VarDumper in the profiler · symfony/symfony@0e16ca9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e16ca9

Browse files
wouterjnicolas-grekas
authored andcommitted
[HttpKernel] Use VarDumper in the profiler
1 parent df8cf70 commit 0e16ca9

File tree

24 files changed

+276
-172
lines changed

24 files changed

+276
-172
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/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: 18 additions & 32 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>
@@ -501,21 +501,7 @@
501501
<span class="newline">Caused by:</span>
502502
{% endif %}
503503

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 %}
504+
{{ profiler_dump(trace) }}
519505
{% else %}
520506
<em>Unknown.</em>
521507
{% endfor %}
@@ -535,7 +521,7 @@
535521
</h3>
536522

537523
<div id="{{ data.id }}-default_data">
538-
<table>
524+
<table class="dump-inline">
539525
<thead>
540526
<tr>
541527
<th width="180">Property</th>
@@ -547,21 +533,21 @@
547533
<th class="font-normal" scope="row">Model Format</th>
548534
<td>
549535
{% if data.default_data.model is defined %}
550-
{{ data.default_data.model }}
536+
{{ profiler_dump(data.default_data.model) }}
551537
{% else %}
552538
<em class="font-normal text-muted">same as normalized format</em>
553539
{% endif %}
554540
</td>
555541
</tr>
556542
<tr>
557543
<th class="font-normal" scope="row">Normalized Format</th>
558-
<td>{{ data.default_data.norm }}</td>
544+
<td>{{ profiler_dump(data.default_data.norm) }}</td>
559545
</tr>
560546
<tr>
561547
<th class="font-normal" scope="row">View Format</th>
562548
<td>
563549
{% if data.default_data.view is defined %}
564-
{{ data.default_data.view }}
550+
{{ profiler_dump(data.default_data.view) }}
565551
{% else %}
566552
<em class="font-normal text-muted">same as normalized format</em>
567553
{% endif %}
@@ -581,7 +567,7 @@
581567

582568
<div id="{{ data.id }}-submitted_data">
583569
{% if data.submitted_data.norm is defined %}
584-
<table>
570+
<table class="dump-inline">
585571
<thead>
586572
<tr>
587573
<th width="180">Property</th>
@@ -593,21 +579,21 @@
593579
<th class="font-normal" scope="row">View Format</th>
594580
<td>
595581
{% if data.submitted_data.view is defined %}
596-
{{ data.submitted_data.view }}
582+
{{ profiler_dump(data.submitted_data.view) }}
597583
{% else %}
598584
<em class="font-normal text-muted">same as normalized format</em>
599585
{% endif %}
600586
</td>
601587
</tr>
602588
<tr>
603589
<th class="font-normal" scope="row">Normalized Format</th>
604-
<td>{{ data.submitted_data.norm }}</td>
590+
<td>{{ profiler_dump(data.submitted_data.norm) }}</td>
605591
</tr>
606592
<tr>
607593
<th class="font-normal" scope="row">Model Format</th>
608594
<td>
609595
{% if data.submitted_data.model is defined %}
610-
{{ data.submitted_data.model }}
596+
{{ profiler_dump(data.submitted_data.model) }}
611597
{% else %}
612598
<em class="font-normal text-muted">same as normalized format</em>
613599
{% endif %}
@@ -632,7 +618,7 @@
632618

633619
<div id="{{ data.id }}-passed_options">
634620
{% if data.passed_options|length %}
635-
<table>
621+
<table class="dump-inline">
636622
<thead>
637623
<tr>
638624
<th width="180">Option</th>
@@ -644,12 +630,12 @@
644630
{% for option, value in data.passed_options %}
645631
<tr>
646632
<th>{{ option }}</th>
647-
<td>{{ value }}</td>
633+
<td>{{ profiler_dump(value) }}</td>
648634
<td>
649-
{% if data.resolved_options[option] is same as(value) %}
635+
{% if data.resolved_options[option] == value %}
650636
<em class="font-normal text-muted">same as passed value</em>
651637
{% else %}
652-
{{ data.resolved_options[option] }}
638+
{{ profiler_dump(data.resolved_options[option]) }}
653639
{% endif %}
654640
</td>
655641
</tr>
@@ -672,7 +658,7 @@
672658
</h3>
673659

674660
<div id="{{ data.id }}-resolved_options" class="hidden">
675-
<table>
661+
<table class="dump-inline">
676662
<thead>
677663
<tr>
678664
<th width="180">Option</th>
@@ -683,7 +669,7 @@
683669
{% for option, value in data.resolved_options %}
684670
<tr>
685671
<th scope="row">{{ option }}</th>
686-
<td>{{ value }}</td>
672+
<td>{{ profiler_dump(value) }}</td>
687673
</tr>
688674
{% endfor %}
689675
</tbody>
@@ -699,7 +685,7 @@
699685
</h3>
700686

701687
<div id="{{ data.id }}-view_vars" class="hidden">
702-
<table>
688+
<table class="dump-inline">
703689
<thead>
704690
<tr>
705691
<th width="180">Variable</th>
@@ -710,7 +696,7 @@
710696
{% for variable, value in data.view_vars %}
711697
<tr>
712698
<th scope="row">{{ variable }}</th>
713-
<td>{{ value }}</td>
699+
<td>{{ profiler_dump(value) }}</td>
714700
</tr>
715701
{% endfor %}
716702
</tbody>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
<p>No GET parameters</p>
121121
</div>
122122
{% else %}
123-
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestquery }, with_context = false) }}
123+
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestquery, maxDepth: 1 }, with_context = false) }}
124124
{% endif %}
125125

126126
<h3>POST Parameters</h3>
@@ -130,7 +130,7 @@
130130
<p>No POST parameters</p>
131131
</div>
132132
{% else %}
133-
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestrequest }, with_context = false) }}
133+
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestrequest, maxDepth: 1 }, with_context = false) }}
134134
{% endif %}
135135

136136
<h3>Request Attributes</h3>
@@ -252,7 +252,7 @@
252252
{% for child in profile.children %}
253253
<h3>
254254
<a href="{{ path('_profiler', { token: child.token }) }}">
255-
{{- child.getcollector('request').requestattributes.get('_controller') -}}
255+
{{- child.getcollector('request').identifier -}}
256256
</a>
257257
<small>(token = {{ child.token }})</small>
258258
</h3>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
{% for child in profile.children %}
129129
{% set events = child.getcollector('time').events %}
130130
<h4>
131-
<a href="{{ path('_profiler', { token: child.token, panel: 'time' }) }}">{{ child.getcollector('request').requestattributes.get('_controller') }}</a>
131+
<a href="{{ path('_profiler', { token: child.token, panel: 'time' }) }}">{{ child.getcollector('request').identifier }}</a>
132132
<small>{{ events.__section__.duration }} ms</small>
133133
</h4>
134134

0 commit comments

Comments
 (0)
0