Skip to content

[HttpKernel] Use VarDumper in the profiler #19614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions UPGRADE-3.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ Form
FrameworkBundle
---------------

* The service `serializer.mapping.cache.doctrine.apc` is deprecated. APCu should now
be automatically used when available.
* The service `serializer.mapping.cache.doctrine.apc` is deprecated. APCu should now
be automatically used when available.

HttpKernel
----------

* `DataCollector::varToString()` is deprecated and will be removed in Symfony
4.0. Use the `cloneVar()` method instead.

HttpFoundation
---------------
Expand Down
2 changes: 2 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ HttpKernel
have your own `ControllerResolverInterface` implementation, you should
inject an `ArgumentResolverInterface` instance.

* The `DataCollector::varToString()` method has been removed in favor of `cloneVar()`.

Serializer
----------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

{% for dump in collector.getDumps('html') %}
<div class="sf-dump sf-reset">
<h3>In
<span class="metadata">In
{% if dump.line %}
{% set link = dump.file|file_link(dump.line) %}
{% if link %}
Expand All @@ -56,10 +56,8 @@
{% else %}
{{ dump.name }}
{% endif %}
<small>line {{ dump.line }}</small>

<a class="text-small sf-toggle" data-toggle-selector="#sf-trace-{{ loop.index0 }}" data-toggle-alt-content="Hide code">Show code</a>
</h3>
line <a class="text-small sf-toggle" data-toggle-selector="#sf-trace-{{ loop.index0 }}">{{ dump.line }}</a>:
</span>

<div class="sf-dump-compact hidden" id="sf-trace-{{ loop.index0 }}">
<div class="trace">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<service id="data_collector.form" class="Symfony\Component\Form\Extension\DataCollector\FormDataCollector">
<tag name="data_collector" template="@WebProfiler/Collector/form.html.twig" id="form" priority="310" />
<argument type="service" id="data_collector.form.extractor" />
<argument>false</argument>
</service>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
use Symfony\Component\Security\Core\Authorization\DebugAccessDecisionManager;
use Symfony\Component\VarDumper\Cloner\Data;

/**
* SecurityDataCollector.
Expand Down Expand Up @@ -58,6 +59,7 @@ public function collect(Request $request, Response $response, \Exception $except
$this->data = array(
'enabled' => false,
'authenticated' => false,
'token' => null,
'token_class' => null,
'logout_url' => null,
'user' => '',
Expand All @@ -69,6 +71,7 @@ public function collect(Request $request, Response $response, \Exception $except
$this->data = array(
'enabled' => true,
'authenticated' => false,
'token' => null,
'token_class' => null,
'logout_url' => null,
'user' => '',
Expand Down Expand Up @@ -101,18 +104,24 @@ public function collect(Request $request, Response $response, \Exception $except
$this->data = array(
'enabled' => true,
'authenticated' => $token->isAuthenticated(),
'token' => $this->cloneVar($token),
'token_class' => get_class($token),
'logout_url' => $logoutUrl,
'user' => $token->getUsername(),
'roles' => array_map(function (RoleInterface $role) { return $role->getRole();}, $assignedRoles),
'inherited_roles' => array_map(function (RoleInterface $role) { return $role->getRole(); }, $inheritedRoles),
'roles' => $this->cloneVar(array_map(function (RoleInterface $role) { return $role->getRole();}, $assignedRoles)),
'inherited_roles' => $this->cloneVar(array_map(function (RoleInterface $role) { return $role->getRole(); }, $inheritedRoles)),
'supports_role_hierarchy' => null !== $this->roleHierarchy,
);
}

// collect voters and access decision manager information
if ($this->accessDecisionManager instanceof DebugAccessDecisionManager) {
$this->data['access_decision_log'] = $this->accessDecisionManager->getDecisionLog();
$this->data['access_decision_log'] = array_map(function ($decision) {
$decision['object'] = $this->cloneVar($decision['object']);

return $decision;
}, $this->accessDecisionManager->getDecisionLog());

$this->data['voter_strategy'] = $this->accessDecisionManager->getStrategy();

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

/**
* Get the full security token class as Data object.
*
* @return Data
*/
public function getToken()
{
return $this->data['token'];
}

/**
* Get the provider key (i.e. the name of the active firewall).
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% block page_title 'Security' %}

{% block toolbar %}
{% if collector.tokenClass %}
{% if collector.token %}
{% set is_authenticated = collector.enabled and collector.authenticated %}
{% set color_code = is_authenticated ? '' : 'yellow' %}
{% else %}
Expand All @@ -16,7 +16,7 @@
{% endset %}

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

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

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

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

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

{% if collector.tokenClass %}
{% if collector.token %}
<tr>
<th>Token class</th>
<td>{{ collector.tokenClass }}</td>
<th>Token</th>
<td>{{ profiler_dump(collector.token) }}</td>
</tr>
{% endif %}
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ public function testCollectAuthenticationTokenAndRoles(array $roles, array $norm
$this->assertTrue($collector->isAuthenticated());
$this->assertSame('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $collector->getTokenClass());
$this->assertTrue($collector->supportsRoleHierarchy());
$this->assertSame($normalizedRoles, $collector->getRoles());
$this->assertSame($inheritedRoles, $collector->getInheritedRoles());
$this->assertSame($normalizedRoles, $collector->getRoles()->getRawData()[1]);
if ($inheritedRoles) {
$this->assertSame($inheritedRoles, $collector->getInheritedRoles()->getRawData()[1]);
} else {
$this->assertSame($inheritedRoles, $collector->getInheritedRoles()->getRawData()[0][0]);
}
$this->assertSame('hhamon', $collector->getUser());
}

Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Bundle/SecurityBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=5.5.9",
"symfony/security": "~3.2",
"symfony/http-kernel": "~3.1",
"symfony/http-kernel": "~3.2",
"symfony/polyfill-php70": "~1.0"
},
"require-dev": {
Expand All @@ -34,6 +34,7 @@
"symfony/twig-bridge": "~2.8|~3.0",
"symfony/process": "~2.8|~3.0",
"symfony/validator": "~2.8|~3.0",
"symfony/var-dumper": "~3.2",
"symfony/yaml": "~2.8|~3.0",
"symfony/expression-language": "~2.8|~3.0",
"doctrine/doctrine-bundle": "~1.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,38 +75,7 @@

<tr>
<td class="text-right">{{ listener.priority|default('-') }}</td>
<td class="font-normal">
{% if listener.type == 'Closure' %}

Closure
<span class="text-muted text-small">(there is no class or file information)</span>

{% elseif listener.type == 'Function' %}

{% set link = listener.file|file_link(listener.line) %}
{% if link %}
<a href="{{ link }}">{{ listener.function }}()</a>
<span class="text-muted text-small">({{ listener.file }})</span>
{% else %}
{{ listener.function }}()
<span class="text-muted newline text-small">{{ listener.file }} (line {{ listener.line }})</span>
{% endif %}

{% elseif listener.type == "Method" %}

{% set link = listener.file|file_link(listener.line) %}
{% set class_namespace = listener.class|split('\\', -1)|join('\\') %}

{% if link %}
<a href="{{ link }}"><strong>{{ listener.class|abbr_class|striptags }}</strong>::{{ listener.method }}()</a>
<span class="text-muted text-small">({{ listener.class }})</span>
{% else %}
<span>{{ class_namespace }}\</span><strong>{{ listener.class|abbr_class|striptags }}</strong>::{{ listener.method }}()
<span class="text-muted newline text-small">{{ listener.file }} (line {{ listener.line }})</span>
{% endif %}

{% endif %}
</td>
<td class="font-normal">{{ profiler_dump(listener.data) }}</td>
</tr>

{% if loop.last %}
Expand Down
Loading