Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 105d3cc

Browse files
committed
[HttpKernel] Deprecate passing objects as URI attributes to the ESI and SSI renderers
1 parent 8f3c06b commit 105d3cc

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

CHANGELOG-3.1.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CHANGELOG for 3.1.x
2+
===================
3+
4+
This changelog references the relevant changes (bug and security fixes) done
5+
in 3.1 minor versions.
6+
7+
To get the diff for a specific change, go to https://github.com/symfony/symfony/commit/XXX where XXX is the change hash
8+
To get the diff between two versions, go to https://github.com/symfony/symfony/compare/v3.1.0...v3.1.1
9+
10+
* 3.1.0
11+
12+
* bug #17611 [HttpKernel] Deprecate passing objects as URI attributes to the ESI and SSI renderers

UPGRADE-3.1.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ Form
1616
* The `choices_as_values` option of the `ChoiceType` has been deprecated and
1717
will be removed in Symfony 4.0.
1818

19+
HttpKernel
20+
----------
21+
22+
* Passing objects as URI attributes to the ESI and SSI renderers has been
23+
deprecated and will be removed in Symfony 4.0. The inline fragment
24+
renderer should be used with object attributes.
25+
1926
Serializer
2027
----------
2128

src/Symfony/Component/HttpKernel/Fragment/AbstractSurrogateFragmentRenderer.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public function __construct(SurrogateInterface $surrogate = null, FragmentRender
6464
public function render($uri, Request $request, array $options = array())
6565
{
6666
if (!$this->surrogate || !$this->surrogate->hasSurrogateCapability($request)) {
67+
if ($uri instanceof ControllerReference && $this->containsNonScalars($uri->attributes)) {
68+
@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);
69+
}
70+
6771
return $this->inlineStrategy->render($uri, $request, $options);
6872
}
6973

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

9397
return substr($fragmentUri, strlen($request->getSchemeAndHttpHost()));
9498
}
99+
100+
private function containsNonScalars(array $values)
101+
{
102+
foreach ($values as $value) {
103+
if (is_array($value) && $this->containsNonScalars($value)) {
104+
return true;
105+
} elseif (!is_scalar($value) && null !== $value) {
106+
return true;
107+
}
108+
}
109+
110+
return false;
111+
}
95112
}

src/Symfony/Component/HttpKernel/Tests/Fragment/EsiFragmentRendererTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,32 @@ public function testRenderFallbackToInlineStrategyIfEsiNotSupported()
2525
$strategy->render('/', Request::create('/'));
2626
}
2727

28+
/**
29+
* @group legacy
30+
*/
31+
public function testRenderFallbackWithObjectAttributesIsDeprecated()
32+
{
33+
$deprecations = array();
34+
set_error_handler(function ($type, $message) use (&$deprecations) {
35+
if (E_USER_DEPRECATED === $type) {
36+
$deprecations[] = $message;
37+
}
38+
});
39+
40+
$strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true), new UriSigner('foo'));
41+
42+
$request = Request::create('/');
43+
44+
$reference = new ControllerReference('main_controller', array('foo' => array('a' => array(), 'b' => new \stdClass())), array());
45+
46+
$strategy->render($reference, $request);
47+
48+
$this->assertCount(1, $deprecations);
49+
$this->assertContains('Passing objects as part of URI attributes to the ESI and SSI rendering strategies is deprecated', $deprecations[0]);
50+
51+
restore_error_handler();
52+
}
53+
2854
public function testRender()
2955
{
3056
$strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy());

0 commit comments

Comments
 (0)