Skip to content

Commit 0ca32aa

Browse files
committed
minor #25133 Proposing Flex-specific error messages in the controller shortcuts (weaverryan)
This PR was merged into the 4.1-dev branch. Discussion ---------- Proposing Flex-specific error messages in the controller shortcuts | Q | A | ------------- | --- | Branch? | 4.0 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | none | License | MIT | Doc PR | not needed This is to help discoverability when you try to use a feature that's not installed. It's opinionated about Flex being installed, which is why this is done on 4.0. Two of the options relate to configuration. An alternative (if we don't like the short description) is to include a link instead (which could be some short URL - e.g. `http://symfony.com/docs/sessions` would be pretty cool). Commits ------- d377b1545b Proposing Flex-specific error messages in the controller shortcuts
2 parents eea7d14 + e1357b0 commit 0ca32aa

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Controller/ControllerTrait.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ protected function file($file, string $fileName = null, string $disposition = Re
153153
protected function addFlash(string $type, string $message)
154154
{
155155
if (!$this->container->has('session')) {
156-
throw new \LogicException('You can not use the addFlash method if sessions are disabled.');
156+
throw new \LogicException('You can not use the addFlash method if sessions are disabled. Enable them in config/packages/framework.yaml.');
157157
}
158158

159159
$this->container->get('session')->getFlashBag()->add($type, $message);
@@ -169,7 +169,7 @@ protected function addFlash(string $type, string $message)
169169
protected function isGranted($attributes, $subject = null): bool
170170
{
171171
if (!$this->container->has('security.authorization_checker')) {
172-
throw new \LogicException('The SecurityBundle is not registered in your application.');
172+
throw new \LogicException('The SecurityBundle is not registered in your application. Try running "composer require security"');
173173
}
174174

175175
return $this->container->get('security.authorization_checker')->isGranted($attributes, $subject);
@@ -206,7 +206,7 @@ protected function renderView(string $view, array $parameters = array()): string
206206
}
207207

208208
if (!$this->container->has('twig')) {
209-
throw new \LogicException('You can not use the "renderView" method if the Templating Component or the Twig Bundle are not available.');
209+
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"');
210210
}
211211

212212
return $this->container->get('twig')->render($view, $parameters);
@@ -224,7 +224,7 @@ protected function render(string $view, array $parameters = array(), Response $r
224224
} elseif ($this->container->has('twig')) {
225225
$content = $this->container->get('twig')->render($view, $parameters);
226226
} else {
227-
throw new \LogicException('You can not use the "render" method if the Templating Component or the Twig Bundle are not available.');
227+
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"');
228228
}
229229

230230
if (null === $response) {
@@ -256,7 +256,7 @@ protected function stream(string $view, array $parameters = array(), StreamedRes
256256
$twig->display($view, $parameters);
257257
};
258258
} else {
259-
throw new \LogicException('You can not use the "stream" method if the Templating Component or the Twig Bundle are not available.');
259+
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"');
260260
}
261261

262262
if (null === $response) {
@@ -326,7 +326,7 @@ protected function createFormBuilder($data = null, array $options = array()): Fo
326326
protected function getDoctrine(): ManagerRegistry
327327
{
328328
if (!$this->container->has('doctrine')) {
329-
throw new \LogicException('The DoctrineBundle is not registered in your application.');
329+
throw new \LogicException('The DoctrineBundle is not registered in your application. Try running "composer require doctrine"');
330330
}
331331

332332
return $this->container->get('doctrine');
@@ -346,7 +346,7 @@ protected function getDoctrine(): ManagerRegistry
346346
protected function getUser()
347347
{
348348
if (!$this->container->has('security.token_storage')) {
349-
throw new \LogicException('The SecurityBundle is not registered in your application.');
349+
throw new \LogicException('The SecurityBundle is not registered in your application. Try running "composer require security"');
350350
}
351351

352352
if (null === $token = $this->container->get('security.token_storage')->getToken()) {
@@ -372,7 +372,7 @@ protected function getUser()
372372
protected function isCsrfTokenValid(string $id, string $token): bool
373373
{
374374
if (!$this->container->has('security.csrf.token_manager')) {
375-
throw new \LogicException('CSRF protection is not enabled in your application.');
375+
throw new \LogicException('CSRF protection is not enabled in your application. Enable it with the "csrf_protection" key in "config/packages/framework.yaml"');
376376
}
377377

378378
return $this->container->get('security.csrf.token_manager')->isTokenValid(new CsrfToken($id, $token));

0 commit comments

Comments
 (0)