webman router获取getCallback(失败)

caizi

问题描述

Webman-framework 从1.43升级到 v1.5.0时,中间件获取路由参数报错,之前1.43可以直接获取

程序代码

public function process(Request $request, callable $handler): Response
    {
        $route = $request->route;
       var_export($route->getCallback());
        $response = $handler($request);
        return $response;

报错信息

TypeError: Webman\Route\Route::getCallback(): Return value must be of type ?callable, string returned in /Users/test/manadmin/vendor/workerman/webman-framework/src/Route/Route.php:131

public function process(Request $request, callable $handler): Response
{
$route = $request->route;
var_export($route->getCallback());
$response = $handler($request);
return $response;


#### 参考文档

中间件

<?php
namespace app\middleware;

use Webman\MiddlewareInterface;
use Webman\Http\Response;
use Webman\Http\Request;

class Hello implements MiddlewareInterface
{
public function process(Request $request, callable $handler) : Response
{
$route = $request->route;
// 如果请求没有匹配任何路由(默认路由除外),则 $request->route 为 null
// 假设浏览器访问地址 /user/111,则会打印如下信息
if ($route) {
var_export($route->getPath()); // /user/{uid}
var_export($route->getMethods()); // ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD','OPTIONS']
var_export($route->getName()); // user_view
var_export($route->getMiddleware()); // []
var_export($route->getCallback()); // ['app\controller\UserController', 'view']
var_export($route->param()); // ['uid'=>111]
var_export($route->param('uid')); // 111
}
return $handler($request);
}
}



#### 操作系统及workerman/webman等框架组件具体版本

macos php8.1 Webman-framework v1.5.0
550 1 0
1个回答

walkor 打赏

Webman-framework 更新到 v1.5.1

年代过于久远,无法发表回答
×
🔝