定制 gemini/hyperf-router 二次开发

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

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

gemini/hyperf-router

Composer 安装命令:

composer require gemini/hyperf-router

包简介

Some features for Hyperf Router.

关键字:

README 文档

README

PHPUnit

composer require gemini/hyperf-router

路由名字

设置路由名字

  • 路由文件模式
<?php
use Hyperf\HttpServer\Router\Router;

Router::get('/', 'App\Controller\IndexController::index', ['name' => 'index']);
Router::get('/user/{id:\d+}', 'App\Controller\UserController::info', ['name' => 'user.info']);
Router::get('/user', 'App\Controller\UserController::index', ['name' => 'user.list']);
  • 注解模式
<?php

declare(strict_types=1);

namespace App\Controller;

use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use function Gemini\Router\route;

/**
 * @Controller(prefix="/user")
 */
class UserController
{
    /**
     * @GetMapping(path="info/{id:\d+}", options={"name": "user.info"})
     */
    public function info(int $id)
    {
        return [
            'id' => $id,
            'next_path' => route('user.info', ['id' => ++$id]),
        ];
    }
}

根据路有名字读取路径

<?php

use function \Gemini\Router\route;

var_dump(route('index'));
var_dump(route('user.info', [1]));

排除中间件

组件提供了 Gemini\Router\Annotation\WithoutMiddleware 注解,可以方便用户排除不想被触发的中间件。

当在控制器中设置时,会使控制器下所有的方法生效。

当在方法中设置时,只会使当前方法生效。

注意使用 ::class 时,不要忘了引入命名空间

<?php

declare(strict_types=1);

namespace App\Controller;

use Gemini\Router\Annotation\WithoutMiddleware;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use function Gemini\Router\route;
use Han\Utils\Middleware\DebugMiddleware;

/**
 * @Controller(prefix="/user")
 * @WithoutMiddleware(DebugMiddleware::class)
 */
class UserController
{
    /**
     * @GetMapping(path="info/{id:\d+}", options={"name": "user.info"})
     * @WithoutMiddleware({Debug2Middleware::class, Debug3Middleware::class})
     */
    public function info(int $id)
    {
        return [
            'id' => $id,
            'next_path' => route('user.info', ['id' => ++$id]),
        ];
    }
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固