0 follower

Final Class Yiisoft\HttpMiddleware\TagRequest\TagRequestMiddleware

InheritanceYiisoft\HttpMiddleware\TagRequest\TagRequestMiddleware
ImplementsPsr\Http\Server\MiddlewareInterface

Tags request with a value that could be later used for identifying it.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string $attributeName 'requestTag', Yiisoft\HttpMiddleware\TagRequest\TagProvider\TagProviderInterface $tagProvider = new TimeBasedTagProvider() )
$attributeName string

The name of the attribute to store the tag in.

$tagProvider Yiisoft\HttpMiddleware\TagRequest\TagProvider\TagProviderInterface

The tag provider.

                public function __construct(
    private readonly string $attributeName = 'requestTag',
    private readonly TagProviderInterface $tagProvider = new TimeBasedTagProvider(),
) {
}

            
process() public method

public \Psr\Http\Message\ResponseInterface process ( \Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Server\RequestHandlerInterface $handler )
$request \Psr\Http\Message\ServerRequestInterface
$handler \Psr\Http\Server\RequestHandlerInterface

                public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
    $request = $request->withAttribute(
        $this->attributeName,
        $this->tagProvider->get(),
    );
    return $handler->handle($request);
}