/** * Parse all cookies set on the response * * - If string - leave alone (this is expected to be a fully rendered cookie string with expiry, etc) * - If instance of "SetCookie" - stringify * - If instance of "SetCookie" and OpaqueProperty - stringify * * Cookies that are "SetCookie" will be encrypted if possible, or not if configured to not encrypt. * * Cookies will be automatically deduped. * * @param SetCookie[]|string[] $reqCookies * * @return string[] */ private function encryptAndRenderCookies($resCookies) { $renderable = []; foreach ($resCookies as $cookie) { if (is_string($cookie)) { $cookie = SetCookie::fromSetCookieString($cookie); } if ($cookie instanceof SetCookie) { $val = $cookie->getValue(); if ($val instanceof OpaqueProperty) { $val = $val->getValue(); } if (!in_array($cookie->getName(), $this->unencryptedCookies)) { $val = $this->encryption->encrypt($val); } $renderable[$cookie->getName()] = (string) $cookie->withValue($val); } } return $renderable; }
/** * Create SetCookies from a Response. * * @param ResponseInterface $response * @return SetCookies */ public static function fromResponse(ResponseInterface $response) { return new static(array_map(function ($setCookieString) { return SetCookie::fromSetCookieString($setCookieString); }, $response->getHeader(static::SET_COOKIE_HEADER))); }