cookies = $cookies; } function getId() { return $this->cookies->get(self::COOKIE_NAME) ?: null; } function init() { if (headers_sent()) { return false; } $id = $this->getId() ?: Security::generateRandomString(self::KEY_LENGTH); $this->setCookie($id); return true; } function destroy() { if ($this->getId() === null) { return; } $this->cookies->delete(self::COOKIE_NAME); } private function setCookie($id) { $this->cookies->set( self::COOKIE_NAME, $id, [ 'expires' => time() + self::COOKIE_EXPIRATION, 'path' => '/', ] ); } }