https://github.com/antidot-framework/session-middleware
Antidot Framework session library
https://github.com/antidot-framework/session-middleware
antidot-framework psr-11 psr-15
Last synced: about 2 months ago
JSON representation
Antidot Framework session library
- Host: GitHub
- URL: https://github.com/antidot-framework/session-middleware
- Owner: antidot-framework
- License: bsd-2-clause
- Created: 2019-04-17T18:42:56.000Z (about 6 years ago)
- Default Branch: 1.x.x
- Last Pushed: 2021-11-20T09:08:51.000Z (over 3 years ago)
- Last Synced: 2025-01-06T07:23:22.417Z (4 months ago)
- Topics: antidot-framework, psr-11, psr-15
- Language: PHP
- Homepage: https://antidotfw.io/
- Size: 24.4 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Antidot Session Middleware
[](https://packagist.org/packages/antidot-fw/session)
[](https://scrutinizer-ci.com/g/antidot-framework/session-middleware/?branch=1.x.x)
[](https://infection.github.io)
[](https://scrutinizer-ci.com/g/antidot-framework/session-middleware/?branch=1.x.x)
[](https://shepherd.dev/github/antidot-framework/react-framework)
[](https://scrutinizer-ci.com/g/antidot-framework/session-middleware/build-status/1.x.x)PSR-15 middleware that allows having session inside the request attributes.
## Install
Install using composer, by default it uses an implementation of [Aura Session](https://github.com/auraphp/Aura.Session).
```bash
composer require antidot-fw/session
```## Config
Using [Antidot Framework Starter](), it will work after adding the middleware to the pipeline. Also, you can use it in any
PSR-15 compatible middleware pipeline using PSR-11 container.```php
pipe(...);
$app->pipe(SessionMiddleware::class); // added here
$app->pipe(RouteDispatcherMiddleware::class);
...
};```
## Usage
The session will be stored as request attribute, For example using a Request handler, and it will be available in middleware
loaded after it too.```php
getAttribute('session');$session->set('foo', 'bar');
$session->set('baz', 'dib');
$message = $session->get('foo'); // 'bar'
$message = $session->get('baz'); // 'dib'
$session->setFlash('message', 'Hello world!');
$message = $session->getFlash('message'); // 'Hello world!'
...
}
}
```## Adding custom session implementation
To create a wrapper for your own custom session, you need to implement both `Antidot\Session\Application\Http\SessionSegment`
and `Antidot\Session\Application\Http\SessionSegmentFactory` clases, take a look to the
`Antidot\Session\Infrastructure\AuraSessionSegment` and `Antidot\Session\Infrastructure\AuraSessionSegmentFactory`.```php