pivotphp/core-routing
最新稳定版本:1.0.0
Composer 安装命令:
composer require pivotphp/core-routing
包简介
Modular, high-performance routing system for PivotPHP - Express.js-inspired API with PSR compliance
README 文档
README
Modular, high-performance routing system for PivotPHP with Express.js-inspired API and full PSR compliance.
Features
- Express.js-Inspired API: Familiar routing patterns (
get(),post(),put(),delete(), etc.) - High Performance: Multi-level caching, route indexing, and memory optimization
- PSR Compliant: Full PSR-7 (HTTP), PSR-15 (Middleware), PSR-6/PSR-16 (Cache) support
- Plugin System: Extensible architecture with built-in plugins
- File Caching: Persistent route compilation for faster startup
- Static File Serving: Express-style static file management
- Type Safety: Strict typing with PHPStan Level 9 compliance
- Modular: Use independently or integrate with PivotPHP Core
Installation
composer require pivotphp/core-routing
Quick Start
use PivotPHP\Routing\Router; // Create router instance $router = new Router(); // Define routes $router->get('/users', function($req, $res) { return $res->json(['users' => []]); }); $router->post('/users', [UserController::class, 'store']); // Route with parameters $router->get('/users/:id', function($req, $res) { $userId = $req->param('id'); return $res->json(['user' => ['id' => $userId]]); }); // Route groups with prefix and middleware $router->group('/api', function() use ($router) { $router->get('/status', function($req, $res) { return $res->json(['status' => 'ok']); }); }, $authMiddleware); // Match route $route = $router::identify($method, $path);
Advanced Features
Plugin System
use PivotPHP\Routing\Plugins\MetricsPlugin; $router->registerPlugin(new MetricsPlugin());
File Caching
use PivotPHP\Routing\Cache\FileCacheStrategy; $cache = new FileCacheStrategy('/path/to/cache'); $router->setCacheStrategy($cache); // Warm cache $router->warmCache();
Static Files
use PivotPHP\Routing\Static\StaticFileManager; $router->static('/public', __DIR__ . '/public');
Requirements
- PHP 8.1 or higher
- PSR-7 HTTP Message implementation
- PSR-15 HTTP Server Handler implementation
Testing
# Run all tests composer test # Run with coverage composer test:coverage # Static analysis composer phpstan # Code style check composer cs:check # Fix code style composer cs:fix # All quality checks composer quality:check
Performance
PivotPHP Core Routing is designed for high performance:
- Multi-level caching: Exact match, compiled routes, pattern cache
- Route indexing: O(1) group lookups, method-based indexing
- Memory management: Automatic garbage collection, usage tracking
- Static/Dynamic separation: Optimized matching strategies
Documentation
License
MIT License - see LICENSE file for details.
Community
Credits
Created by Carlos Fernandes and the PivotPHP community.
Inspired by Express.js routing and built with modern PHP best practices.
统计信息
- 总下载量: 27
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-15