PHPackages                             delolmo/symfony-router - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. delolmo/symfony-router

ActiveLibrary[HTTP &amp; Networking](/categories/http)

delolmo/symfony-router
======================

PSR-15 middleware to use the symfony/routing component and store the route attributes in the request.

4.0(6mo ago)71051MITPHPPHP &gt;=8.4CI failing

Since Oct 1Pushed 6mo ago1 watchersCompare

[ Source](https://github.com/delolmo/symfony-router)[ Packagist](https://packagist.org/packages/delolmo/symfony-router)[ Docs](https://github.com/delolmo/symfony-router)[ RSS](/packages/delolmo-symfony-router/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (10)Dependencies (24)Versions (13)Used By (0)

delolmo/symfony-router
======================

[](#delolmosymfony-router)

[![Packagist Version](https://camo.githubusercontent.com/b5c70701beb8241b77ea28f7cc8ecd8d7e8b15433eb5deabeb9bdaa7f3916f7c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64656c6f6c6d6f2f73796d666f6e792d726f757465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/delolmo/symfony-router)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

PSR-15 middleware to use the symfony/routing component and store the route attributes in the request.

Requirements
------------

[](#requirements)

- PHP &gt;=8.4
- A [PSR-7 http library](https://github.com/middlewares/awesome-psr15-middlewares#psr-7-implementations)
- A [PSR-17 http factory](https://www.php-fig.org/psr/psr-17/)

Installation
------------

[](#installation)

This package is installable and autoloadable via Composer as [delolmo/symfony-router](https://packagist.org/packages/delolmo/symfony-router).

```
composer require delolmo/symfony-router
```

Example
-------

[](#example)

Consider Symfony's PhpFileLoader to load route definitions from the following file:

```
# routes.php

use App\Controller\BlogController;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;

$routes = new RouteCollection();
$routes->add('blog_list', new Route('/blog', array(
    'request-handler' => [BlogController::class, 'list']
)));
$routes->add('blog_show', new Route('/blog/{slug}', array(
    'request-handler' => [BlogController::class, 'show']
)));

return $routes;
```

For this example, we will be using `middlewares/utils` for a PSR-15 compliant dispatcher. See [link](https://github.com/middlewares/awesome-psr15-middlewares#dispatcher)for more PSR-15 implementations.

This example uses a basic anonymous function to print the route's attributes:

```
use Laminas\Diactoros\Response\HtmlResponse;
use Laminas\Diactoros\ResponseFactory;
use Laminas\Diactoros\ServerRequest;
use Middlewares\Utils\Dispatcher;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Routing\Loader\PhpFileLoader;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Router;

$fileLocator = new FileLocator(array(__DIR__));

$router = new Router(
    new PhpFileLoader($fileLocator),
    'routes.php',
    array('cache_dir' => __DIR__ . '/cache'),
    new RequestContext('/')
);

$responseFactory = new ResponseFactory();

$dispatcher = new Dispatcher([
    new DelOlmo\Middleware\SymfonyRouterMiddleware($router, $responseFactory),
    function($request, $next) {
        return new HtmlResponse(json_encode($request->getAttributes()));
    }
]);

// Try matching a /blog request
$response = $dispatcher->dispatch(new ServerRequest([], [], '/blog'));

// Will return {"_route": "blog_list", "request-handler" => ["App\Controller\BlogController", "list"]}
$c->get('emitter')->emit($response);

// Try matching a /blog/hello-world request
$response = $dispatcher->dispatch(new ServerRequest([], [], '/blog/hello-world'));

// Will return {"_route": "blog_show", "request-handler" => ["App\Controller\BlogController", "show"], "slug" => "hello-world"}
$c->get('emitter')->emit($response);
```

Options
-------

[](#options)

The constructor takes two arguments:

```
__construct(
    \Symfony\Component\Routing\Router $router,
    \Psr\Http\Message\ResponseFactoryInterface $responseFactory
)
```

The router instance to use and a PSR-17 factory to create the error responses (`404` or `405`).

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance66

Regular maintenance activity

Popularity16

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity87

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 92.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~238 days

Recently: every ~613 days

Total

12

Last Release

204d ago

Major Versions

1.0.7 → 2.02023-02-20

2.1 → 3.02025-11-18

3.0 → 4.02025-12-08

PHP version history (5 changes)1.0PHP &gt;=7.1

2.0PHP &gt;=8.1

2.1PHP ^8.1

3.0PHP ^8.2

4.0PHP &gt;=8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/659868?v=4)[Antonio del Olmo](/maintainers/delolmo)[@delolmo](https://github.com/delolmo)

---

Top Contributors

[![delolmo](https://avatars.githubusercontent.com/u/659868?v=4)](https://github.com/delolmo "delolmo (24 commits)")[![jan-di](https://avatars.githubusercontent.com/u/23323185?v=4)](https://github.com/jan-di "jan-di (1 commits)")[![jiripudil](https://avatars.githubusercontent.com/u/1042159?v=4)](https://github.com/jiripudil "jiripudil (1 commits)")

---

Tags

httpmiddlewarepsr-15psr-7routersymfonysymfony-routerhttppsr-7middlewaresymfonyrouterserverpsr-15symfony routing

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm, Rector

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/delolmo-symfony-router/health.svg)

```
[![Health](https://phpackages.com/badges/delolmo-symfony-router/health.svg)](https://phpackages.com/packages/delolmo-symfony-router)
```

###  Alternatives

[mezzio/mezzio

PSR-15 Middleware Microframework

3913.8M120](/packages/mezzio-mezzio)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M526](/packages/shopware-core)[laminas/laminas-stratigility

PSR-7 middleware foundation for building and dispatching middleware pipelines

577.0M95](/packages/laminas-laminas-stratigility)[middlewares/fast-route

Middleware to use FastRoute

95200.5k15](/packages/middlewares-fast-route)[sunrise/http-router

A powerful solution as the foundation of your project.

17450.9k10](/packages/sunrise-http-router)[mezzio/mezzio-authentication-oauth2

OAuth2 (server) authentication middleware for Mezzio and PSR-7 applications.

28545.4k3](/packages/mezzio-mezzio-authentication-oauth2)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
