From 9e1246a9d0feffa326c96ecee1db831580e6600c Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Tue, 29 Oct 2013 19:35:45 -0200 Subject: [PATCH 1/2] Adding a helper method to create AccessDeniedException from the controller --- .../FrameworkBundle/Controller/Controller.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php b/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php index 42a43fcd2c015..2ceb71384215a 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,7 +140,7 @@ public function stream($view, array $parameters = array(), StreamedResponse $res * * throw $this->createNotFoundException('Page not found!'); * - * @param string $message A message + * @param string $message A message * @param \Exception $previous The previous exception * * @return NotFoundHttpException @@ -149,6 +150,23 @@ public function createNotFoundException($message = 'Not Found', \Exception $prev return new NotFoundHttpException($message, $previous); } + /** + * Returns a 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 $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. * From 9323efacfb9db415be6dfdb324cf3c5cfed6586b Mon Sep 17 00:00:00 2001 From: Klaus Silveira Date: Fri, 17 Jan 2014 10:44:04 -0200 Subject: [PATCH 2/2] Minor adjustments based on PR comments --- .../Bundle/FrameworkBundle/Controller/Controller.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php b/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php index 2ceb71384215a..186c55326c879 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php +++ b/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php @@ -140,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 */ @@ -151,14 +151,14 @@ public function createNotFoundException($message = 'Not Found', \Exception $prev } /** - * Returns a AccessDeniedException. + * 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 $previous The previous exception + * @param string $message A message + * @param \Exception|null $previous The previous exception * * @return AccessDeniedException */