Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[HttpFoundation] Add SessionHasFlashMessage test constraint#60008
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:7.4
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
{ | ||
public function __construct( | ||
private readonly string $messageType, | ||
private readonly string $message, |
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.
A message can be of any type (technically)https://github.com/symfony/symfony/blob/7.3/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php#L31
For thematches()
part this should use the Constraint comparator.
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.
A message is a string. The methodset
allows an array of strings. This constraint constructor looks good to me.
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.
My bad, referenced the wrong method.https://github.com/symfony/symfony/blob/7.3/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBagInterface.php#L26
/** * Adds a flash message for the given type. */publicfunction add(string$type,mixed$message):void;
https://github.com/symfony/symfony/blob/7.3/src/Symfony/Component/HttpFoundation/Session/Flash/FlashBag.php#L83 (set()
method implementation).
Theset()
method allows to set multiple messages for a type, but the type of a$message
is mixed.
As it can also contain a Translatable object (Which I use in some projects), as long as there is a way to serialize the value, anything goes.
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.
Indeed, if a string is the common type for messages, nothing prevent from using anything else.
I foundthis thread where it is suggested to use aMarkup
object as message. Also, we can imagine that a Translatable
object is used as well.
@Pierstoval would you mind to relax the message type?
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.
Many thanks.
No specific remarks for this PR.
👍
{ | ||
public function __construct( | ||
private readonly string $messageType, | ||
private readonly string $message, |
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.
A message is a string. The methodset
allows an array of strings. This constraint constructor looks good to me.
Eases the checks on the Session, to avoid the user having to do the checks themselves.
Before:
After: