Skip to content

Commit

Permalink
bug #22361 [HttpKernel et al.] Move DataCollector::cloneVar() to late…
Browse files Browse the repository at this point in the history
…Collect() (nicolas-grekas)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[HttpKernel et al.] Move DataCollector::cloneVar() to lateCollect()

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #22166
| License       | MIT
| Doc PR        | -

<!--
- Bug fixes must be submitted against the lowest branch where they apply
  (lowest branches are regularly merged to upper ones so they get the fixes too).
- Features and deprecations must be submitted against the master branch.
- Please fill in this template according to the PR you're about to submit.
- Replace this comment by a description of what your PR is solving.
-->

Commits
-------

f83f971 [HttpKernel et al.] Move DataCollector::cloneVar() to lateCollect()
  • Loading branch information
fabpot committed Apr 10, 2017
2 parents bf7d08d + f83f971 commit dbfea94
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 5 deletions.
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
use Symfony\Component\Security\Core\Role\RoleInterface;
use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
Expand All @@ -30,7 +31,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class SecurityDataCollector extends DataCollector
class SecurityDataCollector extends DataCollector implements LateDataCollectorInterface
{
private $tokenStorage;
private $roleHierarchy;
Expand Down Expand Up @@ -157,7 +158,10 @@ public function collect(Request $request, Response $response, \Exception $except
);
}
}
}

public function lateCollect()
{
$this->data = $this->cloneVar($this->data);
}

Expand Down
Expand Up @@ -63,6 +63,7 @@ public function testCollectAuthenticationTokenAndRoles(array $roles, array $norm

$collector = new SecurityDataCollector($tokenStorage, $this->getRoleHierarchy());
$collector->collect($this->getRequest(), $this->getResponse());
$collector->lateCollect();

$this->assertTrue($collector->isEnabled());
$this->assertTrue($collector->isAuthenticated());
Expand Down Expand Up @@ -90,6 +91,7 @@ public function testGetFirewall()

$collector = new SecurityDataCollector(null, null, null, null, $firewallMap);
$collector->collect($request, $this->getResponse());
$collector->lateCollect();
$collected = $collector->getFirewall();

$this->assertSame($firewallConfig->getName(), $collected['name']);
Expand Down
Expand Up @@ -16,12 +16,13 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;

/**
* @author Aaron Scherer <aequasi@gmail.com>
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
*/
class CacheDataCollector extends DataCollector
class CacheDataCollector extends DataCollector implements LateDataCollectorInterface
{
/**
* @var TraceableAdapter[]
Expand Down Expand Up @@ -50,7 +51,10 @@ public function collect(Request $request, Response $response, \Exception $except

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

public function lateCollect()
{
$this->data = $this->cloneVar($this->data);
}

Expand Down
Expand Up @@ -22,7 +22,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class ConfigDataCollector extends DataCollector
class ConfigDataCollector extends DataCollector implements LateDataCollectorInterface
{
/**
* @var KernelInterface
Expand Down Expand Up @@ -97,6 +97,10 @@ public function collect(Request $request, Response $response, \Exception $except
$this->data['php_version'] = $matches[1];
$this->data['php_version_extra'] = $matches[2];
}
}

public function lateCollect()
{
$this->data = $this->cloneVar($this->data);
}

Expand Down
Expand Up @@ -24,7 +24,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class RequestDataCollector extends DataCollector implements EventSubscriberInterface
class RequestDataCollector extends DataCollector implements EventSubscriberInterface, LateDataCollectorInterface
{
/** @var \SplObjectStorage */
protected $controllers;
Expand Down Expand Up @@ -147,7 +147,10 @@ public function collect(Request $request, Response $response, \Exception $except
));
}
}
}

public function lateCollect()
{
$this->data = $this->cloneVar($this->data);
}

Expand Down
Expand Up @@ -34,6 +34,7 @@ public function testCollect()
$c = new RequestDataCollector();

$c->collect($request = $this->createRequest(), $this->createResponse());
$c->lateCollect();

$attributes = $c->getRequestAttributes();

Expand Down Expand Up @@ -65,6 +66,7 @@ public function testCollectWithoutRouteParams()

$c = new RequestDataCollector();
$c->collect($request, $this->createResponse());
$c->lateCollect();

$this->assertEquals(array(), $c->getRouteParams());
}
Expand Down Expand Up @@ -93,6 +95,7 @@ public function testControllerInspection($name, $callable, $expected)
$response = $this->createResponse();
$this->injectController($c, $callable, $request);
$c->collect($request, $response);
$c->lateCollect();

$this->assertSame($expected, $c->getController()->getValue(true), sprintf('Testing: %s', $name));
}
Expand Down
Expand Up @@ -33,10 +33,11 @@ public function testCollect()
$profiler = new Profiler($this->storage);
$profiler->add($collector);
$profile = $profiler->collect($request, $response);
$profiler->saveProfile($profile);

$this->assertSame(204, $profile->getStatusCode());
$this->assertSame('GET', $profile->getMethod());
$this->assertSame('bar', $profiler->get('request')->getRequestQuery()->all()['foo']->getValue());
$this->assertSame('bar', $profile->getCollector('request')->getRequestQuery()->all()['foo']->getValue());
}

public function testFindWorksWithDates()
Expand Down

0 comments on commit dbfea94

Please sign in to comment.