Download the PHP package mitsuki/router without Composer
On this page you can find all versions of the php package mitsuki/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mitsuki/router
More information about mitsuki/router
Files in mitsuki/router
Package router
Short Description A lightweight and high-performance PHP router for the Mitsuki framework, powered by Symfony Routing components.
License MIT
Informations about the package router
Mitsuki Router
Mitsuki is a modern HTTP routing engine for PHP, powered by Symfony Routing/HttpKernel and PHP 8 attributes. It provides:
- Automatic controller discovery
- Attribute-based routing (
#[Controller],#[Route]) - PSR-11 container integration
- HttpKernel-compatible controller resolution
- Compiled routes caching
Installation
The router relies on Symfony Routing, HttpFoundation, HttpKernel, Filesystem, and a PSR-11 container.
Core Concepts
Attributes
#[Controller('prefix')]on classes#[Route('name', 'path', methods)]on methods
Architecture
Router Class
Namespace: Mitsuki\Hermite\Router
Responsibilities:
- Load routes from compiled cache or controller scanning
- Build Symfony
RouteCollection - Delegate matching to
UrlMatcher - Resolve HttpKernel-compatible controller callable
Workflow
-
load()- If
cache_routes.phpexists → load routes from cache - Otherwise → use
ControllerResolverto discover controllers - Analyze attributes, build routes, write cache
- If
getCallable(Request $request)- Updates
RequestContext::setMethod() - Uses
UrlMatcherto match URL + method - Binds route parameters to request attributes
- Fetches controller instance via container
- Returns
[instance, 'method']for HttpKernel
- Updates
Path Concatenation
In getRoutesFromControllers():
- Class prefix:
#[Controller('posts')] - Method path:
#[Route('posts.show', '{id}', ['GET'])] - Normalized result:
/posts/{id}
Normalization:
- Removes multiple
/ - Strips trailing
/ - Falls back to
/if empty
Container Integration
Example with PHP-DI:
Request Lifecycle
Usage Example
Testing
Tested with PestPHP (95%+ coverage).
Integration tests:
Run tests with coverage:
Best Practices
- Always define unique route names in
#[Route] - Use consistent prefixes via
#[Controller('prefix')] - Write tests for each CRUD endpoint
- Enable route caching in production for optimal performance
Roadmap
- Route-specific middleware support
- Configurable route groups (auth, API, etc.)
- URL generation from route names
- Request validation & DTO integration
📄 License
This project is licensed under the MIT License.
Maintained by Zgenius Matondo GitHub: https://github.com/zgeniuscoders
All versions of router with dependencies
symfony/routing Version ^8.0
symfony/filesystem Version ^8.0
symfony/http-kernel Version ^8.0
mitsuki/contracts Version ^1.0
psr/container Version ^2.0
mitsuki/attributes Version ^1.0