diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php b/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php index 42a43fcd2c015..186c55326c879 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php @@ -18,6 +18,7 @@ use Symfony\Component\DependencyInjection\ContainerAware; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Form\FormTypeInterface; use Symfony\Component\Form\Form; use Symfony\Component\Form\FormBuilder; @@ -139,8 +140,8 @@ public function stream($view, array $parameters = array(), StreamedResponse $res * * throw $this->createNotFoundException('Page not found!'); * - * @param string $message A message - * @param \Exception $previous The previous exception + * @param string $message A message + * @param \Exception|null $previous The previous exception * * @return NotFoundHttpException */ @@ -149,6 +150,23 @@ public function createNotFoundException($message = 'Not Found', \Exception $prev return new NotFoundHttpException($message, $previous); } + /** + * Returns an AccessDeniedException. + * + * This will result in a 403 response code. Usage example: + * + * throw $this->createAccessDeniedException('Unable to access this page!'); + * + * @param string $message A message + * @param \Exception|null $previous The previous exception + * + * @return AccessDeniedException + */ + public function createAccessDeniedException($message = 'Access Denied', \Exception $previous = null) + { + return new AccessDeniedException($message, $previous); + } + /** * Creates and returns a Form instance from the type of the form. *