From 2abb9aac37ef9db5ed95bfb112bbcfa960ac95ef Mon Sep 17 00:00:00 2001 From: Wojciech Kania Date: Sat, 20 Feb 2021 18:02:11 +0100 Subject: [PATCH] [Security] Add PHP Attribute example to controller --- security.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/security.rst b/security.rst index 3b9341a07d6..18d0344f42e 100644 --- a/security.rst +++ b/security.rst @@ -1089,6 +1089,24 @@ Next, you'll need to create a route for this URL (but not a controller): } } + .. code-block:: php-attributes + + // src/Controller/SecurityController.php + namespace App\Controller; + + use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; + use Symfony\Component\Routing\Annotation\Route; + + class SecurityController extends AbstractController + { + #[Route('/logout', name: 'app_logout', methods: ['GET'])] + public function logout() + { + // controller can be blank: it will never be executed! + throw new \Exception('Don\'t forget to activate logout in security.yaml'); + } + } + .. code-block:: yaml # config/routes.yaml