bimacoding/router

2.5 2022-12-06 02:00 UTC

This package is auto-updated.

Last update: 2024-09-06 05:50:05 UTC


README

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

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

特性

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

安装

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

$ composer require bimacoding/router

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

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

然后,运行以下命令

$ composer install

示例用法

require 'vendor/autoload.php';

use Alza\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();

文档

文档页面: Alza\Router 文档

变更日志: Alza\Router 变更日志

支持

bimacoding 的主页

bimacoding 的推特

许可证

MIT 许可证

贡献

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

贡献者