Skip to content

Commit b8bc469

Browse files
[VarDumper] Allow seamless use of Data clones
1 parent 42de145 commit b8bc469

File tree

32 files changed

+384
-207
lines changed

32 files changed

+384
-207
lines changed

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,19 @@ public function collect(Request $request, Response $response, \Exception $except
109109
$this->data = array(
110110
'enabled' => true,
111111
'authenticated' => $token->isAuthenticated(),
112-
'token' => $this->cloneVar($token),
112+
'token' => $token,
113113
'token_class' => get_class($token),
114114
'logout_url' => $logoutUrl,
115115
'user' => $token->getUsername(),
116-
'roles' => $this->cloneVar(array_map(function (RoleInterface $role) { return $role->getRole(); }, $assignedRoles)),
117-
'inherited_roles' => $this->cloneVar(array_map(function (RoleInterface $role) { return $role->getRole(); }, $inheritedRoles)),
116+
'roles' => array_map(function (RoleInterface $role) { return $role->getRole(); }, $assignedRoles),
117+
'inherited_roles' => array_map(function (RoleInterface $role) { return $role->getRole(); }, $inheritedRoles),
118118
'supports_role_hierarchy' => null !== $this->roleHierarchy,
119119
);
120120
}
121121

122122
// collect voters and access decision manager information
123123
if ($this->accessDecisionManager instanceof TraceableAccessDecisionManager) {
124-
$this->data['access_decision_log'] = array_map(function ($decision) {
125-
$decision['object'] = $this->cloneVar($decision['object']);
126-
127-
return $decision;
128-
}, $this->accessDecisionManager->getDecisionLog());
129-
124+
$this->data['access_decision_log'] = $this->accessDecisionManager->getDecisionLog();
130125
$this->data['voter_strategy'] = $this->accessDecisionManager->getStrategy();
131126

132127
foreach ($this->accessDecisionManager->getVoters() as $voter) {
@@ -155,10 +150,12 @@ public function collect(Request $request, Response $response, \Exception $except
155150
'access_denied_handler' => $firewallConfig->getAccessDeniedHandler(),
156151
'access_denied_url' => $firewallConfig->getAccessDeniedUrl(),
157152
'user_checker' => $firewallConfig->getUserChecker(),
158-
'listeners' => $this->cloneVar($firewallConfig->getListeners()),
153+
'listeners' => $firewallConfig->getListeners(),
159154
);
160155
}
161156
}
157+
158+
$this->data = $this->cloneVar($this->data);
162159
}
163160

164161
/**

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,10 @@ public function testCollectAuthenticationTokenAndRoles(array $roles, array $norm
6666

6767
$this->assertTrue($collector->isEnabled());
6868
$this->assertTrue($collector->isAuthenticated());
69-
$this->assertSame('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $collector->getTokenClass());
69+
$this->assertSame('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $collector->getTokenClass()->getValue());
7070
$this->assertTrue($collector->supportsRoleHierarchy());
71-
$this->assertSame($normalizedRoles, $collector->getRoles()->getRawData()[1]);
72-
if ($inheritedRoles) {
73-
$this->assertSame($inheritedRoles, $collector->getInheritedRoles()->getRawData()[1]);
74-
} else {
75-
$this->assertSame($inheritedRoles, $collector->getInheritedRoles()->getRawData()[0][0]);
76-
}
71+
$this->assertSame($normalizedRoles, $collector->getRoles()->getValue(true));
72+
$this->assertSame($inheritedRoles, $collector->getInheritedRoles()->getValue(true));
7773
$this->assertSame('hhamon', $collector->getUser());
7874
}
7975

@@ -107,7 +103,7 @@ public function testGetFirewall()
107103
$this->assertSame($firewallConfig->getAccessDeniedHandler(), $collected['access_denied_handler']);
108104
$this->assertSame($firewallConfig->getAccessDeniedUrl(), $collected['access_denied_url']);
109105
$this->assertSame($firewallConfig->getUserChecker(), $collected['user_checker']);
110-
$this->assertSame($firewallConfig->getListeners(), $collected['listeners']->getRawData()[0][0]);
106+
$this->assertSame($firewallConfig->getListeners(), $collected['listeners']->getValue());
111107
}
112108

113109
public function testGetFirewallReturnsNull()

src/Symfony/Bundle/SecurityBundle/composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@
3636
"symfony/twig-bridge": "~2.8|~3.0",
3737
"symfony/process": "~2.8|~3.0",
3838
"symfony/validator": "~2.8|~3.0",
39-
"symfony/var-dumper": "~3.2",
39+
"symfony/var-dumper": "~3.3",
4040
"symfony/yaml": "~2.8|~3.0",
4141
"symfony/expression-language": "~2.8|~3.0",
4242
"doctrine/doctrine-bundle": "~1.4",
4343
"twig/twig": "~1.28|~2.0"
4444
},
45+
"conflict": {
46+
"symfony/var-dumper": "<3.3"
47+
},
4548
"suggest": {
4649
"symfony/security-acl": "For using the ACL functionality of this bundle"
4750
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
<div class="metric">
9191
<span class="value">
9292
{% if key == 'time' %}
93-
{{ '%0.2f'|format(1000*value) }} ms
93+
{{ '%0.2f'|format(1000*value.value) }} ms
9494
{% else %}
9595
{{ value }}
9696
{% endif %}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
{% for name in collector.bundles|keys|sort %}
268268
<tr>
269269
<th scope="row" class="font-normal">{{ name }}</th>
270-
<td class="font-normal">{{ collector.bundles[name] }}</td>
270+
<td class="font-normal">{{ profiler_dump(collector.bundles[name]) }}</td>
271271
</tr>
272272
{% endfor %}
273273
</tbody>

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

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

7676
<tr>
7777
<td class="text-right">{{ listener.priority|default('-') }}</td>
78-
<td class="font-normal">{{ profiler_dump(listener.data) }}</td>
78+
<td class="font-normal">{{ profiler_dump(listener.stub) }}</td>
7979
</tr>
8080

8181
{% if loop.last %}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
<a class="btn btn-link text-small sf-toggle" data-toggle-selector="#{{ context_id }}" data-toggle-alt-content="Hide trace">Show trace</a>
183183

184184
<div id="{{ context_id }}" class="context sf-toggle-content sf-toggle-hidden">
185-
{{ profiler_dump(log.context.seek('exception').seek('\0Exception\0trace'), maxDepth=2) }}
185+
{{ profiler_dump(log.context.exception['\0Exception\0trace'], maxDepth=2) }}
186186
</div>
187187
</span>
188188
{% elseif log.context is defined and log.context is not empty %}

src/Symfony/Bundle/WebProfilerBundle/Twig/WebProfilerExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ public function dumpLog(\Twig_Environment $env, $message, Data $context)
9898
}
9999

100100
$replacements = array();
101-
foreach ($context->getRawData()[1] as $k => $v) {
102-
$v = '{'.twig_escape_filter($env, $k).'}';
103-
$replacements['&quot;'.$v.'&quot;'] = $replacements[$v] = $this->dumpData($env, $context->seek($k));
101+
foreach ($context as $k => $v) {
102+
$k = '{'.twig_escape_filter($env, $k).'}';
103+
$replacements['&quot;'.$k.'&quot;'] = $replacements[$k] = $this->dumpData($env, $v);
104104
}
105105

106106
return '<span class="dump-inline">'.strtr($message, $replacements).'</span>';

src/Symfony/Bundle/WebProfilerBundle/composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"symfony/routing": "~2.8|~3.0",
2323
"symfony/twig-bridge": "~2.8|~3.0",
2424
"twig/twig": "~1.28|~2.0",
25-
"symfony/var-dumper": "~3.2"
25+
"symfony/var-dumper": "~3.3"
2626
},
2727
"require-dev": {
2828
"symfony/config": "~2.8|~3.0",
@@ -31,7 +31,8 @@
3131
"symfony/stopwatch": "~2.8|~3.0"
3232
},
3333
"conflict": {
34-
"symfony/event-dispatcher": "<3.2"
34+
"symfony/event-dispatcher": "<3.2",
35+
"symfony/var-dumper": "<3.3"
3536
},
3637
"autoload": {
3738
"psr-4": { "Symfony\\Bundle\\WebProfilerBundle\\": "" },

src/Symfony/Component/Cache/DataCollector/CacheDataCollector.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,13 @@ public function collect(Request $request, Response $response, \Exception $except
4545
$empty = array('calls' => array(), 'config' => array(), 'options' => array(), 'statistics' => array());
4646
$this->data = array('instances' => $empty, 'total' => $empty);
4747
foreach ($this->instances as $name => $instance) {
48-
$calls = $instance->getCalls();
49-
foreach ($calls as $call) {
50-
if (isset($call->result)) {
51-
$call->result = $this->cloneVar($call->result);
52-
}
53-
if (isset($call->argument)) {
54-
$call->argument = $this->cloneVar($call->argument);
55-
}
56-
}
57-
$this->data['instances']['calls'][$name] = $calls;
48+
$this->data['instances']['calls'][$name] = $instance->getCalls();
5849
}
5950

6051
$this->data['instances']['statistics'] = $this->calculateStatistics();
6152
$this->data['total']['statistics'] = $this->calculateTotalStatistics();
53+
54+
$this->data = $this->cloneVar($this->data);
6255
}
6356

6457
/**
@@ -133,7 +126,7 @@ private function calculateStatistics()
133126
$statistics[$name]['misses'] += $count - $call->misses;
134127
} elseif ('hasItem' === $call->name) {
135128
$statistics[$name]['reads'] += 1;
136-
if (false === $call->result->getRawData()[0][0]) {
129+
if (false === $call->result) {
137130
$statistics[$name]['misses'] += 1;
138131
} else {
139132
$statistics[$name]['hits'] += 1;

0 commit comments

Comments
 (0)