PHPackages                             echo-fusion/routemanager - 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. echo-fusion/routemanager

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

echo-fusion/routemanager
========================

A lightweight and flexible routing package that helps manage HTTP routes in PHP applications. Supports PSR-7 and PSR-15, designed for MVC architecture with middleware integration.

v2.0.0(1y ago)19MITPHPPHP ~8.1.0 || ~8.2.0 || ~8.3.0

Since Oct 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/echo-fusion/routemanager)[ Packagist](https://packagist.org/packages/echo-fusion/routemanager)[ RSS](/packages/echo-fusion-routemanager/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (6)Versions (7)Used By (0)

Route manager
=============

[](#route-manager)

A lightweight and flexible routing package that helps manage HTTP routes in PHP applications. It supports PSR-7 and PSR-15 standards and is designed for MVC architecture with middleware integration.

Install
-------

[](#install)

Via Composer

```
$ composer require echo-fusion/routemanager
```

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

[](#requirements)

The following versions of PHP are supported by this version.

- PHP 8.1
- PHP 8.2
- PHP 8.3

Usages
------

[](#usages)

### Basic Setup

[](#basic-setup)

1. To get started, you can use the RouteMatcher and Router classes directly.

    ```
    use EchoFusion\RouteManager\RouteMatch;
    use EchoFusion\RouteManager\Router;

    $routeMatcher = new RouteMatch();
    $router = new Router($routeMatcher);
    ```
2. Defining Routes Define routes with optional regex constraints on route parameters. The action parameter can be:

- An array (e.g., \[Controller::class, 'method'\])
- A closure

    ```
    use Psr\Http\Message\ServerRequestInterface;

    // Define a simple route
    $router->post(
        name: 'api.store',
        path: '/api',
        action: [ApiController::class, 'store']
    );

    // Define a route with parameter constraints
    $router->get(
        name: 'blog-show',
        path: '/post/{id}/detail/{slug}',
        action: function (int $id, string $slug, ServerRequestInterface $request) {
            // Your action code here
            var_dump($id, $slug);
        },
        constraints: [
            'id' => '[0-9]+',
            'slug' => '[a-z0-9\-]+',
        ]
    );
    ```

3. Dispatching and Executing a Route Once routes are defined, dispatch the request and execute the action if a match is found.

    ```
    try {
        $routeMatch = $router->dispatch($request);

        $action = $routeMatch->getRoute()->getAction();
        $params = array_merge($routeMatch->getParams(), [$request]);

        // Execute the action (callable or controller method)
        return call_user_func_array($action, $params);
    } catch (EchoFusion\RouteManager\Exceptions\RouteNotFoundException $e) {
        // Handle route not found
    } catch (Throwable $exception) {
        // Handle other errors
    }
    ```

Using Provider
--------------

[](#using-provider)

The RouteManagerProvider allows you to integrate Router and RouteMatch instances into a dependency injection container.

1. Register the Provider: Add RouteManagerProvider to your service container.

    ```
    use EchoFusion\RouteManager\Providers\RouteManagerProvider;
    use YourApp\Container;

    $provider = new RouteManagerProvider();
    $provider->register($container);
    ```
2. Define Routes Using Configuration: Configure routes by calling the boot method, passing an array of routes or a configuration file.

    ```
    $routes = [
        'home' => [
            'method' => 'GET',
            'path' => '/',
            'action' => fn () => 'Welcome to the homepage',
        ],
        'blog_show' => [
            'method' => 'GET',
            'path' => '/post/{id}/detail/{slug}',
            'action' => function (int $id, string $slug, ServerRequestInterface $request) {
                // Route action code here
            },
            'constraints' => [
                'id' => '[0-9]+',
                'slug' => '[a-z0-9\-]+',
            ],
        ],
    ];

    $provider->boot($container, $routes);
    ```

    If no routes are provided, the boot method defaults to loading routes from routemanager.config.php.
3. Dispatching a Route: With the routes registered, retrieve the RouterInterface from the container and dispatch it with a request object.

    ```
    use EchoFusion\Contracts\RouteManager\RouterInterface;
    use EchoFusion\RouteManager\Exceptions\RouteNotFoundException;

    try {
        $router = $container->get(RouterInterface::class);
        $routeMatch = $router->dispatch($request);
    } catch (RouteNotFoundException $e) {
        // Handle route not found
    } catch (Throwable $exception) {
        // Handle other errors
    }
    ```

Testing
-------

[](#testing)

Testing includes PHPUnit and PHPStan (Level 7).

```
$ composer test
```

Credits
-------

[](#credits)

Developed and maintained by [Amir Shadanfar](https://github.com/amir-shadanfar).
Connect on [LinkedIn](https://www.linkedin.com/in/amir-shadanfar).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/echo-fusion/routemanager/blob/main/LICENSE) for more information.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance40

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~8 days

Total

6

Last Release

543d ago

Major Versions

v0.x-dev → v1.0.02024-10-01

v1.x-dev → v2.0.02024-11-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/b8a199998d8b5af726b9c5062f97228244822eb7b64b51adf7b050ff4bee378f?d=identicon)[echo-fusion](/maintainers/echo-fusion)

---

Top Contributors

[![echo-fusion](https://avatars.githubusercontent.com/u/182804396?v=4)](https://github.com/echo-fusion "echo-fusion (29 commits)")

---

Tags

psr-7phpmiddlewareroutingpsr-15mvc

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/echo-fusion-routemanager/health.svg)

```
[![Health](https://phpackages.com/badges/echo-fusion-routemanager/health.svg)](https://phpackages.com/packages/echo-fusion-routemanager)
```

###  Alternatives

[laminas/laminas-mvc-middleware

Dispatch middleware pipelines in place of controllers in laminas-mvc.

22659.3k9](/packages/laminas-laminas-mvc-middleware)[mezzio/mezzio-authentication

Authentication middleware for Mezzio and PSR-7 applications

121.6M26](/packages/mezzio-mezzio-authentication)[jimtools/jwt-auth

PSR-15 JWT Authentication middleware, A replacement for tuupola/slim-jwt-auth

20142.3k3](/packages/jimtools-jwt-auth)

PHPackages © 2026

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