PHPackages                             davidecesarano/embryo-middleware - 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-middleware

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

davidecesarano/embryo-middleware
================================

A PSR-15 middleware dispatcher.

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

Since Nov 14Pushed 5y ago1 watchersCompare

[ Source](https://github.com/davidecesarano/Embryo-Middleware)[ Packagist](https://packagist.org/packages/davidecesarano/embryo-middleware)[ Docs](https://github.com/davidecesarano/embryo-middleware)[ RSS](/packages/davidecesarano-embryo-middleware/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (5)

Embryo Middleware
=================

[](#embryo-middleware)

Simple dispatcher ([PSR-15](https://www.php-fig.org/psr/psr-15/) server request handler) for a queue of PSR-15 middleware entries. Request handlers and middleware components are a fundamental part of any web application. Server side code receives a request message, processes it, and produces a response message. HTTP middleware is a way to move common request and response processing away from the application layer.

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))

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

[](#installation)

Using Composer:

```
$ composer require davidecesarano/embryo-middleware

```

Usage
-----

[](#usage)

The RequestHandler is a container for a queue of PSR-15 middleware. It takes three methods:

- the method `add` add a middleware to the end of the queue.
- the method `prepend` add a middleware to the beginning of the queue.
- the method `dispatch` requires two arguments, a `ServerRequest` object and a `Response` object (used by terminator to return an empty response).

### Set ServerRequest and Response

[](#set-serverrequest-and-response)

Create `ServerRequest` and `Response` objects.

```
use Embryo\Http\Server\RequestHandler;
use Embryo\Http\Factory\{ServerRequestFactory, ResponseFactory};
use Middlewares\{Uuid, ResponseTime};
use Psr\Http\Message\ServerRequestInterface;

// PSR-7 implementation
$request = (new ServerRequestFactory)->createServerRequestFromServer();
$response = (new ResponseFactory)->createResponse(200);
```

### Add middleware

[](#add-middleware)

Create a queue of PSR-15 middleware with the `add` method or `constructor`. The add (and prepend) method must be a string or a instance of MiddlewareInterface. In constructor you may create a queue with array of string or instance of MiddlewareInterface.

In this example we use two PSR-15 compatible middleware: [Uuid Middleware](https://github.com/middlewares/uuid) and [ResponseTime Middleware](https://github.com/middlewares/response-time).

```
// PSR-15 MiddlewareInterface implementation
$middleware = new RequestHandler([
    Uuid::class,
    ResponseTime::class
]);
$response = $middleware->dispatch($request, $response);
```

### Result

[](#result)

The dispatch produces a response messages.

```
echo 'X-Response-Time: ' . $response->getHeaderLine('X-Response-Time').'';
echo 'X-Uuid: ' . $response->getHeaderLine('X-Uuid').'';

echo '';
    print_r($response->getHeaders());
echo '';
```

### Example

[](#example)

You may quickly test this using the built-in PHP server going to .

```
$ cd example
$ php -S localhost:8000

```

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity49

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

2054d 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 (34 commits)")

---

Tags

middlewaremiddleware-dispatchersphppsr-15request-handlermiddlewarepsr-15

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[mezzio/mezzio

PSR-15 Middleware Microframework

3913.8M120](/packages/mezzio-mezzio)[relay/relay

A PSR-15 server request handler.

3302.2M95](/packages/relay-relay)[laminas/laminas-stratigility

PSR-7 middleware foundation for building and dispatching middleware pipelines

577.0M95](/packages/laminas-laminas-stratigility)[php-middleware/php-debug-bar

PHP Debug Bar PSR-15 middleware with PSR-7

77474.5k2](/packages/php-middleware-php-debug-bar)[sunrise/http-router

A powerful solution as the foundation of your project.

17450.9k10](/packages/sunrise-http-router)[laminas/laminas-mvc-middleware

Dispatch middleware pipelines in place of controllers in laminas-mvc.

22715.7k10](/packages/laminas-laminas-mvc-middleware)

PHPackages © 2026

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