Final Class Yiisoft\Cookies\CookieMiddleware
| Inheritance | Yiisoft\Cookies\CookieMiddleware |
|---|---|
| Implements | Psr\Http\Server\MiddlewareInterface |
Validates and decrypts the values of the request cookie parameters,
encrypts and signs the values of the response Set-Cookie headers.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Cookies\CookieMiddleware | |
| process() | Yiisoft\Cookies\CookieMiddleware |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| ENCRYPT | 'encrypt' | Yiisoft\Cookies\CookieMiddleware | |
| SIGN | 'sign' | Yiisoft\Cookies\CookieMiddleware |
Method Details
| public mixed __construct ( \Psr\Log\LoggerInterface $logger, Yiisoft\Cookies\CookieEncryptor $encryptor, Yiisoft\Cookies\CookieSigner $signer, string[] $cookiesSettings = [] ) | ||
| $logger | \Psr\Log\LoggerInterface |
The logger instance. |
| $encryptor | Yiisoft\Cookies\CookieEncryptor |
The encryptor instance. |
| $signer | Yiisoft\Cookies\CookieSigner |
The signer instance. |
| $cookiesSettings | string[] |
The array keys are cookie name patterns {@see \Yiisoft\Strings\WildcardPattern}, and values are constant values of {@see \Yiisoft\Cookies\ENCRYPT} or {@see \Yiisoft\Cookies\SIGN}. For example:
|
public function __construct(
LoggerInterface $logger,
CookieEncryptor $encryptor,
CookieSigner $signer,
array $cookiesSettings = []
) {
$this->logger = $logger;
$this->encryptor = $encryptor;
$this->signer = $signer;
foreach ($cookiesSettings as $pattern => $action) {
if ($action === self::ENCRYPT) {
$this->encryption[] = (string) $pattern;
continue;
}
if ($action === self::SIGN) {
$this->signature[] = (string) $pattern;
}
}
}
| 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 = $this->decodeRequestCookieParams($request);
$response = $handler->handle($request);
return $this->encodeResponseSetCookieHeaders($response);
}
Signup or Login in order to comment.