Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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