Skip to content

Commit

Permalink
feature #17611 [HttpKernel] Deprecate passing objects as URI attribut…
Browse files Browse the repository at this point in the history
…es to the ESI and SSI renderers (jakzal)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[HttpKernel] Deprecate passing objects as URI attributes to the ESI and SSI renderers

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

Commits
-------

a38d96e [HttpKernel] Deprecate passing objects as URI attributes to the ESI and SSI renderers
  • Loading branch information
fabpot committed Jan 31, 2016
2 parents 8f3c06b + a38d96e commit 83b53f4
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
7 changes: 7 additions & 0 deletions UPGRADE-3.1.md
Expand Up @@ -16,6 +16,13 @@ Form
* The `choices_as_values` option of the `ChoiceType` has been deprecated and
will be removed in Symfony 4.0.

HttpKernel
----------

* Passing objects as URI attributes to the ESI and SSI renderers has been
deprecated and will be removed in Symfony 4.0. The inline fragment
renderer should be used with object attributes.

Serializer
----------

Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
@@ -1,6 +1,10 @@
CHANGELOG
=========

3.1.0
-----
* deprecated passing objects as URI attributes to the ESI and SSI renderers

3.0.0
-----

Expand Down
Expand Up @@ -64,6 +64,10 @@ public function __construct(SurrogateInterface $surrogate = null, FragmentRender
public function render($uri, Request $request, array $options = array())
{
if (!$this->surrogate || !$this->surrogate->hasSurrogateCapability($request)) {
if ($uri instanceof ControllerReference && $this->containsNonScalars($uri->attributes)) {
@trigger_error('Passing objects as part of URI attributes to the ESI and SSI rendering strategies is deprecated since version 3.1, and will be removed in 4.0. Use a different rendering strategy or pass scalar values.', E_USER_DEPRECATED);
}

return $this->inlineStrategy->render($uri, $request, $options);
}

Expand Down Expand Up @@ -92,4 +96,17 @@ private function generateSignedFragmentUri($uri, Request $request)

return substr($fragmentUri, strlen($request->getSchemeAndHttpHost()));
}

private function containsNonScalars(array $values)
{
foreach ($values as $value) {
if (is_array($value) && $this->containsNonScalars($value)) {
return true;
} elseif (!is_scalar($value) && null !== $value) {
return true;
}
}

return false;
}
}
Expand Up @@ -25,6 +25,32 @@ public function testRenderFallbackToInlineStrategyIfEsiNotSupported()
$strategy->render('/', Request::create('/'));
}

/**
* @group legacy
*/
public function testRenderFallbackWithObjectAttributesIsDeprecated()
{
$deprecations = array();
set_error_handler(function ($type, $message) use (&$deprecations) {
if (E_USER_DEPRECATED === $type) {
$deprecations[] = $message;
}
});

$strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true), new UriSigner('foo'));

$request = Request::create('/');

$reference = new ControllerReference('main_controller', array('foo' => array('a' => array(), 'b' => new \stdClass())), array());

$strategy->render($reference, $request);

$this->assertCount(1, $deprecations);
$this->assertContains('Passing objects as part of URI attributes to the ESI and SSI rendering strategies is deprecated', $deprecations[0]);

restore_error_handler();
}

public function testRender()
{
$strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy());
Expand Down

0 comments on commit 83b53f4

Please sign in to comment.