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

Skip to content

Commit 9b18306

Browse files
committed
[HttpKernel] Deprecate passing objects as URI attributes to the ESI and SSI renderers
1 parent 5b59703 commit 9b18306

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ 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. Use another rendering strategy or use scalar values.', E_USER_DEPRECATED);
69+
}
6770
return $this->inlineStrategy->render($uri, $request, $options);
6871
}
6972

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

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

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' => 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)