@@ -132,89 +132,12 @@ public function createResponse(ResponseInterface $psrResponse, bool $streamed =
132
132
$ response ->setProtocolVersion ($ psrResponse ->getProtocolVersion ());
133
133
134
134
foreach ($ cookies as $ cookie ) {
135
- $ response ->headers ->setCookie ($ this -> createCookie ($ cookie ));
135
+ $ response ->headers ->setCookie (Cookie:: fromString ($ cookie ));
136
136
}
137
137
138
138
return $ response ;
139
139
}
140
140
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
-
218
141
private function createStreamedResponseCallback (StreamInterface $ body ): callable
219
142
{
220
143
return function () use ($ body ) {
0 commit comments