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