Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions 7 UPGRADE-3.1.md
Original file line number Diff line number Diff line change
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing entry about the removal in the UPGRADE-4.0.md file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not removed yet :)


Serializer
----------

Expand Down
4 changes: 4 additions & 0 deletions 4 src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is null special?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_scalar() returns false with null. We want to support nulls hence the second part of the condition.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be just if not elseif as you call return in other if.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stloyd actually, the code wasn't looking deep enough. I updated the test and the condition. Now the elseif is required.

return true;
}
}

return false;
}
}
Original file line number Diff line number Diff line change
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.