惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
L
LangChain Blog
aimingoo的专栏
aimingoo的专栏
IT之家
IT之家
B
Blog
博客园_首页
博客园 - 司徒正美
有赞技术团队
有赞技术团队
博客园 - 聂微东
I
InfoQ
美团技术团队
GbyAI
GbyAI
阮一峰的网络日志
阮一峰的网络日志
H
Help Net Security
大猫的无限游戏
大猫的无限游戏
MyScale Blog
MyScale Blog
WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
A
About on SuperTechFans
人人都是产品经理
人人都是产品经理
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Cloudflare Blog

博客园 - zh7314

Go 1.23 → 1.26 升级检查文档 Pimcore 版本功能对比表(Community / Professional / Enterprise) typephp的编译核心phpx原理解析 typephp的编译原理 golang多版本控制工具支持Linux/macOS/Windows dbx低性能消耗的支持window/mac/docker的数据库客户端 关于headless和低代码平台的一些思考 docker日志监控dozzle,高性能,性能消耗小 pimcore 12版本的命令 阿里云 nas服务挂了导致docker挂载目录不存,docker无法重启和停止容器 symfony+swoole性能测试 关于小米手机使用 microsoft authenticator 无法扫码成功的解决方案 fastapi的构建cms,推荐fastapi集成框架 s3rius/FastAPI-template python 现代化包管理工具uv安装和使用 博文阅读密码验证 - 博客园 laravel在cli模式下输出格式漂亮一些 laravel计划任务和异步队列任务,拆分成不同队列,减少计划任务系统压力 debug redis里面的lua脚本 laravel chunkById导出数据乱序问题 PHP 真正异步编程即将到来 首个 alpha 版本已经发布 (转) 关于his esb企业服务总线系统设计 多渠道订单,对应渠道公司的提现主体,如何设计系统 laravel 主表和从表一对一,从表是要多个选取最新的一条,性能优化 sourcetree无法获取远程所有的tag 支付宝沙盒模式商家转账经常出现 响应异常: 解包错误 laravel 使用异步队列,context带的上下文造成反序列化出问题 hyperf 的默认创建项目部署k8s docker缺失文件 在laravel使用注解自动注册 线上就医全流程医药机构接入文档接口代码-医保就医接口php-demo版本 windows lm studio 0.3.8无法下载模型,更换镜像
hyperf 查看所有路由的命令
zh7314 · 2025-05-06 · via 博客园 - zh7314

hyperf的版本
"hyperf/framework": "~3.1.0",

<?php

declare(strict_types=1);

namespace App\Commands;

use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Psr\Container\ContainerInterface;
use Hyperf\Contract\ConfigInterface;
use Hyperf\HttpServer\Router\DispatcherFactory;
use Symfony\Component\Console\Command\Command as SymfonyCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Helper\Table;

#[Command]
class RouteListCommand extends HyperfCommand
{
    public function __construct(protected ContainerInterface $container)
    {
        parent::__construct('route:list');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $factory = $this->container->get(DispatcherFactory::class);
        $router = $factory->getRouter('http');
        $routes = $router->getData();

        $config = $this->container->get(ConfigInterface::class);
        $server = $config->get('server.servers.0', ['host' => '0.0.0.0', 'port' => 9501]);
        $domain = "http://{$server['host']}:{$server['port']}";


        $rows = [];
        foreach ($routes as $routeGroup) {
            // POST GET
            if (is_array($routeGroup) && !empty($routeGroup)) {
                foreach ($routeGroup as $httpMethod => $routeItems) {
                    // route object
                    if (is_array($routeItems) && !empty($routeItems)) {
                        foreach ($routeItems as $url => $routeItem) {
                            $uri = $domain . $routeItem->route;
                            $rows[] = [
                                $httpMethod,
                                $uri,
                                $this->formatHandler($routeItem->callback),
                            ];
                        }
                    }
                }
            }

        }

        $table = new Table($output);
        $table->setHeaders(['Method', 'URI', 'Handler'])
            ->setRows($rows);
        $table->render();

        return SymfonyCommand::SUCCESS;
    }

    private function formatHandler($handler): string
    {
        if (is_array($handler) && isset($handler[0], $handler[1])) {
            return $handler[0] . '@' . $handler[1];
        }
        return is_string($handler) ? $handler : 'Closure';
    }
}


执行命令: php bin/hyperf.php route:list

+--------+---------------------------------------------------------+--------------------------------------------------------+
| Method | URI                                                     | Handler                                                |
+--------+---------------------------------------------------------+--------------------------------------------------------+
| POST   | http://0.0.0.0:9501/api/driver/common/driverLogin/xx    | App\API\Common\Controllers\DriverLoginController@xx    |
| POST   | http://0.0.0.0:9501/api/driver/common/tool/xx           | App\API\Common\Controllers\ToolController@xx           |
| POST   | http://0.0.0.0:9501/api/driver/common/region/xx         | App\API\Common\Controllers\ToolController@xx           |
| POST   | http://0.0.0.0:9501/api/driver/logic/driverLog/xx       | App\API\Logic\Controllers\DriverLogController@xx       |
+--------+---------------------------------------------------------+--------------------------------------------------------+