Divide message key further
Currently, the key of the message is probably mainly used for the corresponding category "warning, info, danger, success". However, if you now have two forms in the page, the evaluation of this information and the output is a bit tricky. It would be nice if you can add the corresponding form name in addition to the key.
currently:
$flashMessages->flash('danger', 'You need to supply your email address');
suggestion:
$flashMessages->flash('danger', 'You need to supply your email address', 'form-name'); // OR
$flashMessages->flash('form-name:danger', 'You need to supply your email address');
$flashMessages->getFlashByForm('form-name');
What do you all mean?
I have been thinking about this as well and currently use it something like $flashMessages->flash('form-name:danger', 'message');.
$flashMessages->getFlashByForm('form-name');
I wouldn't call it getFlashByForm. I rather would like to see something like getFlashByNamespace. It does the same but it's more general.
$flashMessages->flash('danger', 'You need to supply your email address', 'form-name');
This cannot happen without a BC break. The current signature is public function flash(string $key, $value, int $hops = 1) : void;. So you would have something like public function flash(string $key, $value, int $hops = 1, string $namespace = null) : void;.
However I think I rather see something like this:
public function flash(string $namespace, $value, int $hops = 1, array options = null) : void;,
where options can be anything. You can add your message level (error, danger, success), form name, field name or whatever you want. To make it even more powerful, a namespace could have multiple messages.
public function getMessagesForNamespace(string $namespace) : array;
This repository has been closed and moved to mezzio/mezzio-flash; a new issue has been opened at https://github.com/mezzio/mezzio-flash/issues/1.