定制 solophp/router 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.

Latest Version on Packagist PHP Version License

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

Full Documentation

Requirements

  • PHP 8.1+

License

MIT License. See LICENSE for details.

统计信息

  • 总下载量: 103
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 1

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固