mezzio-fastroute
FastRoute integration adapter, wiring nikic/FastRoute as a routing engine for the Mezzio middleware microframework.
Repository Health
Technical Analysis
mezzio-fastroute is the official adapter package that lets Mezzio applications use nikic/FastRoute — a fast, regex-dispatch based PHP router — as their routing implementation. It implements Mezzio’s RouterInterface on top of FastRoute’s route collector and dispatcher, translating FastRoute’s match results into Mezzio’s standard RouteResult objects.
Because Mezzio treats routing as a pluggable concern, this package is one of two officially supported router adapters (the other being laminas-router) and is commonly selected by developers who prioritize FastRoute’s compiled-regex dispatch performance for high-throughput middleware applications.
What You Get
- A
FastRouteRouterclass implementing Mezzio’sRouterInterfaceon top of FastRoute’s dispatcher - Automatic translation of FastRoute match/no-match results into Mezzio’s
RouteResultobjects - Support for FastRoute’s route caching to avoid rebuilding the dispatch table on every request
- Drop-in configuration via the Mezzio skeleton installer’s router-selection prompt
- Compatibility with all of Mezzio’s route-parameter and route-name conventions
Common Use Cases
- Selecting FastRoute as the router when scaffolding a new Mezzio application via mezzio-skeleton
- Migrating a Mezzio application from laminas-router to FastRoute for its regex-compilation performance characteristics
- Building high-throughput PSR-15 middleware APIs that benefit from FastRoute’s cached dispatch tables
- Integrating FastRoute-based routing into custom PSR-11 container configurations for Mezzio
Under The Hood
Architecture - The package’s core FastRouteRouter class wraps a FastRoute\RouteCollector and FastRoute\Dispatcher, translating Mezzio’s Route objects (path, allowed methods, handler) into FastRoute’s route definitions at construction time, then converting FastRoute’s dispatch results (found/not-found/method-not-allowed) back into Mezzio’s RouteResult value object on each request. This adapter-pattern design keeps FastRoute’s dispatch internals fully encapsulated behind Mezzio’s router-agnostic interface.
Tech Stack - Pure PHP depending on nikic/fast-route for the underlying dispatch engine and mezzio/mezzio for the RouterInterface contract it implements. Distributed via Composer with PSR-4 autoloading, GitHub Actions CI, and Psalm static analysis tracked on Shepherd.
Code Quality - With 744 commits from 29 contributors and 14 tagged releases, the package is a focused, well-exercised adapter with a small but complete PHPUnit test suite covering route matching, caching, and method-not-allowed scenarios. Its narrow scope (one class implementing one interface) keeps the surface area easy to fully test.
API Design - Consumers rarely interact with this package’s classes directly beyond registering it in their DI container configuration (or letting the mezzio-skeleton installer do so); once configured, all routing calls go through Mezzio’s own Application::get()/post()/route() API, so switching from laminas-router to FastRoute requires no application-code changes.