中间件构造函数传参,中间件里如何获取参数

hackxiaoya
491 1 0
1个回答

walkor 打赏

就是普通类构造函数用法,比如传进去后存到类属性里

<?php
namespace app\middleware;

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

class MiddlewareA implements MiddlewareInterface
{

    protected $param1;

    protected $param2;

    public function __construct($param1, $param2)
    {
        $this->param1 = $param1;
        $this->param2 = $param2;
    }

    public function process(Request $request, callable $handler) : Response
    {
        var_dump($this->param1, $this->param2);
        return $handler($request);
    }

}
  • hackxiaoya 2024-05-28

    真的是智商不在线了。明明就在那,我就是没看。哎。

×
🔝