response = $response; $this->request = $request; } public function saveAuthentication(IIdentity $identity): void { $uid = (string) $identity->getId(); if (strlen($uid) < self::MinLength) { throw new \LogicException('UID is too short.'); } $this->uid = $uid; $this->response->setCookie( $this->cookieName, $uid, $this->cookieExpiration, domain: $this->cookieDomain, sameSite: $this->cookieSameSite, ); } public function clearAuthentication(bool $clearIdentity): void { $this->uid = ''; $this->response->deleteCookie( $this->cookieName, domain: $this->cookieDomain, ); } public function getState(): array { if ($this->uid === null) { $uid = $this->request->getCookie($this->cookieName); $this->uid = is_string($uid) && strlen($uid) >= self::MinLength ? $uid : ''; } return $this->uid ? [true, new Nette\Security\SimpleIdentity($this->uid), null] : [false, null, null]; } public function setExpiration(?string $expire, bool $clearIdentity): void { $this->cookieExpiration = $expire; } public function setCookieParameters( ?string $name = null, ?string $domain = null, ?string $sameSite = null, ) { $this->cookieName = $name ?? $this->cookieName; $this->cookieDomain = $domain ?? $this->cookieDomain; $this->cookieSameSite = $sameSite ?? $this->cookieSameSite; } }