### Install SensioFrameworkExtraBundle via Composer Source: https://symfony.com/bundles/SensioFrameworkExtraBundle/current/index.html Use the official Symfony recipe to automatically install and configure the bundle. ```bash $ composer require sensio/framework-extra-bundle ``` -------------------------------- ### Controller with Annotations Source: https://symfony.com/bundles/SensioFrameworkExtraBundle/current/index.html Demonstrates the usage of various annotations for controller configuration, including routing, caching, template rendering, parameter conversion, and security. ```php use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; /** * @Route("/blog") * @Cache(expires="tomorrow") */ class AnnotController { /** * @Route("/") * @Template */ public function index() { $posts = ...; return array('posts' => $posts); } /** * @Route("/{id}") * @Method("GET") * @ParamConverter("post", class="SensioBlogBundle:Post") * @Template("@SensioBlog/annot/show.html.twig", vars={"post"}) * @Cache(smaxage="15", lastmodified="post.getUpdatedAt()", etag="'Post' ~ post.getId() ~ post.getUpdatedAt()") * @IsGranted("ROLE_SPECIAL_USER") * @Security("is_granted('ROLE_ADMIN') and is_granted('POST_SHOW', post)") */ public function show(Post $post) { } } ``` -------------------------------- ### Configure SensioFrameworkExtraBundle Source: https://symfony.com/bundles/SensioFrameworkExtraBundle/current/index.html Default configuration settings for the bundle, available in YAML, XML, and PHP formats. ```yaml sensio_framework_extra: router: { annotations: true } # Deprecated; use routing annotations of Symfony core instead request: { converters: true, auto_convert: true } view: { annotations: true } cache: { annotations: true } security: { annotations: true } ``` ```xml ``` ```php // load the profiler $container->loadFromExtension('sensio_framework_extra', array( 'router' => array('annotations' => true), 'request' => array('converters' => true, 'auto_convert' => true), 'view' => array('annotations' => true), 'cache' => array('annotations' => true), 'security' => array('annotations' => true), )); ``` -------------------------------- ### Importing Annotation Routes Source: https://symfony.com/bundles/SensioFrameworkExtraBundle/current/index.html Configuration file to import routes defined by annotations from a controller directory. ```yaml # config/routes/annotations.yaml # import routes from a controller directory annot: resource: "@AnnotRoutingBundle/Controller" type: annotation ``` -------------------------------- ### Controller with PHP 8 Attributes Source: https://symfony.com/bundles/SensioFrameworkExtraBundle/current/index.html Shows the equivalent controller configuration using PHP 8 attributes instead of traditional annotations. ```php use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; #[Route('/blog')] #[Cache(expired: 'tomorrow')] class AnnotController { #[Route('/')] #[Template] public function index() { $posts = ...; return array('posts' => $posts); } #[Route('/{id}')] #[Method('GET')] #[ParamConverter('post', class: 'SensioBlogBundle:Post')] #[Template('@SensioBlog/annot/show.html.twig", vars: ['post'])] #[Cache(smaxage: 15, lastmodified: 'post.getUpdatedAt()', etag: "'Post' ~ post.getId() ~ post.getUpdatedAt()")] #[IsGranted('ROLE_SPECIAL_USER')] #[Security("is_granted('ROLE_ADMIN') and is_granted('POST_SHOW', post)")] public function show(Post $post) { } } ``` -------------------------------- ### Simplified Controller Method with Annotations Source: https://symfony.com/bundles/SensioFrameworkExtraBundle/current/index.html A simplified version of a controller method where some annotations are omitted due to convention. ```php /** * @Route("/{id}") * @Cache(smaxage="15", lastModified="post.getUpdatedAt()", Etag="'Post' ~ post.getId() ~ post.getUpdatedAt()") * @IsGranted("ROLE_SPECIAL_USER") * @Security("is_granted('ROLE_ADMIN') and is_granted('POST_SHOW', post)") */ public function show(Post $post) { } ``` -------------------------------- ### Simplified Controller Method with PHP 8 Attributes Source: https://symfony.com/bundles/SensioFrameworkExtraBundle/current/index.html A simplified version of a controller method using PHP 8 attributes, omitting some due to convention. ```php #[Route('/{id}')] #[Cache(smaxage: 15, lastmodified: 'post.getUpdatedAt()', etag: "'Post' ~ post.getId() ~ post.getUpdatedAt()")] #[IsGranted('ROLE_SPECIAL_USER')] #[Security("is_granted('ROLE_ADMIN') and is_granted('POST_SHOW', post)")] public function show(Post $post) { } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.