PHPackages                             woohoolabs/yin-middlewares - 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. woohoolabs/yin-middlewares

Abandoned → [woohoolabs/yin-middleware](/?search=woohoolabs%2Fyin-middleware)Library[HTTP &amp; Networking](/categories/http)

woohoolabs/yin-middlewares
==========================

Woohoo Labs. Yin Middleware

4.2.1(5y ago)141423[1 PRs](https://github.com/woohoolabs/yin-middleware/pulls)MITPHPPHP ^7.4.0||^8.0.0

Since Aug 17Pushed 3y ago1 watchersCompare

[ Source](https://github.com/woohoolabs/yin-middleware)[ Packagist](https://packagist.org/packages/woohoolabs/yin-middlewares)[ RSS](/packages/woohoolabs-yin-middlewares/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (14)Versions (25)Used By (0)

Woohoo Labs. Yin Middleware
===========================

[](#woohoo-labs-yin-middleware)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ace6bd71b3152335340d85b70ea3e3c1c8e9a2858574c15849173afc0f2a90ce/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f776f6f686f6f6c6162732f79696e2d6d6964646c65776172652e737667)](https://packagist.org/packages/woohoolabs/yin-middleware)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Build Status](https://camo.githubusercontent.com/fa2f1bde485dc797a4d221a6bc691e6e48f5d04fbb6129d1eebad636c845c69d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f776f6f686f6f6c6162732f79696e2d6d6964646c65776172652f436f6e74696e756f7573253230496e746567726174696f6e)](https://github.com/woohoolabs/yin-middleware/actions)[![Coverage Status](https://camo.githubusercontent.com/f24d7564e20ad0e4d6a6ed9405a803467b045275238e0c631edf323d222020f9/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f776f6f686f6f6c6162732f79696e2d6d6964646c6577617265)](https://codecov.io/gh/woohoolabs/yin-middleware)[![Quality Score](https://camo.githubusercontent.com/f96f57f18838b00a143045d6fca2d5864897d88cac2cc29a3d98d5a9c02a4d8b/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f776f6f686f6f6c6162732f79696e2d6d6964646c65776172652e737667)](https://scrutinizer-ci.com/g/woohoolabs/yin-middleware)[![Total Downloads](https://camo.githubusercontent.com/5edc0e1f9913ae1ccdd39ef8e4a9e439f4f4099a42f41411c4b503cba776ea7f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f776f6f686f6f6c6162732f79696e2d6d6964646c65776172652e737667)](https://packagist.org/packages/woohoolabs/yin-middleware)[![Gitter](https://camo.githubusercontent.com/a31c4395544a20c6a79ad9a7673f0db750345ee993c2d201061d9eebe8145146/68747470733a2f2f6261646765732e6769747465722e696d2f776f6f686f6f6c6162732f79696e2d6d6964646c65776172652e737667)](https://gitter.im/woohoolabs/yin-middleware?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

**Woohoo Labs. Yin Middleware is a collection of middleware which helps you to integrate [Woohoo Labs. Yin](https://github.com/woohoolabs/yin) into your PHP applications.**

Table of Contents
-----------------

[](#table-of-contents)

- [Introduction](#introduction)
- [Install](#install)
- [Basic Usage](#basic-usage)
- [Versioning](#versioning)
- [Change Log](#change-log)
- [Testing](#testing)
- [Contributing](#contributing)
- [Support](#support)
- [Credits](#credits)
- [License](#license)

Introduction
------------

[](#introduction)

### Features

[](#features)

- 100% [PSR-15](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-15-request-handlers.md) compatibility
- 100% [PSR-7](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md) compatibility
- Validation of requests against the JSON schema
- Validation of responses against the JSON and JSON:API schema
- Dispatching of JSON:API-aware controllers
- JSON:API exception handling

Install
-------

[](#install)

The only thing you need before getting started is [Composer](https://getcomposer.org).

### Install a PSR-7 implementation:

[](#install-a-psr-7-implementation)

Because Yin Middleware requires a PSR-7 implementation (a package which provides the `psr/http-message-implementation` virtual package), you must install one first. You may use [Zend Diactoros](https://github.com/zendframework/zend-diactoros) or any other library of your preference:

```
$ composer require zendframework/zend-diactoros
```

### Install Yin Middleware:

[](#install-yin-middleware)

To install the latest version of this library, run the command below:

```
$ composer require woohoolabs/yin-middleware
```

> Note: The tests and examples won't be downloaded by default. You have to use `composer require woohoolabs/yin-middleware --prefer-source`or clone the repository if you need them.

Yin Middleware 4.1 requires PHP 7.4 at least, but you may use Yin Middleware 4.0.0 for PHP 7.1.

### Install the optional dependencies:

[](#install-the-optional-dependencies)

If you want to use `JsonApiRequestValidatorMiddleware` and `JsonApiResponseValidatorMiddleware` from the default middleware stack then you have to require the following dependencies too:

```
$ composer require seld/jsonlint
$ composer require justinrainbow/json-schema
```

Basic Usage
-----------

[](#basic-usage)

### Supported middleware interface design

[](#supported-middleware-interface-design)

The interface design of Yin-Middleware is based on the [PSR-15](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-15-request-handlers.md) de-facto standard. That's why it is compatible with [Woohoo Labs. Harmony](https://github.com/woohoolabs/harmony), [Zend-Stratigility](https://github.com/zendframework/zend-stratigility/), [Zend-Expressive](https://github.com/zendframework/zend-expressive/)and many other frameworks.

The following sections will guide you through how to use and configure the provided middleware.

> Note: When passing a `ServerRequestInterface` instance to your middleware dispatcher, a `WoohooLabs\Yin\JsonApi\Request\JsonApiRequestInterface` instance must be used in fact (the `WoohooLabs\Yin\JsonApi\Request\JsonApiRequest`class possibly), otherwise the `JsonApiDispatcherMiddleware` and the `JsonApiExceptionHandlerMiddleware` will throw an exception.

### YinCompatibilityMiddleware

[](#yincompatibilitymiddleware)

This middleware facilitates the usage of Yin and Yin-Middleware in other frameworks. It does so by upgrading a basic PSR-7 request object to `JsonApiRequest`, which is suitable for working with Yin. Please keep in mind, that this middleware should precede any other middleware that uses `JsonApiRequest` as `$request` parameter.

```
$harmony->addMiddleware(new YinCompatibilityMiddleware());
```

Available configuration options for the middleware (they can be passed to the constructor):

- `exceptionFactory`: The [ExceptionFactoryInterface](https://github.com/woohoolabs/yin/#exceptions) instance to be used
- `deserializer`: The [DeserializerInterface](https://github.com/woohoolabs/yin/#custom-deserialization) instance to be used

### JsonApiRequestValidatorMiddleware

[](#jsonapirequestvalidatormiddleware)

The middleware is mainly useful in a development environment, and it is able to validate a PSR-7 request against the JSON and the JSON:API schema. Just add it to your application (the example is for [Woohoo Labs. Harmony](https://github.com/woohoolabs/harmony)):

```
$harmony->addMiddleware(new JsonApiRequestValidatorMiddleware());
```

If validation fails, an exception containing the appropriate JSON:API errors will be thrown. If you want to customize the error messages or the response, provide an Exception Factory of your own. For other customizations, feel free to extend the class.

Available configuration options for the middleware (they can be passed to the constructor):

- `exceptionFactory`: The [ExceptionFactoryInterface](https://github.com/woohoolabs/yin/#exceptions) instance to be used
- `includeOriginalMessageInResponse`: If true, the original request body will be included in the "meta" top-level member
- `negotiate`: If true, the middleware performs content-negotiation as specified by the JSON:API spec. In this case, the "Content-Type" and the "Accept" header is checked.
- `validateQueryParams`: If true, query parameters are validated against the JSON:API specification
- `validateJsonBody`: If true, the request body gets validated against the JSON schema

### JsonApiResponseValidatorMiddleware

[](#jsonapiresponsevalidatormiddleware)

The middleware is mainly useful in a development environment, and it is able to validate a PSR-7 response against the JSON and the JSON:API schema. Just add it to your application (the example is for [Woohoo Labs. Harmony](https://github.com/woohoolabs/harmony)):

```
$harmony->addMiddleware(new JsonApiResponseValidatorMiddleware());
```

If validation fails, an exception containing the appropriate JSON:API errors will be thrown. If you want to customize the error messages or the response, provide an Exception Factory of your own. For other customizations, feel free to extend the class.

Available configuration options for the middleware (they can be passed to the constructor):

- `exceptionFactory`: The [ExceptionFactoryInterface](https://github.com/woohoolabs/yin/#exceptions) instance to be used
- `serializer`: The [SerializerInterface](https://github.com/woohoolabs/yin/#custom-serialization) instance to be used
- `includeOriginalMessageInResponse`: If true, the original response will be included in the "meta" top-level member
- `validateJsonBody`: If true, the response body gets validated against the JSON schema
- `validateJsonApiBody`: If true, the response is validated against the JSON:API schema

### JsonApiDispatcherMiddleware

[](#jsonapidispatchermiddleware)

This middleware is able to dispatch JSON:API-aware controllers. Just add it to your application (the example is for [Woohoo Labs. Harmony](https://github.com/woohoolabs/harmony)):

```
$harmony->addMiddleware(new JsonApiDispatcherMiddleware());
```

This middleware works exactly as [the one in Woohoo Labs. Harmony](https://github.com/woohoolabs/harmony#using-your-favourite-di-container-with-harmony), the only difference is that it dispatches controller actions with the following signature:

```
public function myAction(JsonApi $jsonApi): ResponseInterface;
```

instead of:

```
public function myAction(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface;
```

The difference is subtle, as the `$jsonApi` object contains a PSR-7 compatible request, and PSR-7 responses can also be created with it. Learn more from the documentation of [Woohoo Labs. Yin](https://github.com/woohoolabs/yin#jsonapi-class).

Available configuration options for the middleware (they can be passed to the constructor):

- `container`: A [PSR-11 compliant](https://www.php-fig.org/psr/psr-11/) container instance to be used to instantiate the controller
- `exceptionFactory`: The [ExceptionFactoryInterface](https://github.com/woohoolabs/yin/#exceptions) instance to be used (e.g.: when dispatching fails)
- `serializer`: The [SerializerInterface](https://github.com/woohoolabs/yin/#custom-serialization) instance to be used
- `handlerAttribute`: The name of the request attribute which stores a dispatchable controller (it is usually provided by a router).

### JsonApiExceptionHandlerMiddleware

[](#jsonapiexceptionhandlermiddleware)

It catches exceptions and responds with an appropriate JSON:API error response.

Available configuration options for the middleware (they can be passed to the constructor):

- `errorResponsePrototype`: In case of an error, this response object will be manipulated and returned
- `catching`: If false, the middleware won't catch `JsonApiException`s
- `verbose`: If true, additional meta information will be provided about the exception thrown
- `exceptionFactory`: The [ExceptionFactoryInterface](https://github.com/woohoolabs/yin/#exceptions) instance to be used
- `serializer`: The [SerializerInterface](https://github.com/woohoolabs/yin/#custom-serialization) instance to be used

Versioning
----------

[](#versioning)

This library follows [SemVer v2.0.0](https://semver.org/).

Change Log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

Woohoo Labs. Yin Middleware has a PHPUnit test suite. To run the tests, run the following command from the project folder after you have copied phpunit.xml.dist to phpunit.xml:

```
$ phpunit
```

Additionally, you may run `docker-compose up` or `make test` in order to execute the tests.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Support
-------

[](#support)

Please see [SUPPORT](SUPPORT.md) for details.

Credits
-------

[](#credits)

- [Máté Kocsis](https://github.com/kocsismate)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see the [License File](LICENSE) for more information.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity78

Established project with proven stability

 Bus Factor1

Top contributor holds 99.6% 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

Every ~84 days

Recently: every ~107 days

Total

22

Last Release

2150d ago

Major Versions

0.8.0 → 1.0.02016-10-28

1.0.0 → 2.0.02017-03-12

2.2.0 → 3.0.02018-02-02

3.0.1 → 4.0.0-beta12018-12-21

PHP version history (8 changes)0.1.0PHP &gt;=5.5.0

0.5.0PHP ^5.5.0|^7.0.0

0.6.0PHP ^5.5.0||^7.0.0

1.0.0PHP ^5.6.0||^7.0.0

2.0.0PHP ^7.0.0

2.1.0PHP ^7.1.0

4.1.0PHP ^7.4.0

4.2.1PHP ^7.4.0||^8.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b84c2c00735d2c7408e53566b0a622d39998be610bc02856e1b887d40f7a8024?d=identicon)[woohoolabs](/maintainers/woohoolabs)

---

Top Contributors

[![kocsismate](https://avatars.githubusercontent.com/u/6057627?v=4)](https://github.com/kocsismate "kocsismate (247 commits)")[![jnamenyi](https://avatars.githubusercontent.com/u/56647220?v=4)](https://github.com/jnamenyi "jnamenyi (1 commits)")

---

Tags

json-apimiddlewarephppsr-11psr-15psr-7serverpsr-7middlewarepsr-15JSON-APIWoohoo Labs.Yin

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/woohoolabs-yin-middlewares/health.svg)

```
[![Health](https://phpackages.com/badges/woohoolabs-yin-middlewares/health.svg)](https://phpackages.com/packages/woohoolabs-yin-middlewares)
```

###  Alternatives

[woohoolabs/yin-middleware

Woohoo Labs. Yin Middleware

138.6k](/packages/woohoolabs-yin-middleware)[mezzio/mezzio

PSR-15 Middleware Microframework

3883.6M97](/packages/mezzio-mezzio)[woohoolabs/yin

Woohoo Labs. Yin

240437.1k8](/packages/woohoolabs-yin)[mezzio/mezzio-authentication

Authentication middleware for Mezzio and PSR-7 applications

121.6M26](/packages/mezzio-mezzio-authentication)[middlewares/utils

Common utils for PSR-15 middleware packages

503.4M92](/packages/middlewares-utils)[middlewares/request-handler

Middleware to execute request handlers

451.6M26](/packages/middlewares-request-handler)

PHPackages © 2026

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