league/route
Fast routing and dispatch component including PSR-15 middleware, built on top of FastRoute.
7.0.0
3.4M downloads/mo
#3091 most downloaded on Packagist
thephpleague/route
What this package is like to depend on
Last release 1 months ago
14 Jul 2026
Ships unpredictably
gaps range from 9 days to 3.2 years
Most releases are documented
notes for 28 of 39 stable releases
Nothing withdrawn
no release was ever pulled
12 years old
39 releases · first in 2015
1 release in the last 12 months
see the full history below
Release timeline
39 releases · Jan 2015 to Jul 2026Releases
latest 39-
7.0.014 Jul 2026Release notes
Open source →[7.0.0] 2026-07-14
Added
RouterInterfaceextending PSR-15RequestHandlerInterfacefor Router/Cache\Router substitutability.MatchResultvalue object andMatchStatusenum for matching routes without dispatching (#328, #352).Router::match()method to inspect route matching without executing handlers.Router::getRoutes()method to introspect all registered routes (#330).Route::setPathVars()for dispatcher-set path parameters, separate from user-set defaults.- Index-based route caching with signature hash validation for cache integrity.
- Corrupt cache auto-recovery in cached router.
UrlGeneratorInterfacewithgenerateUrl()for reverse routing from named routes (#355).RouterandCache\Routerboth implementUrlGeneratorInterface.DispatcherInterface(marked@internal) formalising the Router-Dispatcher contract (#359).- Middleware groups:
defineMiddlewareGroup()andmiddlewareGroup()for named middleware collections onRouterandRouteGroup. MatchStatus::ConditionNotMetenum case distinguishing host/scheme/port condition failures from true not-found results.MatchResult::conditionNotMet()named constructor andisConditionNotMet()convenience method.MethodNotAllowedException::getAllowedMethods()for typed array access to allowed HTTP methods.- Matched
Routeobject added as a request attribute (keyed byRoute::class) during dispatch, enabling routing-aware middleware. - Route freezing: routes become immutable after
prepareRoutes(), preventing silent post-compilation misconfiguration. FreezeableInterface,FreezeableTrait, andFreezeGuardfor route immutability lifecycle.- Optional segment support in
generateUrl(): routes using FastRoute[/{param}]syntax resolve correctly with defaults fromsetVars()or omit the segment when unset. query()route helper onRouterandRouteGroup(viaRouteCollectionInterface) for the HTTP QUERY method (draft-ietf-httpbis-safe-method-w-body).
Changed
- Minimum PHP version raised to 8.3.
- PHPStan analysis raised from level 4 to level 7 (#360).
- Switched from PHP_CodeSniffer (PSR-12) to PHP CS Fixer (PER-CS2.0).
- Switched from PHPUnit to Pest v4.
- Switched from PHPUnit mocks to Mockery.
- Test namespace changed from
League\Route\toLeague\Route\Test\. - Cached router completely redesigned: caches compiled FastRoute data (scalars only) instead of serialising the entire Router object (#353).
Route::setVars()now sets declaration-time defaults only; dispatcher usessetPathVars()internally (#350).Route::getVars()returns merged result of default vars and path vars, with path vars taking precedence.- Route compilation is now request-independent: all routes compiled unconditionally, condition matching at dispatch time only.
Cache\Routernow implementsRouterInterface.FileCache::getMultiple(),setMultiple(), anddeleteMultiple()now throwBadMethodCallExceptioninstead of returning incorrect values.Dispatchernow uses composition instead of inheriting fromFastRoute\Dispatcher\GroupCountBased(#359).Dispatcherconstructor accepts strategy and route map at construction time instead of via setters.Dispatcherno longer implementsRouteConditionHandlerInterface(condition matching extracted as internal concern).JsonStrategy::getOptionsCallable()returned closure now accepts(ServerRequestInterface $request, array $vars)parameters, enabling CORS-aware OPTIONS handling (#361).OptionsHandlerInterface::getOptionsCallable()docblock now specifies the expected callable signature.- Cache signature hash upgraded from md5 to xxh128 for improved collision resistance.
Dispatcherswitch statements replaced withmatchexpressions for exhaustiveness checking.MatchResultis now areadonlyclass.Route::setPathVars()marked@internal(dispatcher-only operation, exempted from route freezing).
Removed
laravel/serializable-closureremoved from hard dependencies (moved to suggest).- Closure wrapping removed from
Routeconstructor. - BETA status removed from cached router.
- Request-dependent route filtering removed from
prepareRoutes(). - Support for PHP 8.1 and 8.2 dropped.
- Scrutinizer CI integration removed.
Dispatcher::setRouteMap()removed (route map now set via constructor).- Duplicate
Router::processGroups()method removed (consolidated intocollectGroupRoutes()).
Fixed
Release notes
Open source →Added
RouterInterfaceextending PSR-15RequestHandlerInterfacefor Router/Cache\Router substitutability.MatchResultvalue object andMatchStatusenum for matching routes without dispatching (#328, #352).Router::match()method to inspect route matching without executing handlers.Router::getRoutes()method to introspect all registered routes (#330).Route::setPathVars()for dispatcher-set path parameters, separate from user-set defaults.- Index-based route caching with signature hash validation for cache integrity.
- Corrupt cache auto-recovery in cached router.
UrlGeneratorInterfacewithgenerateUrl()for reverse routing from named routes (#355).RouterandCache\Routerboth implementUrlGeneratorInterface.DispatcherInterface(marked@internal) formalising the Router-Dispatcher contract (#359).- Middleware groups:
defineMiddlewareGroup()andmiddlewareGroup()for named middleware collections onRouterandRouteGroup. MatchStatus::ConditionNotMetenum case distinguishing host/scheme/port condition failures from true not-found results.MatchResult::conditionNotMet()named constructor andisConditionNotMet()convenience method.MethodNotAllowedException::getAllowedMethods()for typed array access to allowed HTTP methods.- Matched
Routeobject added as a request attribute (keyed byRoute::class) during dispatch, enabling routing-aware middleware. - Route freezing: routes become immutable after
prepareRoutes(), preventing silent post-compilation misconfiguration. FreezeableInterface,FreezeableTrait, andFreezeGuardfor route immutability lifecycle.- Optional segment support in
generateUrl(): routes using FastRoute[/{param}]syntax resolve correctly with defaults fromsetVars()or omit the segment when unset. query()route helper onRouterandRouteGroup(viaRouteCollectionInterface) for the HTTP QUERY method (draft-ietf-httpbis-safe-method-w-body).
Changed
- Minimum PHP version raised to 8.3.
- PHPStan analysis raised from level 4 to level 7 (#360).
- Switched from PHP_CodeSniffer (PSR-12) to PHP CS Fixer (PER-CS2.0).
- Switched from PHPUnit to Pest v4.
- Switched from PHPUnit mocks to Mockery.
- Test namespace changed from
League\Route\toLeague\Route\Test\. - Cached router completely redesigned: caches compiled FastRoute data (scalars only) instead of serialising the entire Router object (#353).
Route::setVars()now sets declaration-time defaults only; dispatcher usessetPathVars()internally (#350).Route::getVars()returns merged result of default vars and path vars, with path vars taking precedence.- Route compilation is now request-independent: all routes compiled unconditionally, condition matching at dispatch time only.
Cache\Routernow implementsRouterInterface.FileCache::getMultiple(),setMultiple(), anddeleteMultiple()now throwBadMethodCallExceptioninstead of returning incorrect values.Dispatchernow uses composition instead of inheriting fromFastRoute\Dispatcher\GroupCountBased(#359).Dispatcherconstructor accepts strategy and route map at construction time instead of via setters.Dispatcherno longer implementsRouteConditionHandlerInterface(condition matching extracted as internal concern).JsonStrategy::getOptionsCallable()returned closure now accepts(ServerRequestInterface $request, array $vars)parameters, enabling CORS-aware OPTIONS handling (#361).OptionsHandlerInterface::getOptionsCallable()docblock now specifies the expected callable signature.- Cache signature hash upgraded from md5 to xxh128 for improved collision resistance.
Dispatcherswitch statements replaced withmatchexpressions for exhaustiveness checking.MatchResultis now areadonlyclass.Route::setPathVars()marked@internal(dispatcher-only operation, exempted from route freezing).
Removed
laravel/serializable-closureremoved from hard dependencies (moved to suggest).- Closure wrapping removed from
Routeconstructor. - BETA status removed from cached router.
- Request-dependent route filtering removed from
prepareRoutes(). - Support for PHP 8.1 and 8.2 dropped.
- Scrutinizer CI integration removed.
Dispatcher::setRouteMap()removed (route map now set via constructor).- Duplicate
Router::processGroups()method removed (consolidated intocollectGroupRoutes()).
Fixed
- Naming a route no longer alters route registration order, which could cause a
FastRoute\BadRouteExceptionwhen a named static route was shadowed by a later variable route (#362, #363).
-
6.2.025 Nov 2024Release notes
Open source →[6.2.0] 2024-11
Changed
- Replaced opis/closure with laravel/serializable-closure and implemented throughout the handler process rather than a blanket serialisation of the router.
Release notes
Open source →Changed
- Replaced opis/closure with laravel/serializable-closure and implemented throughout the handler process rather than a blanket serialisation of the router.
-
6.1.120 Nov 2024Release notes
Open source →Fixed
- Further fixes for type hinting bug related to array based callables with a string class name.
-
6.1.020 Nov 2024Release notes
Open source →[6.1.0] 2024-11
Fixed
- Fixed a bug introduced in 6.0.0 where an array based callable with a string class name would not be considered valid.
- Added some doc comments for clarity on array types. (@marekskopal)
Changed
- Updated
psr/http-messageto^2.0.0.
Release notes
Open source →Fixed
- Fixed a bug introduced in 6.0.0 where an array based callable with a string class name would not be considered valid.
- Added some doc comments for clarity on array types. (@marekskopal)
Changed
- Updated
psr/http-messageto^2.0.0.
-
6.0.010 Nov 2024Release notes
Open source →[6.0.0]
Note: While this is a major release, there are no breaking changes to the public API. The major version bump is due to the removal of support for PHP 8.0 and below.
This being said, there are some internal changes that may affect you if you have extended the library in any way. Please test thoroughly before upgrading.
Added
- Added full support for PHP 8.1 to 8.4.
- Ability to use a PSR-15 middleware as a controller.
- Ability to pass an array of HTTP methods to
Router::mapto create a route that matches multiple methods.- This method still accepts a string so is not a breaking change.
- Ability to add a custom key to a caching router.
Changed
- Fixes and improvements throughout for PHP 8.1 to 8.4.
Removed
- Removed support for PHP < 8.1.
Release notes
Open source →Note: While this is a major release, there are no breaking changes to the public API. The major version bump is due to the removal of support for PHP 8.0 and below.
This being said, there are some internal changes that may affect you if you have extended the library in any way. Please test thoroughly before upgrading.
Added
- Added full support for PHP 8.1 to 8.4.
- Ability to use a PSR-15 middleware as a controller.
- Ability to pass an array of HTTP methods to
Router::mapto create a route that matches multiple methods.- This method still accepts a string so is not a breaking change.
- Ability to add a custom key to a caching router.
Changed
- Fixes and improvements throughout for PHP 8.1 to 8.4.
Removed
- Removed support for PHP < 8.1.
-
5.1.230 Jul 2021Release notes
Open source →Added
- Extra logic for
Route::gretPathto be able to properly resolve optional parameters.
- Extra logic for
-
5.1.126 Jul 2021Release notes
Open source →Fix
- Fix to allow multiple routes with the same path to be mapped across multiple extra conditions (scheme, host, port).
-
5.1.009 Jul 2021 -
5.0.126 Mar 2021 -
5.0.025 Jan 2021Release notes
Open source →Added
- A cached router, a way to have a fully built router cached and resolved from cache on subsequent requests.
- Response decorators, a way to manipulate a response object returned from a matched route.
- Automatic generation of OPTIONS routes if they have not been defined.
Changed
- Minimum PHP requirement bumped to 7.2.
Routerno longer extends FastRouteRouteCollecter.Routerconstructor no longer accepts optional FastRouteRouteParserandDataGenerator.Routerconstructor now accepts an optional FastRouteRouteCollector.- Routes already registered with FastRoute
RouteCollectorare respected and matched.
- Routes already registered with FastRoute
- Separated route preparation from dispatch process so that the router can dispatch multiple times.
- General code improvements.
Removed
- Setting of default response headers on strategies. (Replaced by response decorators, see Added).
- Exception handlers from strategies. (Already deprecated in favour of throwable handlers).
-
4.5.427 Mar 2025Nothing published for this version
-
4.5.327 Mar 2025Nothing published for this version
-
4.5.228 Sep 2024Nothing published for this version
-
4.5.125 Jan 2021 -
4.5.018 May 2020Release notes
Open source →Added
- Ability to pass optional
$replacementsarray toRoute::getPathin order to build literal route path strings.
- Ability to pass optional
-
4.4.018 May 2020Release notes
Open source →Added
- Ability to pass JSON flags to JsonStrategy. (@pine3ree)
- Router is now a RequestHandlerInterface so can be used as a middleware itself. (@delboy1978uk)
- Route params now added as Request attributes. (@delboy1978uk)
Fixed
- Exception moved to more appropriate place when shifting no middleware. (@delboy1978uk)
- Ensure group prefix is always added when adding a parent group. (@delboy1978uk)
-
4.3.101 Jul 2019Release notes
Open source →Fixed
- Fixed bug when attempting to get a container for custom strategy that is not container aware.
-
4.3.030 Jun 2019Release notes
Open source →Added
- Ability to add middleware to the stack as a class name so it is only instantiated when used.
Changed
- Switch to use
zendframework/zend-httphandlerrunneras removed fromdiactoros(@JohnstonCode)
Fixed
- When adding a prefix to a group after adding routes, it is now applied to those routes. (@delboy1978uk)
- Fix to how shifting middleware is handled to prevent error triggering. (@delboy1978uk)
- Fix to ensure that when invoking FastRoute methods on League\Route all callables are converted to League\Route objects (@pgk)
- Various documentation fixes.
-
4.2.016 Oct 2018Release notes
Open source →Added
- Allow adding default response headers to strategies.
- Expand error handling to include Throwable.
-
4.1.109 Oct 2018Release notes
Open source →Fixed
- Fixed issue where group middleware was being dublicated on internal routes.
-
4.1.021 Sep 2018Release notes
Open source →Changed
- JSON strategy now allows array and object returns and builds JSON response. (Thanks @willemwollebrants)
Fixed
- Fixed issue where setting strategy on specific routes had no effect. (Thanks @aag)
-
4.0.113 Aug 2018Release notes
Open source →Fixed
- Fixed a bug where content-type header would not be added to response in Json Strategy.
-
4.0.010 Aug 2018Release notes
Open source →Changed
- Increased minimum PHP version to 7.1.0
- Now implements PSR-15 middleware and request handlers.
- No longer enforces use of container, one can be used optionally.
- Strategies now return PSR-15 middleare as handlers.
- Increased types of proxy callables that can be used as controllers.
- General housekeeping and refactoring for continued improvement.
Fixed
- Group level strategies now handle exceptions if a route is not matched but the request falls within the group.
-
3.1.023 Jul 2018Release notes
Open source →Fixed
- Ensure JsonStrategy handles all exceptions by default.
- Handle multiline exception messages.
Added
- Add port condition to routes.
-
3.0.422 Mar 2017 -
3.0.321 Mar 2017Nothing published for this version
-
3.0.221 Mar 2017Nothing published for this version
-
3.0.121 Mar 2017Nothing published for this version
-
3.0.021 Mar 2017Nothing published for this version
-
2.0.223 Jul 2018 -
2.0.114 Nov 2016Nothing published for this version
-
2.0.011 Mar 2016Release notes
Open source →Added
- All routing and dispatching now built around PSR-7.
- Can now group routes with prefix and match conditions.
- Routes now stored against a specific
Routeobject that describes the route. - New
dispatchmethod onRouteCollectionthat is a compliant PSR-7 middleware. - Additional route matching conditions for scheme and host.
Changed
- API rewrite to simplify.
- API naming improvements.
- Strategies now less opinionated about return from controller.
-
1.2.311 Sep 2015Nothing published for this version
-
1.2.208 Sep 2015Nothing published for this version
-
1.2.107 Sep 2015Nothing published for this version
-
1.2.024 Aug 2015Release notes
Open source →Added
- Can now use any callable as a controller.
- Request object is now built by the strategy when one is not available from the container.
Fixed
- General tidying and removal of unused code.
- URI variables now correctly passed to controller in
MethodArgumentStrategy.
-
1.1.024 Feb 2015Release notes
Open source →Added
- Added
addPatternMatchermethod to allow custom regex shortcuts within wildcard routes. - Refactored logic around matching routes.
- Added
-
1.0.129 Jan 2015Release notes
Open source →Fixed
- Added import statements for all used objects.
- Fixed dockblock annotations.
- PSR-2 standards improvements within tests.
-
1.0.012 Jan 2015