izniburak/router

简单的PHP路由类

v3.0.0 2024-04-14 00:37 UTC

README

  _____  _    _ _____             _____             _            
 |  __ \| |  | |  __ \           |  __ \           | |           
 | |__) | |__| | |__) |  ______  | |__) |___  _   _| |_ ___ _ __
 |  ___/|  __  |  ___/  |______| |  _  // _ \| | | | __/ _ \ '__|
 | |    | |  | | |               | | \ \ (_) | |_| | ||  __/ |   
 |_|    |_|  |_|_|               |_|  \_\___/ \__,_|\__\___|_|   

PHP Router 是一个简单而实用的PHP路由类,它还拥有中间件和控制器等丰富功能。

Tests Total Downloads Latest Stable Version Latest Unstable Version License

功能

  • 支持GET、POST、PUT、DELETE、OPTIONS、PATCH、HEAD、AJAX和任何请求方法
  • 通过 symfony/http-foundation 包轻松访问和管理请求和响应。
  • 支持控制器(示例:HomeController@about)
  • 支持路由中间件的前后处理
  • 静态路由模式
  • 动态路由模式
  • 易于使用的模式
  • 支持添加新的模式(使用正则表达式)
  • 支持命名空间
  • 分组路由
  • 自定义404和异常处理
  • 调试模式(错误消息开启/关闭)

安装

要安装 PHP Router,您可以直接在控制台中运行以下命令,在您的项目路径下

$ composer require izniburak/router

或者,您可以手动将以下行添加到 composer.json 文件中

{
    "require": {
        "izniburak/router": "^2.0"
    }
}

然后,运行以下命令

$ composer install

示例用法

require 'vendor/autoload.php';

use Buki\Router\Router;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

$router = new Router;

// For basic GET URI
$router->get('/', function(Request $request, Response $response) {
    $response->setContent('Hello World');
    return $response;

    # OR
    # return 'Hello World!';
});

// For basic GET URI by using a Controller class.
$router->get('/test', 'TestController@main');

// For auto discovering all methods and URIs
$router->controller('/users', 'UserController');

$router->run();

文档

文档页面: Buki\Router Docs

变更日志: Buki\Router Changelogs

支持

izniburak的主页

izniburak的twitter

许可证

MIT许可证

贡献

  1. 分叉它( https://github.com/izniburak/php-router/fork
  2. 创建您的功能分支(git checkout -b my-new-feature)
  3. 提交您的更改(git commit -am '添加一些功能')
  4. 推送到分支(git push origin my-new-feature)
  5. 创建新的拉取请求

贡献者

  • izniburak İzni Burak Demirtaş - 创建者,维护者