odan / session

A middleware oriented session handler for PHP and Slim 4+
https://odan.github.io/session/
MIT License
56 stars 11 forks source link

Version 5 - Roadmap #7

Closed odan closed 4 years ago

odan commented 4 years ago

Here are some initial ideas:

Breaking Changes

New Features

Please add additional thoughts below.

jnessier commented 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?

odan commented 4 years ago

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?

jnessier commented 4 years ago

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.

jnessier commented 4 years ago

But to be honest, I would skip the flash messages and keep focused on the session library itself.

darkalchemy commented 4 years ago

@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

jnessier commented 4 years ago

Congratulations! I really like the simpleness of the flash support.

odan commented 4 years ago

Thanks to all for the feedback.