PHPackages                             davidecesarano/embryo-session - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. davidecesarano/embryo-session

ActiveLibrary[HTTP &amp; Networking](/categories/http)

davidecesarano/embryo-session
=============================

PSR-15 middleware to create a php session using the PSR-7 request.

1.0.0(5y ago)11351MITPHPPHP &gt;=7.1

Since Apr 28Pushed 5y ago2 watchersCompare

[ Source](https://github.com/davidecesarano/Embryo-Session)[ Packagist](https://packagist.org/packages/davidecesarano/embryo-session)[ Docs](https://github.com/davidecesarano/embryo-session)[ RSS](/packages/davidecesarano-embryo-session/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (1)

Embryo Session
==============

[](#embryo-session)

Middleware to start a php session using the request data and close it after return the response.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.1
- A [PSR-7](https://www.php-fig.org/psr/psr-7/) http message implementation and [PSR-17](https://www.php-fig.org/psr/psr-17/) http factory implementation (ex. [Embryo-Http](https://github.com/davidecesarano/Embryo-Http))
- A [PSR-15](https://www.php-fig.org/psr/psr-15/) http server request implementation (ex. [Embryo-Middleware](https://github.com/davidecesarano/embryo-middleware))

Installation
------------

[](#installation)

Using Composer:

```
$ composer require davidecesarano/embryo-session

```

Usage
-----

[](#usage)

Creates a middleware for setting session item:

```
class TestSetSessionMiddleware implements MiddlewareInterface
{
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $session = $request->getAttribute('session');
        $session->set('name', 'World');
        $response = $handler->handle($request);
        return $response->write('Hello '.$session->get('name').'Other Page');
    }
}
```

Creates another middleware for getting session item:

```
class TestGetSessionMiddleware implements MiddlewareInterface
{
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        $session = $request->getAttribute('session');
        $response = $handler->handle($request);
        return $response->write('Hello '.$session->get('name').'');
    }
}
```

Adds middleware to dispatcher:

```
$session = new Session;
$middleware = new RequestHandler;
$middleware->add(
    (new SessionMiddleware)
        ->setSession($session)
        ->setOptions([
            'use_cookies'      => false,
            'use_only_cookies' => true
        ])
);
$middleware->add(TestSetSessionMiddleware::class);
$middleware->add(TestGetSessionMiddleware::class);
$response = $middleware->dispatch($request, $response);
```

Options
-------

[](#options)

### `setName(string $name)`

[](#setnamestring-name)

The session name. If it's not provided, use the php's default.

### `seOptions(array $options = [])`

[](#seoptionsarray-options--)

Array of options passed to `session_start()`.

### `setSessionRequestAttribute(string $name)`

[](#setsessionrequestattributestring-name)

The session request attribute. If it's not provided, use `$request->getAttribute('session')`.

Collection
----------

[](#collection)

### Retrieving data

[](#retrieving-data)

You may retrieve an item from the session and you may also pass a default value as the second argument to the `get` method:

```
$session->get('key', 'default');
```

### Retrieving all session data

[](#retrieving-all-session-data)

If you would like to retrieve all the data in the session, you may use the `all` method:

```
$session->all();
```

### Determining if an item exists in the session

[](#determining-if-an-item-exists-in-the-session)

To determine if an item is present in the session, you may use the `has` method. The has method returns `true` if the item is present and is not `null`:

```
if ($session->has('key')) {
    //...
}
```

### Storing data

[](#storing-data)

The `set` method may be used to set a new value onto a session:

```
$session->set('name', 'value');
```

### Flash data

[](#flash-data)

You may wish to store items in the session only for the next request using the `flash` method:

```
$session->flash('name', 'value');
```

### Deleting data

[](#deleting-data)

The `remove` method will remove a piece of data from the session. If you would like the remove all data from the session, you may use the `clear` method:

```
$session->remove('name');
$session->clear();
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1837d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16277144?v=4)[Davide Cesarano](/maintainers/davidecesarano)[@davidecesarano](https://github.com/davidecesarano)

---

Top Contributors

[![davidecesarano](https://avatars.githubusercontent.com/u/16277144?v=4)](https://github.com/davidecesarano "davidecesarano (29 commits)")

---

Tags

phpphp-sessionspsr-15psr-7phppsr-15session

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/davidecesarano-embryo-session/health.svg)

```
[![Health](https://phpackages.com/badges/davidecesarano-embryo-session/health.svg)](https://phpackages.com/packages/davidecesarano-embryo-session)
```

###  Alternatives

[httpsoft/http-runner

Running PSR-7 components and building PSR-15 middleware pipelines

1455.0k5](/packages/httpsoft-http-runner)[httpsoft/http-basis

Simple and fast HTTP microframework implementing PSR standards

1334.9k1](/packages/httpsoft-http-basis)[divineniiquaye/flight-routing

Flight routing is a simple, fast PHP router that is easy to get integrated with other routers.

152.5k](/packages/divineniiquaye-flight-routing)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
