PHPackages                             sirix/mezzio-routing-attributes - 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. sirix/mezzio-routing-attributes

ActiveLibrary

sirix/mezzio-routing-attributes
===============================

Attribute-based routing support for Mezzio applications

0.1.5(1mo ago)046↑552.2%MITPHPPHP ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Mar 12Pushed 1mo agoCompare

[ Source](https://github.com/sirix777/mezzio-routing-attributes)[ Packagist](https://packagist.org/packages/sirix/mezzio-routing-attributes)[ Fund](https://buymeacoffee.com/sirix)[ GitHub Sponsors](https://github.com/sirix777)[ RSS](/packages/sirix-mezzio-routing-attributes/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (9)Versions (7)Used By (0)

Mezzio Routing Attributes
=========================

[](#mezzio-routing-attributes)

[![Latest Stable Version](https://camo.githubusercontent.com/01e3c4aa6aaffd7e922531d8fd78c22218d8b237e7232ccdedf709f66fc8158c/687474703a2f2f706f7365722e707567782e6f72672f73697269782f6d657a7a696f2d726f7574696e672d617474726962757465732f76)](https://packagist.org/packages/sirix/mezzio-routing-attributes)[![Total Downloads](https://camo.githubusercontent.com/72f23226d75acac533b2158d036478c2f4ee8d852b1dc9c33719a361a67dc907/687474703a2f2f706f7365722e707567782e6f72672f73697269782f6d657a7a696f2d726f7574696e672d617474726962757465732f646f776e6c6f616473)](https://packagist.org/packages/sirix/mezzio-routing-attributes)[![Latest Unstable Version](https://camo.githubusercontent.com/5cd27483cd90702a85304849476e3346626a3dc0133ed76a84b2a2d1288285aa/687474703a2f2f706f7365722e707567782e6f72672f73697269782f6d657a7a696f2d726f7574696e672d617474726962757465732f762f756e737461626c65)](https://packagist.org/packages/sirix/mezzio-routing-attributes)[![License](https://camo.githubusercontent.com/fdbbe84c4700ebeb1b8b35a8de08701a408d7265949f84d46f60611c9ae71ccc/687474703a2f2f706f7365722e707567782e6f72672f73697269782f6d657a7a696f2d726f7574696e672d617474726962757465732f6c6963656e7365)](https://packagist.org/packages/sirix/mezzio-routing-attributes)[![PHP Version Require](https://camo.githubusercontent.com/c39a03108a8240a0a06ca618d3a80de4a7a408f3acbfbd350a6cd3c878c1d567/687474703a2f2f706f7365722e707567782e6f72672f73697269782f6d657a7a696f2d726f7574696e672d617474726962757465732f726571756972652f706870)](https://packagist.org/packages/sirix/mezzio-routing-attributes)

Attribute-based route registration for Mezzio applications.

> Warning: this package is not production-ready yet. Before `1.0.0`, backward compatibility is not guaranteed.

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

[](#installation)

```
composer require sirix/mezzio-routing-attributes
```

Status
------

[](#status)

This package provides:

- PHP 8 route attributes (`Route`, `Get`, `Post`, `Put`, `Patch`, `Delete`, `Any`)
- Class-level and method-level attribute extraction
- Route provider registration via `RouteCollectorInterface`
- Optional route middleware stacks in attributes (`middleware: [...]`)
- Optional class discovery from configured directories
- Compiled route cache artifact (`require`-based)
- CLI commands:
    - `routing-attributes:routes:list`
    - `routing-attributes:cache:clear`

Configuration
-------------

[](#configuration)

Production default (performance-first):

```
return [
    'routing_attributes' => [
        'classes' => [
            App\Handler\PingHandler::class,
        ],
        'duplicate_strategy' => 'throw', // throw|ignore
        'handlers' => [
            'mode' => 'psr15', // psr15|callable
        ],
        'override_mezzio_routes_list_command' => false,
        'route_list' => [
            'classic_routes_middleware_display' => 'upstream', // upstream|resolved
        ],
        'discovery' => [
            'enabled' => false,
            'paths' => [],
            'strategy' => 'token', // token|psr4
            'psr4' => [
                'mappings' => [],
                'fallback_to_token' => true,
            ],
        ],
        'cache' => [
            'enabled' => true,
            'file' => 'data/cache/mezzio-routing-attributes.php',
        ],
    ],
];
```

Supported `routing_attributes.cache` keys:

- `enabled` (`bool`)
- `file` (`non-empty string`, required when `enabled=true`)

Removed and no longer supported:

- `routing_attributes.lazy_service_resolution`
- `routing_attributes.cache.mode`
- `routing_attributes.cache.backend`
- `routing_attributes.cache.strict`
- `routing_attributes.cache.write_fail_strategy`
- `routing_attributes.discovery.class_map_cache`

Discovery Behavior
------------------

[](#discovery-behavior)

- If `discovery.enabled=false`, only explicit `classes` are used.
- If `discovery.enabled=true`, classes are discovered from `discovery.paths`.
- If compiled cache is enabled and cache file already exists, discovery is skipped on boot.

Compiled Cache Behavior
-----------------------

[](#compiled-cache-behavior)

- If `cache.enabled=true` and cache file exists, routes are registered from compiled cache.
- If cache file is missing or invalid, routes are extracted/discovered and cache file is rebuilt.
- Cache format is optimized for startup speed and keeps middleware pipeline resolution lazy per service.

Cache Clear Command
-------------------

[](#cache-clear-command)

Clear compiled cache file:

```
php vendor/bin/laminas routing-attributes:cache:clear
```

Override file path:

```
php vendor/bin/laminas routing-attributes:cache:clear --file=data/cache/custom-routes.php
```

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

[](#basic-usage)

Method-level attribute:

```
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Sirix\Mezzio\Routing\Attributes\Attribute\Get;

final class PingHandler implements RequestHandlerInterface
{
    #[Get('/ping', name: 'ping')]
    public function handle(ServerRequestInterface $request): ResponseInterface
    {
        throw new \RuntimeException('Implement your response.');
    }
}
```

Class-level attribute:

```
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Sirix\Mezzio\Routing\Attributes\Attribute\Get;

#[Get('/ping', name: 'ping')]
final class PingHandler implements RequestHandlerInterface
{
    public function handle(ServerRequestInterface $request): ResponseInterface
    {
        throw new \RuntimeException('Implement your response.');
    }
}
```

Benchmarks
----------

[](#benchmarks)

Run:

```
composer benchmark
composer benchmark-threshold
```

Latest local run (`PHP 8.2.30`):

- `warm_cache_hit_manual`: `0.0059 ms` median, `2.0625 KB` median peak
- `no_cache_manual`: `0.0211 ms` median, `3.4922 KB` median peak
- `cold_cache_rebuild_manual`: `0.0922 ms` median, `6.1719 KB` median peak
- `warm_cache_hit_discovery_token`: `0.0128 ms` median, `3.3438 KB` median peak
- `warm_cache_hit_discovery_psr4`: `0.0124 ms` median, `3.3438 KB` median peak
- Threshold benchmark (`compiled`) showed cache-win from `10` routes onward.
- At `12800` routes: `50.4975 ms` (no-cache) vs `23.1091 ms` (compiled), speedup `54.24%`; peak memory `13213.25 KB` vs `9260.84 KB`.

Troubleshooting
---------------

[](#troubleshooting)

- Service not found: register handler/action class in container.
- Route changes are not visible: clear compiled cache with `routing-attributes:cache:clear`.
- In long-running workers (RoadRunner/Swoole), reload/restart workers after cache rebuild/clear.
- Invalid cache payload errors: delete cache file and warm it again.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance89

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

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 ~0 days

Total

6

Last Release

57d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6ecccf9003c061847e877eeea3bdf1b382f6f9dbb11d33112d6b2740bf0533f9?d=identicon)[sirix777](/maintainers/sirix777)

---

Tags

middlewarelaminasrouterroutingpsr-15mezzioattributesphp8routing-attributes

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sirix-mezzio-routing-attributes/health.svg)

```
[![Health](https://phpackages.com/badges/sirix-mezzio-routing-attributes/health.svg)](https://phpackages.com/packages/sirix-mezzio-routing-attributes)
```

###  Alternatives

[mezzio/mezzio

PSR-15 Middleware Microframework

3883.6M97](/packages/mezzio-mezzio)[mezzio/mezzio-authentication

Authentication middleware for Mezzio and PSR-7 applications

121.6M26](/packages/mezzio-mezzio-authentication)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)[mezzio/mezzio-helpers

Helper/Utility classes for Mezzio

134.3M67](/packages/mezzio-mezzio-helpers)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.0M61](/packages/mezzio-mezzio-router)[mezzio/mezzio-fastroute

FastRoute integration for Mezzio

162.7M52](/packages/mezzio-mezzio-fastroute)

PHPackages © 2026

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