Closed odan closed 4 years ago
I learned a lot about separation of concerns in the last few days: https://java-design-patterns.com/principles/#separation-of-concerns
What you think about implementing Neoflow/FlashMessages or Slim/Flash, instead of creating a integrated flash messages support?
I have already played with the idea to sepearte the Flash component but also wanted to "keep it simple" at the same time. Most session implementations come with their built-in Flash functionality (see Symfony, Aura, etc.). On the other hand you should be able to use your own Flash component in combination with this component (see Readme).
The new readme contains a section how to integrate the slim/flash
component by sharing the same "storage" (ArrayObject). Slim/Flash also uses an internal ArrayAccess
interface as internal storage. So both components can work together without the need for a running session.
https://github.com/odan/session#slim-flash-integration
The downside of this concept is, that they don't share the same FlashInterface. There is also a new FlashInterface which could be implemented. But it's also important that both components a sharing or abstracting the same storage interface to make it interobable. Of course we could provide a Adapter for it. Maybe I add a proof of concept.
Do you have a good idea / concept how you can make it very easy to integrate other Flash components like yours?
I think a specific FlashInterface is the easiest way to go, by providing a constructor argument and/or a set method public function setFlash(FlashInterface $flash);
in session class.
Example with set method:
SessionInterface::class => function (ContainerInterface $container) {
$settings = $container->get('settings');
$flash = $container->get(FlashInterface::class);
$session = new PhpSession();
$session->setOptions((array)$settings['session']);
$session->setFlash($flash);
return $session;
},
Example with constructor argument:
SessionInterface::class => function (ContainerInterface $container) {
$settings = $container->get('settings');
$flash = $container->get(FlashInterface::class);
$session = new PhpSession($flash);
$session->setOptions((array)$settings['session']);
return $session;
},
I would prefer to provide both options. And if no custom flash got set, the session uses the default flash solution.
But to be honest, I would skip the flash messages and keep focused on the session library itself.
@odan While you are still building out these changes, could you add a couple of methods?
getFirst() and getLast()
These are easy enough to implement on my own, if you don't want to add them.
Thanks
Congratulations! I really like the simpleness of the flash support.
Thanks to all for the feedback.
Here are some initial ideas:
Breaking Changes
Move all interface into its own namespace::no_entry:Odan\Session\Interfaces
SessionDoublePassMiddleware
:heavy_check_mark:Rename class:no_entry:PhpSession
toSession
Remove:no_entry:MemorySession
classSessionMiddleware
into its own namespace:Odan\Session\Middleware
:heavy_check_mark:Add a native PHP session cookie handler, e.g.:no_entry:Odan\Session\Cookie
Remove:no_entry:setCookieParams
andgetCookieParams
Move this library to selective/session:no_entry:New Features
Add support for dot notation using selective/array-reader:no_entry:SessionException
instead of returning false for errors :heavy_check_mark:Please add additional thoughts below.