minor #25636 Backport Flex-specific error messages in controller shortcuts to 3.4 (weaverryan)

This PR was merged into the 3.4 branch.

Discussion
----------

Backport Flex-specific error messages in controller shortcuts to 3.4

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | https://github.com/symfony/symfony/pull/25133#issuecomment-354551079
| License       | MIT
| Doc PR        | n/a

Commits
-------

419e93465f Proposing Flex-specific error messages in the controller shortcuts
This commit is contained in:
Fabien Potencier 2018-01-03 18:28:45 +01:00
commit abfa3eeca5

View File

@ -194,7 +194,7 @@ trait ControllerTrait
protected function addFlash($type, $message)
{
if (!$this->container->has('session')) {
throw new \LogicException('You can not use the addFlash method if sessions are disabled.');
throw new \LogicException('You can not use the addFlash method if sessions are disabled. Enable them in "config/packages/framework.yaml".');
}
$this->container->get('session')->getFlashBag()->add($type, $message);
@ -215,7 +215,7 @@ trait ControllerTrait
protected function isGranted($attributes, $subject = null)
{
if (!$this->container->has('security.authorization_checker')) {
throw new \LogicException('The SecurityBundle is not registered in your application.');
throw new \LogicException('The SecurityBundle is not registered in your application. Try running "composer require security".');
}
return $this->container->get('security.authorization_checker')->isGranted($attributes, $subject);
@ -261,7 +261,7 @@ trait ControllerTrait
}
if (!$this->container->has('twig')) {
throw new \LogicException('You can not use the "renderView" method if the Templating Component or the Twig Bundle are not available.');
throw new \LogicException('You can not use the "renderView" method if the Templating Component or the Twig Bundle are not available. Try running "composer require twig".');
}
return $this->container->get('twig')->render($view, $parameters);
@ -285,7 +285,7 @@ trait ControllerTrait
} elseif ($this->container->has('twig')) {
$content = $this->container->get('twig')->render($view, $parameters);
} else {
throw new \LogicException('You can not use the "render" method if the Templating Component or the Twig Bundle are not available.');
throw new \LogicException('You can not use the "render" method if the Templating Component or the Twig Bundle are not available. Try running "composer require twig".');
}
if (null === $response) {
@ -323,7 +323,7 @@ trait ControllerTrait
$twig->display($view, $parameters);
};
} else {
throw new \LogicException('You can not use the "stream" method if the Templating Component or the Twig Bundle are not available.');
throw new \LogicException('You can not use the "stream" method if the Templating Component or the Twig Bundle are not available. Try running "composer require twig".');
}
if (null === $response) {
@ -373,7 +373,7 @@ trait ControllerTrait
protected function createAccessDeniedException($message = 'Access Denied.', \Exception $previous = null)
{
if (!class_exists(AccessDeniedException::class)) {
throw new \LogicException('You can not use the "createAccessDeniedException" method if the Security component is not available.');
throw new \LogicException('You can not use the "createAccessDeniedException" method if the Security component is not available. Try running "composer require security".');
}
return new AccessDeniedException($message, $previous);
@ -422,7 +422,7 @@ trait ControllerTrait
protected function getDoctrine()
{
if (!$this->container->has('doctrine')) {
throw new \LogicException('The DoctrineBundle is not registered in your application.');
throw new \LogicException('The DoctrineBundle is not registered in your application. Try running "composer require doctrine".');
}
return $this->container->get('doctrine');
@ -442,7 +442,7 @@ trait ControllerTrait
protected function getUser()
{
if (!$this->container->has('security.token_storage')) {
throw new \LogicException('The SecurityBundle is not registered in your application.');
throw new \LogicException('The SecurityBundle is not registered in your application. Try running "composer require security".');
}
if (null === $token = $this->container->get('security.token_storage')->getToken()) {
@ -470,7 +470,7 @@ trait ControllerTrait
protected function isCsrfTokenValid($id, $token)
{
if (!$this->container->has('security.csrf.token_manager')) {
throw new \LogicException('CSRF protection is not enabled in your application.');
throw new \LogicException('CSRF protection is not enabled in your application. Enable it with the "csrf_protection" key in "config/packages/framework.yaml".');
}
return $this->container->get('security.csrf.token_manager')->isTokenValid(new CsrfToken($id, $token));