laminas / laminas-mvc-plugin-flashmessenger

Plugin for creating and exposing flash messages via laminas-mvc controllers
https://docs.laminas.dev/laminas-mvc-plugin-flashmessenger/
BSD 3-Clause "New" or "Revised" License
10 stars 17 forks source link

hops are not applied to correct namespace #2

Open weierophinney opened 4 years ago

weierophinney commented 4 years ago
$flashMessenger->addMessage('success display few times.', FlashMessenger::NAMESPACE_SUCCESS, 1);
$flashMessenger->addMessage('warning persist', FlashMessenger::NAMESPACE_WARNING, 100);

Last specified hop value is applied to all namespaces. Here, success message will be shown as many times as warnings. And if success is defined after warning, user will not be bugged with messages enough times. Need to apply hops to namespaces correctly.


Originally posted by @alextech at https://github.com/zendframework/zend-mvc-plugin-flashmessenger/issues/13

ghost commented 3 years ago

Any progress on that 'hops'-parameter? Or is it still useless?

froschdesign commented 3 years ago

@maatcode1 Any help with this problem is welcome!

reinfi commented 2 years ago

I tried to fix this problem but I think with the current implementation this can not be fixed.

https://github.com/laminas/laminas-mvc-plugin-flashmessenger/blob/1.9.x/src/FlashMessenger.php#L659

This line always removes the namespace from the container, so there will be no namespace on any next hop.

Of course the expiration hops will always only work for the namespace, not for the given message, because this would need to have own expiration meta data for every single message.

Also I am a bit unsure why the expiration hops are only set if there are no messages added.

https://github.com/laminas/laminas-mvc-plugin-flashmessenger/blob/1.9.x/src/FlashMessenger.php#L167

In my opinion this should be set every time.

$container->setExpirationHops($hops, $namespace);

This would expire a namespace after the amount of hops which in our case means the x times the messages got read from the container.

I could try to improve this but may be we should remove the hops flag because it is not working and it would not work for a single message.