PHPackages                             denosyscore/routing - 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. [API Development](/categories/api)
4. /
5. denosyscore/routing

ActiveLibrary[API Development](/categories/api)

denosyscore/routing
===================

DenosysCore: Fast PSR-7 Router and Dispatcher PHP package with PSR-15 Middleware support

v0.4.0(9mo ago)9251MITPHPPHP ^8.2

Since May 27Pushed 4mo ago1 watchersCompare

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

READMEChangelog (9)Dependencies (10)Versions (13)Used By (1)

Denosys Routing
===============

[](#denosys-routing)

A highly efficient and flexible routing package for PHP, designed to support modern web applications with minimal overhead.

Features
--------

[](#features)

- **Fast Route Matching**: Utilizes a trie data structure for efficient route matching.
- **Flexible Handlers**: Supports various types of handlers (closures, arrays, strings).
- **PSR-7/PSR-15 Compliant**: Compatible with PSR-7 HTTP messages and PSR-15 middleware.
- **Global Middleware**: Application-wide middleware via `$router->use()`.
- **Middleware Groups &amp; Aliases**: Reusable middleware configurations with named groups.
- **Customizable Invocation Strategies**: Define how route handlers are invoked.
- **Dependency Injection**: Integrates with PSR-11 containers for automatic dependency resolution.
- **Dynamic and Static Routes**: Easily define and handle both dynamic and static routes.
- **Attribute-Based Routing**: Define routes using PHP 8 attributes on controller methods.

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

[](#requirements)

- PHP 8.2 or later

Usage
-----

[](#usage)

Install the package using Composer:

```
composer require denosyscore/routing
```

Install a PSR-7 implementation, such as Laminas Diactoros:

```
composer require laminas/laminas-diactoros
```

Here's a simple example of how to define routes and handle requests:

```
// Create a new router instance
$router = new Denosys\Routing\Router();

// Define a route
$router->get('/', function (): ResponseInterface {
    $response = new Laminas\Diactoros\Response();
    $response->getBody()->write('Hello, World!');
    return $response;
});

// Create Request
$request = Laminas\Diactoros\ServerRequestFactory::fromGlobals();

// Dispatch the request
$response = $router->dispatch($request);

// Output the response
echo $response->getBody();
```

Middleware
----------

[](#middleware)

The Router supports PSR-15 middleware with built-in execution via the Dispatcher.

### Global Middleware

[](#global-middleware)

Use `$router->use()` to register middleware that runs on **every request**:

```
// Global middleware runs on ALL routes
$router->use(LoggingMiddleware::class);
$router->use(CorsMiddleware::class);

// Supports arrays
$router->use([ErrorHandlerMiddleware::class, SessionMiddleware::class]);

// Routes defined before or after - doesn't matter
$router->get('/users', 'UserController@index');
$router->get('/posts', 'PostController@index');
```

Global middleware:

- Executes before any route-specific middleware (outermost layer)
- Applied at dispatch time, so order of `use()` vs route definitions doesn't matter
- Supports class strings, aliases, or middleware instances

### Route Middleware

[](#route-middleware)

Add middleware to specific routes:

```
// Single middleware
$router->get('/admin', 'AdminController@index')
       ->middleware('auth');

// Multiple middleware
$router->get('/api/users', 'UserController@index')
       ->middleware(['auth', 'throttle']);

// Chained middleware (applies to next route only)
$router->middleware('auth')
       ->get('/dashboard', 'DashboardController@index');
```

### Middleware Groups and Aliases

[](#middleware-groups-and-aliases)

Register reusable middleware configurations:

```
// Register aliases
$router->aliasMiddleware('auth', AuthMiddleware::class);
$router->aliasMiddleware('throttle', ThrottleMiddleware::class);

// Register groups (can reference aliases or other groups)
$router->middlewareGroup('web', ['session', 'csrf', 'cookies']);
$router->middlewareGroup('api', ['throttle', 'auth']);

// Use aliases/groups on routes
$router->get('/dashboard', 'DashboardController@index')
       ->middleware('web');

$router->get('/api/users', 'UserController@index')
       ->middleware('api');

// Modify existing groups
$router->prependMiddlewareToGroup('web', 'logging');
$router->appendMiddlewareToGroup('api', 'cors');
```

### Route Groups with Middleware

[](#route-groups-with-middleware)

Apply middleware to all routes in a group:

```
$router->middleware('auth')->group('/admin', function ($group) {
    $group->get('/dashboard', 'AdminController@dashboard');
    $group->get('/users', 'AdminController@users');
});
```

### Excluding Middleware

[](#excluding-middleware)

Use `withoutMiddleware()` to exclude specific middleware from a route:

```
// Exclude from route middleware
$router->get('/test', 'TestController@index')
       ->middleware(['auth', 'logging', 'throttle'])
       ->withoutMiddleware('logging');

// Exclude inherited group middleware
$router->middleware(['auth', 'admin'])->group('/admin', function ($group) {
    $group->get('/dashboard', 'AdminController@dashboard');  // Has auth + admin
    $group->get('/public', 'AdminController@public')
          ->withoutMiddleware('auth');                       // Only has admin
});

// Exclude multiple middleware
$route->withoutMiddleware(['logging', 'throttle']);
```

### Retrieving Middleware Metadata

[](#retrieving-middleware-metadata)

```
$routes = $router->getRouteCollection()->all();
$route = reset($routes);
$middleware = $route->getMiddleware(); // ['auth', 'throttle']
```

Adding Routes
-------------

[](#adding-routes)

You can add routes using various HTTP methods:

```
$router->get('/user/{id}', 'UserController@show');
$router->post('/user', 'UserController@store');
$router->put('/user/{id}', 'UserController@update');
$router->delete('/user/{id}', 'UserController@destroy');
$router->patch('/user/{id}', 'UserController@patch');
$router->options('/user', 'UserController@options');
$router->any('/any-method', 'AnyController@handle');
```

### Full documentation coming soon...

[](#full-documentation-coming-soon)

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/denosyscore/routing/blob/main/CONTRIBUTING.md) for details.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](https://github.com/denosyscore/routing/blob/main/LICENSE.md) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance69

Regular maintenance activity

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity50

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 ~66 days

Recently: every ~7 days

Total

10

Last Release

121d ago

PHP version history (2 changes)v0.1.0PHP ^8.1

v0.2.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f1c1a5b25865f0e67ca1a7d172fed5e6a7b1adb9339674341a8f1b0dbcee652?d=identicon)[deondazy](/maintainers/deondazy)

---

Top Contributors

[![deondazy](https://avatars.githubusercontent.com/u/16439886?v=4)](https://github.com/deondazy "deondazy (254 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/denosyscore-routing/health.svg)

```
[![Health](https://phpackages.com/badges/denosyscore-routing/health.svg)](https://phpackages.com/packages/denosyscore-routing)
```

###  Alternatives

[cakephp/cakephp

The CakePHP framework

8.8k18.5M1.6k](/packages/cakephp-cakephp)[thecodingmachine/graphqlite

Write your GraphQL queries in simple to write controllers (using webonyx/graphql-php).

5723.1M30](/packages/thecodingmachine-graphqlite)[neos/flow

Flow Application Framework

862.0M451](/packages/neos-flow)[neos/flow-development-collection

Flow packages in a joined repository for pull requests.

144179.3k3](/packages/neos-flow-development-collection)[windwalker/framework

The next generation PHP framework.

25639.1k1](/packages/windwalker-framework)[mezzio/mezzio-authentication-oauth2

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

28483.0k2](/packages/mezzio-mezzio-authentication-oauth2)

PHPackages © 2026

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