feature #17611 [HttpKernel] Deprecate passing objects as URI attributes 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
This commit is contained in:
commit
83b53f4a89
@ -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
|
||||
----------
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
3.1.0
|
||||
-----
|
||||
* deprecated passing objects as URI attributes to the ESI and SSI renderers
|
||||
|
||||
3.0.0
|
||||
-----
|
||||
|
||||
|
@ -64,6 +64,10 @@ abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRendere
|
||||
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);
|
||||
}
|
||||
|
||||
@ -92,4 +96,17 @@ abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRendere
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,32 @@ class EsiFragmentRendererTest extends \PHPUnit_Framework_TestCase
|
||||
$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());
|
||||
|
Reference in New Issue
Block a user