8000 feature #9405 [FrameworkBundle] Added a helper method to create Acces… · symfony/symfony@e1b85db · GitHub
[go: up one dir, main page]

Skip to content

Commit e1b85db

Browse files
committed
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
2 parents 7da803f + 183d0ec commit e1b85db

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\DependencyInjection\ContainerAware;
1919
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2020
use Symfony\Component\HttpKernel\HttpKernelInterface;
21+
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
2122
use Symfony\Component\Form\FormTypeInterface;
2223
use Symfony\Component\Form\Form;
2324
use Symfony\Component\Form\FormBuilder;
@@ -139,8 +140,8 @@ public function stream($view, array $parameters = array(), StreamedResponse $res
139140
*
140141
* throw $this->createNotFoundException('Page not found!');
141142
*
142-
* @param string $message A message
143-
* @param \Exception $previous The previous exception
143+
* @param string $message A message
144+
* @param \Exception|null $previous The previous exception
144145
*
145146
* @return NotFoundHttpException
146147
*/
@@ -149,6 +150,23 @@ public function createNotFoundException($message = 'Not Found', \Exception $prev
149150
return new NotFoundHttpException($message, $previous);
150151
}
151152

153+
/**
154+
* Returns an AccessDeniedException.
155+
*
156+
* This will result in a 403 response code. Usage example:
157+
*
158+
* throw $this->createAccessDeniedException('Unable to access this page!');
159+
*
160+
* @param string $message A message
161+
* @param \Exception|null $previous The previous exception
162+
*
163+
* @return AccessDeniedException
164+
*/
165+
public function createAccessDeniedException($message = 'Access Denied', \Exception $previous = null)
166+
{
167+
return new AccessDeniedException($message, $previous);
168+
}
169+
152170
/**
153171
* Creates and returns a Form instance from the type of the form.
154172
*

0 commit comments

Comments
 (0)
0