PHPackages                             chimera/mapping - 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. chimera/mapping

ActiveLibrary

chimera/mapping
===============

Useful annotations to configure the application layer of your software

0.4.0(5y ago)4124.9k↓38.2%1[10 PRs](https://github.com/chimeraphp/mapping/pulls)1MITPHPPHP ^7.4 || ^8.0

Since May 6Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/chimeraphp/mapping)[ Packagist](https://packagist.org/packages/chimera/mapping)[ GitHub Sponsors](https://github.com/lcobucci)[ Patreon](https://www.patreon.com/lcobucci)[ RSS](/packages/chimera-mapping/feed)WikiDiscussions 1.0.x Synced 1mo ago

READMEChangelog (4)Dependencies (9)Versions (16)Used By (1)

Chimera - mapping
=================

[](#chimera---mapping)

[![Total Downloads](https://camo.githubusercontent.com/6a23c0eac3cd99348b86ef08141d361bba1d56d95c5065b478b99e0813b8aeaf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6368696d6572612f6d617070696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chimera/mapping)[![Latest Stable Version](https://camo.githubusercontent.com/0c471b60c5d76e6d6d8cbed6f96fe138abce4e1f5f0ec3e48fc9e3d39ef123c5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6368696d6572612f6d617070696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chimera/mapping)[![Unstable Version](https://camo.githubusercontent.com/b86154d427b0e917e08e2512157d908dee5f21a0699e0cf28c2248ebb642d2b5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f6368696d6572612f6d617070696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chimera/mapping)

[![Build Status](https://camo.githubusercontent.com/a671244a2b675d575c334278078f3b30ba2de200d1bee2179af4fa08e7cbdb20/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6368696d6572617068702f6d617070696e672f706870756e69742e796d6c3f6272616e63683d312e302e78267374796c653d666c61742d737175617265)](https://github.com/chimeraphp/mapping/actions?query=workflow%3A%22PHPUnit%20Tests%22+branch%3A1.0.x)[![Code Coverage](https://camo.githubusercontent.com/54afb8984b86227878f8411c71d924aff16b8640b448f48edc89be69fb77bc26/68747470733a2f2f636f6465636f762e696f2f67682f6368696d6572617068702f6d617070696e672f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/chimeraphp/mapping)

> The term Chimera (*/kɪˈmɪərə/* or */kaɪˈmɪərə/*) has come to describe any mythical or fictional animal with parts taken from various animals, or to describe anything composed of very disparate parts, or perceived as wildly imaginative, implausible, or dazzling.

There are many many amazing libraries in the PHP community and with the creation and adoption of the PSRs we don't necessarily need to rely on full stack frameworks to create a complex and well designed software. Choosing which components to use and plugging them together can sometimes be a little challenging.

The goal of this set of packages is to make it easier to do that (without compromising the quality), allowing you to focus on the behaviour of your software.

This package provides a set of annotations to be used to configured your command/query handlers, HTTP middleware, and command/query bus middleware.

**Important:** these annotations will only be used when used together with packages that read them, like [`chimera/di-symfony`](https://github.com/chimeraphp/di-symfony).

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

[](#installation)

Package is available on [Packagist](http://packagist.org/packages/chimera/mapping), you can install it using [Composer](http://getcomposer.org).

```
composer require chimera/mapping
```

### PHP Configuration

[](#php-configuration)

In order to make sure that we're dealing with the correct data, we're using `assert()`, which is a very interesting feature in PHP but not often used. The nice thing about `assert()` is that we can (and should) disable it in production mode so that we don't have useless statements.

So, for production mode, we recommend you to set `zend.assertions` to `-1` in your `php.ini`. For development you should leave `zend.assertions` as `1` and set `assert.exception` to `1`, which will make PHP throw an [`AssertionError`](https://secure.php.net/manual/en/class.assertionerror.php)when things go wrong.

Check the documentation for more information:

Usage
-----

[](#usage)

These are the annotations related to how services should be mapped to the command/query bus:

- `Chimera\Mapping\ServiceBus\CommandHandler`: exposes the class as a command handler
- `Chimera\Mapping\ServiceBus\QueryHandler`: exposes the class as a query handler
- `Chimera\Mapping\ServiceBus\Middleware`: exposes the class as a command/query middleware

And these are the ones related to how services should be mapped to the PSR-15 application:

- `Chimera\Mapping\Routing\CreateAndFetchEndpoint`: adds an endpoint that will execute a command to create a resource and then a query to fetch its state
- `Chimera\Mapping\Routing\CreateEndpoint`: adds an endpoint that will execute a command to create a resource
- `Chimera\Mapping\Routing\ExecuteAndFetchEndpoint`: adds an endpoint that will execute a command to modify a resource and then a query to fetch its state
- `Chimera\Mapping\Routing\ExecuteEndpoint`: adds an endpoint that will execute a command to modify/remove a resource
- `Chimera\Mapping\Routing\FetchEndpoint`: adds an endpoint that will execute a query
- `Chimera\Mapping\Routing\Middleware`: exposes the class as a PSR-15 HTTP middleware

The idea of the annotations is to simplify the mapping of services, removing complex tags from the dependency injection container file. They should essentially be used like this:

```
