sirix / yii-radixrouter
Yii router RadixRouter adapter
Fund package maintenance!
sirix777
buymeacoffee.com/sirix
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/sirix/yii-radixrouter
Requires
- php: 8.2 - 8.5
- psr/http-message: ^1.0 || ^2.0
- psr/simple-cache: ^2.0 || ^3.0
- wilaak/radix-router: ^3.5
- yiisoft/http: ^1.2
- yiisoft/router: ^4
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.8
- maglnet/composer-require-checker: ^4.7.1
- nyholm/psr7: ^1.8
- phpbench/phpbench: ^1.3
- phpunit/phpunit: ^11.5.46
- psr/container: ^2.0.2
- yiisoft/di: ^1.4
- yiisoft/test-support: ^3.1
Provides
README
A high-performance Radix Tree based router implementation for the Yii Framework (Yii3), using the wilaak/radix-router under the hood.
This package is based on the yiisoft/router-fastroute implementation.
Installation
The package can be installed with Composer:
composer require sirix/yii-radixrouter
Important
This package provides its own DI configuration for UrlMatcherInterface and UrlGeneratorInterface.
To avoid "Duplicate key" errors during configuration building, you must not have another router implementation (like yiisoft/router-fastroute) enabled at the same time.
If you have yiisoft/router-fastroute installed, remove it:
composer remove yiisoft/router-fastroute
Route Formats
This adapter supports both the standard Yii-style route patterns and the native Radix Router format.
Yii-style Support
You can use the familiar {param} syntax, including optional regex parts. The matcher automatically converts these into a format compatible with the underlying Radix Tree.
Warning
The underlying Radix Router does not support regular expressions for parameter matching.
When using Yii-style syntax with regex (e.g., {id:\d+}), the regular expression part is ignored and stripped during conversion to Radix format.
All parameters are treated as simple string segments.
| Yii Format | Internal Radix Format | Description |
|---|---|---|
/post/{id} |
/post/:id |
Standard parameter |
/user/{name:\w+} |
/user/:name |
Parameter with regex (regex is ignored) |
/post/[{id}] |
/post/:id? |
Optional parameter |
/site/post[/{id}] |
/site/post/:id? |
Optional segment |
/site[/{name}[/{id}]] |
/site/:name?/:id? |
Nested optional segments |
Native Radix Router Formats
For advanced use cases, you can use native Radix Router parameters directly in your route definitions.
| Native Format | Description | Example |
|---|---|---|
:param |
Required parameter | /blog/:slug |
:param? |
Optional parameter | /archive/:year? |
:param* |
Optional wildcard (0 or more segments) | /downloads/:path* |
:param+ |
Required wildcard (1 or more segments) | /assets/:file+ |
For more details on the native format, see the Radix Router documentation.
Usage
The package is designed to work seamlessly with Yii3's DI container.
DI Configuration
If you are using yiisoft/config, the configuration will be applied automatically. Otherwise, you can manually configure the UrlMatcherInterface and UrlGeneratorInterface.
Parameters
Configuration is available via params.php:
return [ 'sirix/yii-radixrouter' => [ 'enableCache' => true, 'encodeRaw' => true, 'scheme' => null, 'host' => null, ], ];
License
The Yii Radix Router is free software. It is released under the terms of the MIT License. Please see LICENSE for more information.