Skip to content

Commit 4475c85

Browse files
committed
Merge branch '7.1' into 7.2
* 7.1: [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 ae2fde1 + 405a7bc commit 4475c85

File tree

1 file changed

+1
-78
lines changed

1 file changed

+1
-78
lines changed

Factory/HttpFoundationFactory.php

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -129,89 +129,12 @@ public function createResponse(ResponseInterface $psrResponse, bool $streamed =
129129
$response->setProtocolVersion($psrResponse->getProtocolVersion());
130130

131131
foreach ($cookies as $cookie) {
132-
$response->headers->setCookie($this->createCookie($cookie));
132+
$response->headers->setCookie(Cookie::fromString($cookie));
133133
}
134134

135135
return $response;
136136
}
137137

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

0 commit comments

Comments
 (0)