8000 Add `@ContentSafe` annotation for controller actions by rvanlaak · Pull Request #686 · sensiolabs/SensioFrameworkExtraBundle · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Feb 24, 2023. It is now read-only.

Add @ContentSafe annotation for controller actions #686

Closed
wants to merge 4 commits into from

Conversation

rvanlaak
Copy link
@rvanlaak rvanlaak commented Jun 10, 2020

In Symfony 5.2 support was added for safe content negotiation via PR symfony/symfony#34847 and was explained via https://symfony.com/blog/new-in-symfony-5-1-the-safe-http-preference

This PR introduces the @ContentSafe annotation. The annotation automatically will get enabled when Response::setContentSafe method exists, or by setting content_safe.annotations to true in the configuration.

Controller actions do not necessarily create the Response object themselves.

Annotations like @Template can get used to do that.

/*
 * @Template()
 */
public function indexAction()
{
    return ['data' => $data];
}

Without the @ContentSafe annotation the @Template annotation can not get used anymore. With the @ContentSafe annotation this will look like:

/*
 * @Template()
 * @ContentSafe
 */
public function indexAction()
{
    return ['data' => $data];
}

Marking a Response with setContentSafe requires defining the response as variable.

Without content safe:

return new Response(200, '<html><body>Hello world!</body></html>');

With content safe:

$response = new Response(200, '<html><body>Hello world!</body></html>');
$response->setContentSafe();
return $response;

@rvanlaak rvanlaak marked this pull request as ready for review June 12, 2020 10:58
@rvanlaak rvanlaak changed the title Add ContentSafe annotation for controller actions Add @ContentSafe annotation for controller actions Jun 12, 2020
@rvanlaak
Copy link
Author

@fabpot what do you think of this PR? Would be great to have the @ContentSafe annotation at our disposal.

@fabpot
Copy link
Member
fabpot commented Dec 2, 2022

Closing as this repository is not maintained anymore. As of Symfony 6.2, all features have been moved to Symfony core now.
See #783

@fabpot fabpot closed this Dec 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0