PHPackages                             articus/path-handler - 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. [API Development](/categories/api)
4. /
5. articus/path-handler

ActiveLibrary[API Development](/categories/api)

articus/path-handler
====================

Library for API development with Mezzio that simplifies creating operation middlewares and registering them in router

0.8.3(4y ago)418.4k↓46.2%2[1 PRs](https://github.com/Articus/PathHandler/pulls)1MITPHPPHP ^7.1|^8.0

Since Sep 9Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Articus/PathHandler)[ Packagist](https://packagist.org/packages/articus/path-handler)[ RSS](/packages/articus-path-handler/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (11)Versions (17)Used By (1)

Path Handler
============

[](#path-handler)

[![Run tests](https://github.com/Articus/PathHandler/actions/workflows/run-tests.yml/badge.svg)](https://github.com/Articus/PathHandler/actions/workflows/run-tests.yml)[![Publish docs](https://github.com/Articus/PathHandler/actions/workflows/publish-docs.yml/badge.svg)](https://github.com/Articus/PathHandler/actions/workflows/publish-docs.yml)[![Coveralls](https://camo.githubusercontent.com/48f864c9d17bf85b40c95367c1fb589774b74cc0bdf0a406b1cc46a8b473b33c/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f417274696375732f5061746848616e646c65722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Articus/PathHandler?branch=master)[![Codacy](https://camo.githubusercontent.com/97aaa8b929d4520f5309c1a28b40084ba66417d59d81b29e094154366d90ca7d/68747470733a2f2f6170702e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3032646334636662363965333430373961623338303539336665356634663730)](https://app.codacy.com/gh/Articus/PathHandler/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)

This library considerably simplifies API development with [Mezzio](https://github.com/mezzio/mezzio) by reducing amount of boilerplate code you have to write for each API operation. The idea is to provide a more convenient way to deal with:

- routing - routes for all operations are registered automatically
- consuming - each operation may have unique algorithm to parse request body according its content type
- attributing (as in [PSR-7 request attributes](https://www.php-fig.org/psr/psr-7/#15-server-side-requests)) - each operation may have its own set of request attributes calculated from raw request data (like current user information insteadof authentication header, validated DTO insteadof form value array, entity object insteadof query parameter with its id and so on)
- producing - each operation may have unique algorithm to prepare response body from operation result according media type accepted by client

So you can focus on handling your API operations and spend less time on writing auxiliary code for request processing.

How to install?
---------------

[](#how-to-install)

Just add `"articus/path-handler"` to your [composer.json](https://getcomposer.org/doc/04-schema.md#require) and check [packages suggested by the library](https://getcomposer.org/doc/04-schema.md#suggest) for extra dependencies of optional components you want to use.

How to use?
-----------

[](#how-to-use)

First of all you need a project with [Mezzio](https://github.com/mezzio/mezzio) application. For example, you can generate one with [this installer](https://github.com/mezzio/mezzio-skeleton).

Next you need to declare **handlers**. Each handler is a set of all **operations** that can be performed when some **path** of your API is accessed with distinct HTTP methods. Any class can be a handler, you just need to decorate it with special PHP attributes:

```
namespace My;

use Articus\PathHandler\PhpAttribute as PHA;
use Articus\PathHandler\Exception;
use Psr\Http\Message\ServerRequestInterface;

#[PHA\Route('/entity')] //This is how you set path for handler operations
class Handler
{
    #[PHA\Post()] //This is how you declare HTTP method of the operation
    #[PHA\Consumer('application/json', 'Json')] //This is how you consume request body
    #[PHA\Attribute('Transfer', ['type'=>'My\DTO','object_attr'=>'dto','error_attr'=>'errors'])] //This is how you attribute request
    #[PHA\Producer('application/json', 'Json')] //This is how you produce response body from returned value
    public function handlePost(ServerRequestInterface $request): \My\DTO
    {
        $errors = $request->getAttribute('errors');
        if (!empty($errors))
        {
            //This is how you can return non-200 responses
            throw new Exception\UnprocessableEntity($errors);
        }
        /* @var \My\DTO $dto */
        $dto = $request->getAttribute('dto');
        return $dto;
    }
}
```

Finally, you need to configure special factory for router service. Here is a sample configuration for [Laminas Service Manager](https://docs.laminas.dev/laminas-servicemanager/) (example is in YAML just for readability):

```
dependencies:
  factories:
    Mezzio\Router\RouterInterface: Articus\PathHandler\RouteInjectionFactory
    Articus\PathHandler\MetadataProviderInterface: Articus\PathHandler\MetadataProvider\Factory\PhpAttribute
    Articus\PathHandler\Handler\PluginManager: [Articus\PluginManager\Factory\Laminas, Articus\PathHandler\Handler\PluginManager]
    Articus\PathHandler\Consumer\PluginManager: Articus\PathHandler\Consumer\Factory\PluginManager
    Articus\PathHandler\Attribute\PluginManager: Articus\PathHandler\Attribute\Factory\PluginManager
    Articus\PathHandler\Producer\PluginManager: Articus\PathHandler\Producer\Factory\PluginManager

Articus\PathHandler\RouteInjectionFactory:
  paths:
    '':
    # List of your handlers
    - My\Handler
# Configuration for handler plugin manager - sub-container dedicated for handlers
Articus\PathHandler\Handler\PluginManager:
  factories:
    My\Handler: My\HandlerFactory
```

For more details check [documentation](https://articus.github.io/PathHandler/).

Enjoy!
------

[](#enjoy)

I hope this library will be useful for someone except me. It is used for production purposes, but it lacks lots of refinement, especially in terms of tests and documentation.

If you have any suggestions, advices, questions or fixes feel free to submit issue or pull request.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity66

Established project with proven stability

 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

Every ~166 days

Recently: every ~81 days

Total

13

Last Release

1545d ago

PHP version history (3 changes)0.1PHP ^5.6 || ^7.0

0.4PHP ^7.1

0.6.1PHP ^7.1|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/36d4540118e010edabdfa478fb5b4ff2fa8465bd9426e1bb43b582c3ad280727?d=identicon)[Articus](/maintainers/Articus)

---

Top Contributors

[![Articus](https://avatars.githubusercontent.com/u/358544?v=4)](https://github.com/Articus "Articus (12 commits)")

---

Tags

apidispatchlaminas-mezziomiddlewareroutingmiddlewareapilaminasroutingmezziodispatch

### Embed Badge

![Health badge](/badges/articus-path-handler/health.svg)

```
[![Health](https://phpackages.com/badges/articus-path-handler/health.svg)](https://phpackages.com/packages/articus-path-handler)
```

###  Alternatives

[shahghasiadil/laravel-api-versioning

Elegant attribute-based API versioning solution for Laravel applications with built-in deprecation management and version inheritance

2913.6k](/packages/shahghasiadil-laravel-api-versioning)

PHPackages © 2026

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