Skip to content

Commit 405a7bc

Browse files
committed
Merge branch '6.4' into 7.1
* 6.4: [Serializer] Remove redundant @internal tags from traceable classes Fix conversion of partitioned cookies in the PSR-7 bridge [Validator] added Polish translation for units 116-119 Revert stateless check [Console] Fix side-effects from running bash completions skip transient Redis integration tests on AppVeyor
2 parents 1365d10 + 74835ba commit 405a7bc

File tree

1 file changed

+1
-78
lines changed

1 file changed

+1
-78
lines changed

Factory/HttpFoundationFactory.php

+1-78
Original file line numberDiff line numberDiff line change
@@ -132,89 +132,12 @@ public function createResponse(ResponseInterface $psrResponse, bool $streamed =
132132
$response->setProtocolVersion($psrResponse->getProtocolVersion());
133133

134134
foreach ($cookies as $cookie) {
135-
$response->headers->setCookie($this->createCookie($cookie));
135+
$response->headers->setCookie(Cookie::fromString($cookie));
136136
}
137137

138138
return $response;
139139
}
140140

141-
/**
142-
* Creates a Cookie instance from a cookie string.
143-
*
144-
* Some snippets have been taken from the Guzzle project: https://github.com/guzzle/guzzle/blob/5.3/src/Cookie/SetCookie.php#L34
145-
*
146-
* @throws \InvalidArgumentException
147-
*/
148-
private function createCookie(string $cookie): Cookie
149-
{
150-
foreach (explode(';', $cookie) as $part) {
151-
$part = trim($part);
152-
153-
$data = explode('=', $part, 2);
154-
$name = $data[0];
155-
$value = isset($data[1]) ? trim($data[1], " \n\r\t\0\x0B\"") : null;
156-
157-
if (!isset($cookieName)) {
158-
$cookieName = $name;
159-
$cookieValue = $value;
160-
161-
continue;
162-
}
163-
164-
if ('expires' === strtolower($name) && null !== $value) {
165-
$cookieExpire = new \DateTime($value);
166-
167-
continue;
168-
}
169-
170-
if ('path' === strtolower($name) && null !== $value) {
171-
$cookiePath = $value;
172-
173-
continue;
174-
}
175-
176-
if ('domain' === strtolower($name) && null !== $value) {
177-
$cookieDomain = $value;
178-
179-
continue;
180-
}
181-
182-
if ('secure' === strtolower($name)) {
183-
$cookieSecure = true;
184-
185-
continue;
186-
}
187-
188-
if ('httponly' === strtolower($name)) {
189-
$cookieHttpOnly = true;
190-
191-
continue;
192-
}
193-
194-
if ('samesite' === strtolower($name) && null !== $value) {
195-
$samesite = $value;
196-
197-
continue;
198-
}
199-
}
200-
201-
if (!isset($cookieName)) {
202-
throw new \InvalidArgumentException('The value of the Set-Cookie header is malformed.');
203-
}
204-
205-
return new Cookie(
206-
$cookieName,
207-
$cookieValue,
208-
$cookieExpire ?? 0,
209-
$cookiePath ?? '/',
210-
$cookieDomain ?? null,
211-
isset($cookieSecure),
212-
isset($cookieHttpOnly),
213-
true,
214-
$samesite ?? null
215-
);
216-
}
217-
218141
private function createStreamedResponseCallback(StreamInterface $body): callable
219142
{
220143
return function () use ($body) {

0 commit comments

Comments
 (0)