dotkernel / dot-session
DotKernel session component extending and customizing laminas-session
Installs: 11 568
Dependents: 3
Suggesters: 0
Security: 0
Stars: 3
Watchers: 5
Forks: 1
Open Issues: 4
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0
- laminas/laminas-servicemanager: ^3.22.1
- laminas/laminas-session: ^2.21.0
- laminas/laminas-stdlib: ^3.18.0
- psr/http-message: ^1.0 || ^2.0
- psr/http-server-middleware: ^1.0.2
Requires (Dev)
- laminas/laminas-coding-standard: ^2.5.0
- phpunit/phpunit: ^10.4.2
- vimeo/psalm: ^5.16.0
README
Important
dot-session is a wrapper on top of laminas/laminas-session
DotKernel session component extending and customizing laminas-session
Installation
Run the following command in your project folder
composer require dotkernel/dot-session
Configuration
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,
Usage
Basic usage to access and use the session object in your services:
Method #1 - Factory
Step 1: Create a factory that retrieves the SessionManger from the container
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.
Step 2: Access through your Service
class ExampleService { private SessionManager $session; public function __construct(SessionManager $session) { $this->session = $session; } //your methods }
Method #2 - Injection
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 }