Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 (over 5 years ago)
- Default Branch: 1.x.x
- Last Pushed: 2021-11-20T09:08:51.000Z (about 3 years ago)
- Last Synced: 2024-05-21T07:10:36.258Z (8 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
[![link-packagist](https://img.shields.io/packagist/v/antidot-fw/session.svg?style=flat-square)](https://packagist.org/packages/antidot-fw/session)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/antidot-framework/session-middleware/badges/quality-score.png?b=1.x.x)](https://scrutinizer-ci.com/g/antidot-framework/session-middleware/?branch=1.x.x)
[![Infection MSI](https://badge.stryker-mutator.io/github.com/antidot-framework/session-middleware/1.x.x)](https://infection.github.io)
[![Code Coverage](https://scrutinizer-ci.com/g/antidot-framework/session-middleware/badges/coverage.png?b=1.x.x)](https://scrutinizer-ci.com/g/antidot-framework/session-middleware/?branch=1.x.x)
[![type-coverage](https://shepherd.dev/github/antidot-framework/react-framework/coverage.svg)](https://shepherd.dev/github/antidot-framework/react-framework)
[![Build Status](https://scrutinizer-ci.com/g/antidot-framework/session-middleware/badges/build.png?b=1.x.x)](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