webman 新建的 middleware 报错?

andyzu

webman 里,为了学习中间件,我在 middleware 目录里新建了一个 TokenVerifyMiddleware.php 中间件:

<?php
    namespace app\middleware;

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

    class TokenVerifyMiddleware implements MiddlewareInterface
    {
        public function process(Request $request, callable $handler) : Response
        {
            return $handler($request);

        }
    }

然后在 config 目录里的 middleware.php 里:

<?php

return [
    // token 验证
    app\middleware\TokenVerifyMiddleware::class,
];

然后我用 postman 调用我写的接口一直loading 无反应,查看 workerman.log

pid:46948 RuntimeException: Bad middleware config in /Users/z/Desktop/webserver/webmanAPI/vendor/workerman/webman-framework/src/Middleware.php:44
Stack trace:
#0 /Users/z/Desktop/webserver/webmanAPI/support/bootstrap.php(70): Webman\Middleware::load(Array)
#1 /Users/z/Desktop/webserver/webmanAPI/vendor/workerman/webman-framework/src/support/App.php(104): require_once('/Users/andyzu/D...')
#2 /Users/z/Desktop/webserver/webmanAPI/vendor/workerman/workerman/Worker.php(2494): support\App::support\{closure}(Object(Workerman\Worker))
#3 /Users/z/Desktop/webserver/webmanAPI/vendor/workerman/workerman/Worker.php(1633): Workerman\Worker->run()
#4 /Users/z/Desktop/webserver/webmanAPI/vendor/workerman/workerman/Worker.php(1426): Workerman\Worker::forkOneWorkerForLinux(Object(Workerman\Worker))
#5 /Users/z/Desktop/webserver/webmanAPI/vendor/workerman/workerman/Worker.php(1400): Workerman\Worker::forkWorkersForLinux()
#6 /Users/z/Desktop/webserver/webmanAPI/vendor/workerman/workerman/Worker.php(560): Workerman\Worker::forkWorkers()
#7 /Users/z/Desktop/webserver/webmanAPI/vendor/workerman/webman-framework/src/support/App.php(131): Workerman\Worker::runAll()
#8 /Users/z/Desktop/webserver/webmanAPI/start.php(4): support\App::run()
#9 {main}

我的中间件里啥复杂的也没写,配置也按照文档来,为啥报错?求大神们指点!

684 2 0
2个回答

fgt1t5y

是这样写的

截图

admin
return [
    // 全局中间件
    '' => [
        app\middleware\AuthCheckTest::class,
        app\middleware\AccessControlTest::class,
    ],
    // api应用中间件(应用中间件仅在多应用模式下有效)
    'api' => [
        app\middleware\ApiOnly::class,
    ]
];
  • 暂无评论
年代过于久远,无法发表回答
×
🔝