Session library with flash message support for Slim 4

I have tried to test it a little bit.

I added the middleware as follows:

$app->add(new \Neoflow\Session\Middleware\SessionMiddleware([
    'name' => 'app',
]));

Container

I got this error message:

Error: Entry “Neoflow\Session\Session” cannot be resolved: Entry “Neoflow\Session\FlashInterface” cannot be resolved:

So I added this into my config/container.php file and the error was gone:

use Neoflow\Session\Flash;
use Neoflow\Session\FlashInterface;
use Neoflow\Session\Session;
use Neoflow\Session\SessionInterface;

// ...
return [

	// ...
	
    SessionInterface::class => function (ContainerInterface $container) {
        return new Session($container->get(FlashInterface::class));
    },

    FlashInterface::class => function (ContainerInterface $container) {
        return new Flash();
    },
	
}

Twig

Twig integration doesn’t work in combination with a Twig container definition
because it requires a running session. Which should not the case when defining container
definitions.

$flash = $container->get(SessionInterface::class)->flash();
$twig->getEnvironment()->addGlobal('flash', $flash);

Fatal error: Uncaught Neoflow\Session\Exception\SessionException: Session not started yet.
in neoflow\session\src\Flash.php on line 25

Login test

For my login I have to clear all flash messages, but I could not find a clear method.

$flash->clear(); // Not working

The method names with *New() where a little confusing to me.

$flash->setNew('success', __('Login successfully'));

What I really miss is a method to start the session. To implement a secure login someone has to clear all session data and regenerate the session ID. The old session must be destroyed and started again. I would add a method start() to the session class (and interface). The SessionMiddleware could also use the start method to start the session.