-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Proposing Flex-specific error messages in the controller shortcuts #25133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,7 +153,7 @@ protected function file($file, string $fileName = null, string $disposition = Re | |
protected function addFlash(string $type, string $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); | ||
|
@@ -169,7 +169,7 @@ protected function addFlash(string $type, string $message) | |
protected function isGranted($attributes, $subject = null): bool | ||
{ | ||
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); | ||
|
@@ -206,7 +206,7 @@ protected function renderView(string $view, array $parameters = array()): string | |
} | ||
|
||
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); | ||
|
@@ -224,7 +224,7 @@ protected function render(string $view, array $parameters = array(), Response $r | |
} 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) { | ||
|
@@ -256,7 +256,7 @@ protected function stream(string $view, array $parameters = array(), StreamedRes | |
$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) { | ||
|
@@ -326,7 +326,7 @@ protected function createFormBuilder($data = null, array $options = array()): Fo | |
protected function getDoctrine(): ManagerRegistry | ||
{ | ||
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'); | ||
|
@@ -346,7 +346,7 @@ protected function getDoctrine(): ManagerRegistry | |
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()) { | ||
|
@@ -372,7 +372,7 @@ protected function getUser() | |
protected function isCsrfTokenValid(string $id, string $token): bool | ||
{ | ||
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"'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
always be specific/generic? |
||
} | ||
|
||
return $this->container->get('security.csrf.token_manager')->isTokenValid(new CsrfToken($id, $token)); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flex should be auto-enabling it when requiring the
security-csrf
package, no ? If yes, the right advice is to require it tooThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems logical to me, bit I actually don't think it's enabled by default. It looks like it's always disabled unless you explicitly enable it: https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php#L107-L116
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😢 why making FrameworkBundle auto-enable all components except one ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like something we need to fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anybody willing to submit a PR on that one? Would be cool to have it for 3.4/4.0 before final.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fapbot here you go: #25151