0 follower

Final Class Yiisoft\Session\SessionMiddleware

InheritanceYiisoft\Session\SessionMiddleware
ImplementsPsr\Http\Server\MiddlewareInterface

Session middleware handles storing session ID into a response cookie and restoring the session associated with the ID from a request cookie.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( Yiisoft\Session\SessionInterface $session )
$session Yiisoft\Session\SessionInterface

                public function __construct(private SessionInterface $session)
{
}

            
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
{
    $requestSessionId = $this->getSessionIdFromRequest($request);
    if ($requestSessionId !== null && $this->session->getId() === null) {
        $this->session->setId($requestSessionId);
    }
    try {
        $response = $handler->handle($request);
    } catch (Throwable $e) {
        $this->session->discard();
        throw $e;
    }
    return $this->commitSession($request, $response);
}