sirix/mezzio-radixrouter

RadixRouter integration for Mezzio

1.0.0 2025-07-13 14:24 UTC

This package is auto-updated.

Last update: 2025-07-14 18:49:31 UTC


README

License: MIT

RadixRouter integration for Mezzio, providing high-performance HTTP routing using a radix tree algorithm.

Installation

Install this package via Composer:

composer require sirix/mezzio-radixrouter

Features

  • High-performance routing using a radix tree algorithm
  • PSR-7 and PSR-15 compatible
  • Supports route parameters and optional parameters
  • Route caching for improved performance
  • Fully compatible with Mezzio middleware architecture

Usage

Basic Setup

There are two ways to set up RadixRouter in your Mezzio application:

Automatic Configuration (Recommended)

The easiest way to set up RadixRouter is to use the provided ConfigProvider, which automatically registers all necessary dependencies:

// In config/config.php or similar configuration file
$aggregator = new ConfigAggregator([
    // ... other config providers
    \Sirix\Mezzio\Router\RadixRouter\ConfigProvider::class,
    // ... other config providers
]);

This will automatically register the RadixRouter as the default router implementation for your application.

Manual Configuration

Alternatively, you can manually update your dependencies configuration:

// In config/autoload/dependencies.php or similar configuration file
use Mezzio\Router\RouterInterface;
use Sirix\Mezzio\Router\RadixRouter;
use Sirix\Mezzio\Router\RadixRouterFactory;

return [
    'dependencies' => [
        'factories' => [
            RouterInterface::class => RadixRouterFactory::class,
        ],
    ],
];

Route Configuration

Routes can be defined in your Mezzio application as usual:

// In config/routes.php or similar
$app->get('/api/users', [UserListHandler::class], 'api.users');
$app->get('/api/users/:id', [UserDetailsHandler::class], 'api.user');
$app->post('/api/users', [CreateUserHandler::class]);

Caching Configuration

To enable route caching for improved performance:

// In config/autoload/router.global.php or similar
use Sirix\Mezzio\Router\Enum\CacheConfig;

return [
    'router' => [
        'radix' => [
            CacheConfig::Enabled->value => true,
            CacheConfig::File->value => 'data/cache/radix-cache.php',
        ],
    ]
];

Documentation

For more information about routing in Mezzio, please refer to the Mezzio routing documentation.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Credits