Skip to content

对请求进行匹配,放到请求的attribute属性中,keyDispatched::class

php
$psr7Request = $this->coreMiddleware->dispatch($psr7Request);

文件位置:/vendor/hyperf/http-server/src/CoreMiddleware.php

php
public function dispatch(ServerRequestInterface $request): ServerRequestInterface
{
    // 获取路由信息
    $routes = $this->dispatcher->dispatch($request->getMethod(), $request->getUri()->getPath());
    $dispatched = new Dispatched($routes, $this->serverName);
    return RequestContext::set($request)->setAttribute(Dispatched::class, $dispatched);
}

该行默认不触发事件,如果需要触发事件,要设置enable_request_lifecycletrue

php
$this->option?->isEnableRequestLifecycle() && $this->event?->dispatch(new RequestReceived(
        request: $psr7Request,
        response: $psr7Response,
        server: $this->serverName
    ));