sirix/mezzio-routing-contracts
Composer 安装命令:
composer require sirix/mezzio-routing-contracts
包简介
Contracts for sirix/mezzio-routing-attributes route attribute modifiers
README 文档
README
Contracts for sirix/mezzio-routing-attributes route attribute modifiers.
This package contains the stable public contract used by routing attributes that need to contribute middleware or default route options to a route definition.
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.
Contract
interface RouteAttributeModifierInterface { /** @return list<class-string<MiddlewareInterface>|non-empty-string> */ public function getMiddleware(): array; /** @return array<string, mixed> */ public function getDefaults(): array; }
getMiddleware()
Returns middleware identifiers that should be appended to the route pipeline.
Each item must be a middleware class name implementing Psr\Http\Server\MiddlewareInterface or another non-empty middleware identifier supported by the consuming router integration.
getDefaults()
Returns default route options keyed by option name. Consumers merge these values into the route defaults/options for the route that carries the attribute.
Versioning
The 1.x series follows Semantic Versioning.
Breaking changes to public contracts are reserved for the next major version.
统计信息
- 总下载量: 674
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-09