feature #9405 [FrameworkBundle] Added a helper method to create AccessDeniedException (klaussilveira)
This PR was squashed before being merged into the 2.5-dev branch (closes #9405).
Discussion
----------
[FrameworkBundle] Added a helper method to create AccessDeniedException
Just a small helper method that has been missing, since the addition of createNotFoundException().
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
Commits
-------
183d0ec
[FrameworkBundle] Added a helper method to create AccessDeniedException
This commit is contained in:
commit
e1b85db631
@ -18,6 +18,7 @@ use Symfony\Component\HttpFoundation\StreamedResponse;
|
|||||||
use Symfony\Component\DependencyInjection\ContainerAware;
|
use Symfony\Component\DependencyInjection\ContainerAware;
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||||
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||||
use Symfony\Component\Form\FormTypeInterface;
|
use Symfony\Component\Form\FormTypeInterface;
|
||||||
use Symfony\Component\Form\Form;
|
use Symfony\Component\Form\Form;
|
||||||
use Symfony\Component\Form\FormBuilder;
|
use Symfony\Component\Form\FormBuilder;
|
||||||
@ -139,8 +140,8 @@ class Controller extends ContainerAware
|
|||||||
*
|
*
|
||||||
* throw $this->createNotFoundException('Page not found!');
|
* throw $this->createNotFoundException('Page not found!');
|
||||||
*
|
*
|
||||||
* @param string $message A message
|
* @param string $message A message
|
||||||
* @param \Exception $previous The previous exception
|
* @param \Exception|null $previous The previous exception
|
||||||
*
|
*
|
||||||
* @return NotFoundHttpException
|
* @return NotFoundHttpException
|
||||||
*/
|
*/
|
||||||
@ -149,6 +150,23 @@ class Controller extends ContainerAware
|
|||||||
return new NotFoundHttpException($message, $previous);
|
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.
|
* Creates and returns a Form instance from the type of the form.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user