@@ -162,17 +162,18 @@ public function isHeaderOnly()
162162 /**
163163 * Sets a cookie.
164164 *
165- * @param string $name HTTP header name
166- * @param string $value Value for the cookie
167- * @param string $expire Cookie expiration period
168- * @param string $path Path
169- * @param string $domain Domain name
170- * @param bool $secure If secure
171- * @param bool $httpOnly If uses only HTTP
165+ * @param string $name HTTP header name
166+ * @param string $value Value for the cookie
167+ * @param string $expire Cookie expiration period
168+ * @param string $path Path
169+ * @param string $domain Domain name
170+ * @param bool $secure If secure
171+ * @param bool $httpOnly If uses only HTTP
172+ * @param ''|'None'|'Lax'|'Strict' $samesite If uses Same-site cookies
172173 *
173174 * @throws sfException If fails to set the cookie
174175 */
175- public function setCookie ($ name , $ value , $ expire = null , $ path = '/ ' , $ domain = '' , $ secure = false , $ httpOnly = false )
176+ public function setCookie ($ name , $ value , $ expire = null , $ path = '/ ' , $ domain = '' , $ secure = false , $ httpOnly = false , string $ samesite = '' )
176177 {
177178 if (null !== $ expire ) {
178179 if (is_numeric ($ expire )) {
@@ -193,6 +194,7 @@ public function setCookie($name, $value, $expire = null, $path = '/', $domain =
193194 'domain ' => $ domain ,
194195 'secure ' => $ secure ? true : false ,
195196 'httpOnly ' => $ httpOnly ,
197+ 'samesite ' => $ samesite ,
196198 ];
197199 }
198200
@@ -359,7 +361,14 @@ public function sendHttpHeaders()
359361 foreach ($ this ->cookies as $ cookie ) {
360362 $ expire = isset ($ cookie ['expire ' ]) ? $ cookie ['expire ' ] : 0 ;
361363 $ domain = isset ($ cookie ['domain ' ]) ? $ cookie ['domain ' ] : '' ;
362- setrawcookie ($ cookie ['name ' ], $ cookie ['value ' ], $ expire , $ cookie ['path ' ], $ domain , $ cookie ['secure ' ], $ cookie ['httpOnly ' ]);
364+ setrawcookie ($ cookie ['name ' ], $ cookie ['value ' ], [
365+ 'expires ' => $ expire ,
366+ 'path ' => $ cookie ['path ' ],
367+ 'domain ' => $ domain ,
368+ 'secure ' => $ cookie ['secure ' ],
369+ 'httpOnly ' => $ cookie ['httpOnly ' ],
370+ 'samesite ' => $ cookie ['samesite ' ],
371+ ]);
363372
364373 if ($ this ->options ['logging ' ]) {
365374 $ this ->dispatcher ->notify (new sfEvent ($ this , 'application.log ' , [sprintf ('Send cookie "%s": "%s" ' , $ cookie ['name ' ], $ cookie ['value ' ])]));
0 commit comments