solophp/router
最新稳定版本:v3.2.2
Composer 安装命令:
composer require solophp/router
包简介
A high-performance PHP router with middleware support, route groups, named routes, and advanced optional segment patterns.
README 文档
README
High-performance PHP router with middleware support, route groups, named routes, and advanced optional segment patterns.
Features
- High Performance — Static routes use O(1) hash lookup, pattern caching
- Fluent API — Chainable
->name()and->middleware()methods - Route Groups — Shared prefixes and middleware with nesting
- Middleware — Single and multiple middleware per route/group
- Advanced Patterns — Optional segments anywhere, nested optionals, regex constraints
- Named Routes — Easy route referencing for URL generation
- HEAD Support — Automatic fallback to GET routes per RFC 7231
Installation
composer require solophp/router
Quick Example
use Solo\Router\RouteCollector; $router = new RouteCollector(); // Simple routes $router->get('/users', [UserController::class, 'index']); $router->get('/users/{id}', [UserController::class, 'show']); // Route with middleware and name $router->post('/posts', [PostController::class, 'store']) ->middleware(AuthMiddleware::class) ->name('posts.store'); // Route groups $router->group('/admin', function(RouteCollector $router) { $router->get('/dashboard', [AdminController::class, 'dashboard']); $router->get('/users', [AdminController::class, 'users']); }, [AuthMiddleware::class]); // Match request $match = $router->match('GET', '/users/123'); if ($match) { $handler = $match['handler']; $params = $match['params']; // ['id' => '123'] $middlewares = $match['middlewares']; $name = $match['name']; // route name or null }
Documentation
- Installation
- Quick Start
- Handlers
- Route Parameters
- Optional Segments
- Route Groups
- Middleware
- Named Routes
- API Reference
Requirements
- PHP 8.1+
License
MIT License. See LICENSE for details.
统计信息
- 总下载量: 103
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2024-12-15