Download the PHP package delolmo/symfony-router without Composer
On this page you can find all versions of the php package delolmo/symfony-router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download delolmo/symfony-router
More information about delolmo/symfony-router
Files in delolmo/symfony-router
Package symfony-router
Short Description PSR-15 middleware that matches requests with symfony/routing and stores the route attributes in the PSR-7 request.
License MIT
Homepage https://github.com/delolmo/symfony-router
Informations about the package symfony-router
delolmo/symfony-router
PSR-15 middleware to use the symfony/routing component and store the route attributes in the request.
Requirements
- PHP ~8.4.27 || ^8.5.12
- A PSR-7 http library
- A PSR-17 http factory
Installation
This package is installable and autoloadable via Composer as delolmo/symfony-router.
To load route definitions from files through Symfony's Router, as in the example below, also require symfony/config:
Example
Consider Symfony's PhpFileLoader to load route definitions from the following file:
For this example, we will be using middlewares/utils for a PSR-15 compliant
dispatcher. See link
for more PSR-15 implementations.
This example uses a basic anonymous function to print the route's attributes:
Mapping requests with Valinor
The route parameters are request attributes, so a handler further down the pipeline can pass them to cuyz/valinor as the route parameters of an HttpRequest and map the whole request to a typed object:
Options
The constructor takes two arguments:
The router to match with (a Symfony Router, or a UrlMatcher for routes built in code) and a PSR-17 factory to create the error responses:
| Outcome | Response |
|---|---|
| No route matches the path | 404 Not Found |
| A route matches the path but not the method | 405 Method Not Allowed, with an Allow header listing the allowed methods |
| The router has no routes at all | 500 Internal Server Error |
Error responses carry the standard reason phrase, never the routing exception's message, which can echo the requested path.
Before matching, the router's context takes the request's host, scheme and base URL, so URLs a Router generates while the request is handled match it.
All versions of symfony-router with dependencies
psr/http-factory Version ^1.1
psr/http-message Version ^1.1 || ^2.0
psr/http-server-handler Version ^1.0
psr/http-server-middleware Version ^1.0
symfony/psr-http-message-bridge Version ^8.0
symfony/routing Version ^8.0.13