diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php index 96b4fa10fb22a..cf7df37e86f94 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php @@ -289,10 +289,16 @@ protected function createNotFoundException(string $message = 'Not Found', \Excep * * throw $this->createAccessDeniedException('Unable to access this page!'); * + * @throws \LogicException If SecurityBundle is not available + * * @final since version 3.4 */ protected function createAccessDeniedException(string $message = 'Access Denied.', \Exception $previous = null): AccessDeniedException { + if (!class_exists(AccessDeniedException::class)) { + throw new \LogicException('You can not use the "createAccessDeniedException" method if the SecurityBundle is not registered in your application. Try running "composer require security-core".'); + } + return new AccessDeniedException($message, $previous); }