DotKernel session component extending and customizing laminas-session
Run the following command in your project folder
composer require dotkernel/dot-session
Register SessionMiddleware
in your application's pipeline by adding the following line to config/pipeline.php
:
$app->pipe(Dot\Session\SessionMiddleware::class);
Register dot-session
's ConfigProvider in your application's configurations by adding the following line to config/config.php
:
\Dot\Session\ConfigProvider::class,
Basic usage to access and use the session object in your services:
class ExampleFactory
{
// code
public function __invoke(ContainerInterface $container)
{
return new ExampleService(
$container->get(SessionManager::class)
)
}
}
Register the factory in any mode you register factories on your project.
class ExampleService
{
private SessionManager $session;
public function __construct(SessionManager $session)
{
$this->session = $session;
}
//your methods
}
If you use annotated injection you can inject the Session Manager in your services.
use Dot\AnnotatedServices\Annotation\Inject;
use Laminas\Session\SessionManager;
class ExampleService
{
private SessionManager $session;
/**
* @Inject({SessionManager::class})
*/
public function __construct(SessionManager $session)
{
$this->session = $session;
}
//your methods
}