sirix/mezzio-routing-contracts

Contracts for sirix/mezzio-routing-attributes route attribute modifiers

Maintainers

Package info

github.com/sirix777/mezzio-routing-contracts

pkg:composer/sirix/mezzio-routing-contracts

Fund package maintenance!

sirix777

buymeacoffee.com/sirix

Statistics

Installs: 65

Dependents: 4

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0 2026-05-09 15:07 UTC

This package is auto-updated.

Last update: 2026-05-10 13:33:36 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

Contracts for sirix/mezzio-routing-attributes route attribute modifiers.

Pre-1.0 package: Not yet production-ready. Public contracts may change with breaking changes before 1.0.0.

Installation

composer require sirix/mezzio-routing-contracts

Usage

Implement RouteAttributeModifierInterface on any route-related attribute to inject middleware and/or provide default route options.

use Attribute;
use Sirix\Mezzio\Routing\Contracts\RouteAttributeModifierInterface;

#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
final readonly class RequireTenant implements RouteAttributeModifierInterface
{
    public function __construct(private string $tenantHeader = 'x-tenant-id') {}

    public function getMiddleware(): array
    {
        return [RequireTenantMiddleware::class];
    }

    public function getDefaults(): array
    {
        return ['tenant_header' => $this->tenantHeader];
    }
}

Usage with routing attributes:

use Sirix\Mezzio\Routing\Attributes\Attribute\Get;

final class OrdersHandler
{
    #[Get('/orders', name: 'orders.list')]
    #[RequireTenant('x-org-id')]
    public function list(): ResponseInterface
    {
        // ...
    }
}

The routing-attributes package discovers all implementations of RouteAttributeModifierInterface at boot time and merges their middleware and defaults into the route definition.

Interface

interface RouteAttributeModifierInterface
{
    /** @return list<class-string<MiddlewareInterface>|non-empty-string> */
    public function getMiddleware(): array;

    /** @return array<string, mixed> */
    public function getDefaults(): array;
}