10000 [VarDumper] Allow seamless use of Data clones by nicolas-grekas · Pull Request #21638 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[VarDumper] Allow seamless use of Data clones #21638

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 1 commit into from
Feb 27, 2017
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
10000
Diff view
Diff view
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\TraceableAccessDecisionManager;
use Symfony\Component\VarDumper\Caster\ClassStub;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\Security\Http\FirewallMapInterface;
use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
Expand All @@ -36,6 +37,7 @@ class SecurityDataCollector extends DataCollector
private $logoutUrlGenerator;
private $accessDecisionManager;
private $firewallMap;
private $hasVarDumper;

/**
* Constructor.
Expand All @@ -53,6 +55,7 @@ public function __construct(TokenStorageInterface $tokenStorage = null, RoleHier
$this->logoutUrlGenerator = $logoutUrlGenerator;
$this->accessDecisionManager = $accessDecisionManager;
$this->firewallMap = $firewallMap;
$this->hasVarDumper = class_exists(ClassStub::class);
}

/**
Expand Down Expand Up @@ -109,28 +112,23 @@ 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),
'token' => $token,
'token_class' => $this->hasVarDumper ? new ClassStub(get_class($token)) : get_class($token),
'logout_url' => $logoutUrl,
'user' => $token->getUsername(),
'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)),
'roles' => array_map(function (RoleInterface $role) { return $role->getRole(); }, $assignedRoles),
'inherited_roles' => 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 TraceableAccessDecisionManager) {
$this->data['access_decision_log'] = array_map(function ($decision) {
$decision['object'] = $this->cloneVar($decision['object']);

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

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

foreach ($this->accessDecisionManager->getVoters() as $voter) {
$this->data['voters'][] = get_class($voter);
$this->data['voters'][] = $this->hasVarDumper ? new ClassStub(get_class($voter)) : get_class($voter);
}
} else {
$this->data['access_decision_log'] = array();
Expand All @@ -155,10 +153,12 @@ public function collect(Request $request, Response $response, \Exception $except
'access_denied_handler' => $firewallConfig->getAccessDeniedHandler(),
'access_denied_url' => $firewallConfig->getAccessDeniedUrl(),
'user_checker' => $firewallConfig->getUserChecker(),
'listeners' => $this->cloneVar($firewallConfig->getListeners()),
'listeners' => $firewallConfig->getListeners(),
);
}
}

$this->data = $this->cloneVar($this->data);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,10 @@ public function testCollectAuthenticationTokenAndRoles(array $roles, array $norm

$this->assertTrue($collector->isEnabled());
$this->assertTrue($collector->isAuthenticated());
$this->assertSame('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $collector->getTokenClass());
$this->assertSame('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $collector->getTokenClass()->getValue());
$this->assertTrue($collector->supportsRoleHierarchy());
$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($normalizedRoles, $collector->getRoles()->getValue(true));
$this->assertSame($inheritedRoles, $collector->getInheritedRoles()->getValue(true));
$this->assertSame('hhamon', $collector->getUser());
}

Expand Down Expand Up @@ -107,7 +103,7 @@ public function testGetFirewall()
$this->assertSame($firewallConfig->getAccessDeniedHandler(), $collected['access_denied_handler']);
$this->assertSame($firewallConfig->getAccessDeniedUrl(), $collected['access_denied_url']);
$this->assertSame($firewallConfig->getUserChecker(), $collected['user_checker']);
$this->assertSame($firewallConfig->getListeners(), $collected['listeners']->getRawData()[0][0]);
$this->assertSame($firewallConfig->getListeners(), $collected['listeners']->getValue());
}

public function testGetFirewallReturnsNull()
Expand Down
7 changes: 5 additions & 2 deletions src/Symfony/Bundle/SecurityBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"php": ">=5.5.9",
"symfony/security": "~3.3",
"symfony/dependency-injection": "~3.3",
"symfony/http-kernel": "~3.2",
"symfony/http-kernel": "~3.3",
"symfony/polyfill-php70": "~1.0"
},
"require-dev": {
Expand All @@ -37,12 +37,15 @@
"symfony/twig-bridge": "~2.8|~3.0",
"symfony/process": "~2.8|~3.0",
"symfony/validator": "^3.2.5",
"symfony/var-dumper": "~3.2",
"symfony/var-dumper": "~3.3",
"symfony/yaml": "~2.8|~3.0",
"symfony/expression-language": "~2.8|~3.0",
"doctrine/doctrine-bundle": "~1.4",
"twig/twig": "~1.28|~2.0"
},
"conflict": {
"symfony/var-dumper": "<3.3"
},
"suggest": {
"symfony/security-acl": "For using the ACL functionality of this bundle"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<div class="metric">
<span class="value">
{% if key == 'time' %}
{{ '%0.2f'|format(1000*value) }} ms
{{ '%0.2f'|format(1000*value.value) }} ms
{% else %}
{{ value }}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
{% for name in collector.bundles|keys|sort %}
<tr>
<th scope="row" class="font-normal">{{ name }}</th>
<td class="font-normal">{{ collector.bundles[name] }}</td>
<td class="font-normal">{{ profiler_dump(collector.bundles[name]) }}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@

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

{% if loop.last %}
Expand Down
< 10000 td id="diff-2a47a1a00839a6617bc42670002b9258752ba1bc2ab91d8a7ea14054062a93cfL184" data-line-number="184" class="blob-num blob-num-context js-linkable-line-number">
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
<a class="btn btn-link text-small sf-toggle" data-toggle-selector="#{{ context_id }}" data-toggle-alt-content="Hide trace">Show trace</a>

<div id="{{ context_id }}" class="context sf-toggle-content sf-toggle-hidden">
{{ profiler_dump(log.context.seek('exception').seek('\0Exception\0trace'), maxDepth=2) }}
{{ profiler_dump(log.context.exception['\0Exception\0trace'], maxDepth=2) }}
</div>
</span>
{% elseif log.context is defined and log.context is not empty %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public function dumpLog(\Twig_Environment $env, $message, Data $context)
}

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

return '<span class="dump-inline">'.strtr($message, $replacements).'</span>';
Expand Down
5 changes: 3 additions & 2 deletions src/Symfony/Bundle/WebProfilerBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"symfony/routing": "~2.8|~3.0",
"symfony/twig-bridge": "~2.8|~3.0",
"twig/twig": "~1.28|~2.0",
"symfony/var-dumper": "~3.2"
"symfony/var-dumper": "~3.3"
},
"require-dev": {
"symfony/config": "~2.8|~3.0",
Expand All @@ -31,7 +31,8 @@
"symfony/stopwatch": "~2.8|~3.0"
},
"conflict": {
"symfony/event-dispatcher": "<3.2"
"symfony/event-dispatcher": "<3.2",
"symfony/var-dumper": "<3.3"
},
"autoload": {
"psr-4": { "Symfony\\Bundle\\WebProfilerBundle\\": "" },
Expand Down
15 changes: 4 additions & 11 deletions src/Symfony/Component/Cache/DataCollector/CacheDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,13 @@ public function collect(Request $request, Response $response, \Exception $except
$empty = array('calls' => array(), 'config' => array(), 'options' => array(), 'statistics' => array());
$this->data = array('instances' => $empty, 'total' => $empty);
foreach ($this->instances as $name => $instance) {
$calls = $instance->getCalls();
foreach ($calls as $call) {
if (isset($call->result)) {
$call->result = $this->cloneVar($call->result);
}
if (isset($call->argument)) {
$call->argument = $this->cloneVar($call->argument);
}
}
$this->data['instances']['calls'][$name] = $calls;
$this->data['instances']['calls'][$name] = $instance->getCalls();
}

$this->data['instances']['statistics'] = $this->calculateStatistics();
$this->data['total']['statistics'] = $this->calculateTotalStatistics();

$this->data = $this->cloneVar($this->data);
}

/**
Expand Down Expand Up @@ -133,7 +126,7 @@ private function calculateStatistics()
$statistics[$name]['misses'] += $count - $call->misses;
} elseif ('hasItem' === $call->name) {
$statistics[$name]['reads'] += 1;
if (false === $call->result->getRawData()[0][0]) {
if (false === $call->result) {
$statistics[$name]['misses'] += 1;
} else {
$statistics[$name]['hits'] += 1;
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Cache/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"doctrine/dbal": "~2.4",
"predis/predis": "~1.0"
},
"conflict": {
"symfony/var-dumper": "<3.3"
},
"suggest": {
"symfony/polyfill-apcu": "For using ApcuAdapter on HHVM"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class WrappedListener
private $stopwatch;
private $dispatcher;
private $pretty;
private $data;
private $stub;

private static $cloner;

Expand Down Expand Up @@ -91,15 +91,15 @@ public function getPretty()

public function getInfo($eventName)
{
if (null === $this->data) {
$this->data = false !== self::$cloner ? self::$cloner->cloneVar(array(new ClassStub($this->pretty.'()', $this->listener)))->seek(0) : $this->pretty;
if (null === $this->stub) {
$this->stub = false === self::$cloner ? $this->pretty.'()' : new ClassStub($this->pretty.'()', $this->listener);
}

return array(
'event' => $eventName,
'priority' => null !== $this->dispatcher ? $this->dispatcher->getListenerPriority($eventName, $this->listener) : null,
'pretty' => $this->pretty,
'data' => $this->data,
'stub' => $this->stub,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@ public function testGetCalledListeners()
$tdispatcher->addListener('foo', $listener = function () {});

$listeners = $tdispatcher->getNotCalledListeners();
$this->assertArrayHasKey('data', $listeners['foo.closure']);
unset($listeners['foo.closure']['data']);
$this->assertArrayHasKey('stub', $listeners['foo.closure']);
unset($listeners['foo.closure']['stub']);
$this->assertEquals(array(), $tdispatcher->getCalledListeners());
$this->assertEquals(array('foo.closure' => array('event' => 'foo', 'pretty' => 'closure', 'priority' => 0)), $listeners);

$tdispatcher->dispatch('foo');

$listeners = $tdispatcher->getCalledListeners();
$this->assertArrayHasKey('data', $listeners['foo.closure']);
unset($listeners['foo.closure']['data']);
$this->assertArrayHasKey('stub', $listeners['foo.closure']);
unset($listeners['foo.closure']['stub']);
$this->assertEquals(array('foo.closure' => array('event' => 'foo', 'pretty' => 'closure', 'priority' => null)), $listeners);
$this->assertEquals(array(), $tdispatcher->getNotCalledListeners());
}
Expand Down
Loading
0