2727 * reassign this new instance to a new variable to capture it.
2828 *
2929 * ```php
30- * $cookie = Cookie::create ('test_cookie', 'test_value');
30+ * $cookie = new Cookie('test_cookie', 'test_value');
3131 * $cookie->getName(); // test_cookie
3232 *
3333 * $cookie->withName('prod_cookie');
@@ -149,8 +149,8 @@ public static function setDefaults($config = [])
149149 $ newDefaults = $ config ;
150150 }
151151
152- // This array union ensures that even if passed `$config`
153- // is not `CookieConfig` or `array`, no empty defaults will occur.
152+ // This array union ensures that even if passed `$config` is not
153+ // `CookieConfig` or `array`, no empty defaults will occur.
154154 self ::$ defaults = $ newDefaults + $ oldDefaults ;
155155
156156 return $ oldDefaults ;
@@ -197,21 +197,19 @@ public static function fromHeaderString(string $cookie, bool $raw = false)
197197 $ data [strtolower ($ attr )] = $ val ;
198198 }
199199
200- return static :: create ($ name , $ value , $ data );
200+ return new static ($ name , $ value , $ data );
201201 }
202202
203203 /**
204- * Create Cookie objects on the fly .
204+ * Construct a new Cookie instance .
205205 *
206- * @param string $name
207- * @param string $value
208- * @param array<string, mixed> $options
206+ * @param string $name The cookie's name
207+ * @param string $value The cookie's value
208+ * @param array<string, mixed> $options The cookie's options
209209 *
210210 * @throws CookieException
211- *
212- * @return static
213211 */
214- public static function create (string $ name , string $ value = '' , array $ options = [])
212+ final public function __construct (string $ name , string $ value = '' , array $ options = [])
215213 {
216214 $ options += self ::$ defaults ;
217215
@@ -224,56 +222,14 @@ public static function create(string $name, string $value = '', array $options =
224222 unset($ options ['max-age ' ]);
225223 }
226224
227- return new static (
228- $ name ,
229- $ value ,
230- $ options ['expires ' ],
231- $ options ['prefix ' ],
232- $ options ['path ' ],
233- $ options ['domain ' ],
234- $ options ['secure ' ],
235- $ options ['httponly ' ],
236- $ options ['raw ' ],
237- $ options ['samesite ' ]
238- );
239- }
240-
241- /**
242- * Construct a new Cookie instance.
243- *
244- * @param string $name The name of the cookie
245- * @param string $value The value of the cookie
246- * @param DateTimeInterface|integer|string $expires The time the cookie expires
247- * @param string|null $prefix The prefix of the cookie
248- * @param string|null $path The path on the server in which the cookie is available
249- * @param string|null $domain The domain in which the cookie is available
250- * @param boolean $secure Whether to send back the cookie over HTTPS
251- * @param boolean $httponly Whether to forbid JavaScript access to cookies
252- * @param boolean $raw Whether the cookie should be sent with no URL encoding
253- * @param string $samesite Whether the cookie will be available for cross-site requests
254- *
255- * @throws CookieException
256- */
257- final public function __construct (
258- string $ name ,
259- string $ value = '' ,
260- $ expires = 0 ,
261- string $ prefix = null ,
262- string $ path = null ,
263- string $ domain = null ,
264- bool $ secure = false ,
265- bool $ httponly = true ,
266- bool $ raw = false ,
267- string $ samesite = self ::SAMESITE_LAX
268- )
269- {
270225 // to retain BC
271- $ prefix = $ prefix ?: self ::$ defaults ['prefix ' ];
272- $ path = $ path ?: self ::$ defaults ['path ' ];
273- $ domain = $ domain ?: self ::$ defaults ['domain ' ];
274- $ secure = $ secure ?: self ::$ defaults ['secure ' ];
275- $ httponly = $ httponly ?: self ::$ defaults ['httponly ' ];
276- $ samesite = $ samesite ?: self ::$ defaults ['samesite ' ];
226+ $ prefix = $ options ['prefix ' ] ?: self ::$ defaults ['prefix ' ];
227+ $ path = $ options ['path ' ] ?: self ::$ defaults ['path ' ];
228+ $ domain = $ options ['domain ' ] ?: self ::$ defaults ['domain ' ];
229+ $ secure = $ options ['secure ' ] ?: self ::$ defaults ['secure ' ];
230+ $ httponly = $ options ['httponly ' ] ?: self ::$ defaults ['httponly ' ];
231+ $ samesite = $ options ['samesite ' ] ?: self ::$ defaults ['samesite ' ];
232+ $ raw = $ options ['raw ' ] ?: self ::$ defaults ['raw ' ];
277233
278234 $ this ->validateName ($ name , $ raw );
279235 $ this ->validatePrefix ($ prefix , $ secure , $ path , $ domain );
@@ -282,7 +238,7 @@ final public function __construct(
282238 $ this ->prefix = $ prefix ;
283239 $ this ->name = $ name ;
284240 $ this ->value = $ value ;
285- $ this ->expires = static ::convertExpiresTimestamp ($ expires );
241+ $ this ->expires = static ::convertExpiresTimestamp ($ options [ ' expires ' ] );
286242 $ this ->path = $ path ;
287243 $ this ->domain = $ domain ;
288244 $ this ->secure = $ secure ;
@@ -438,7 +394,7 @@ public function isRaw(): bool
438394 */
439395 public function getOptions (): array
440396 {
441- // This is the order of options in `setcookie`. DO NOT change .
397+ // This is the order of options in `setcookie`. DO NOT CHANGE .
442398 return [
443399 'expires ' => $ this ->expires ,
444400 'path ' => $ this ->path ,
@@ -496,7 +452,7 @@ public function withValue(string $value)
496452 /**
497453 * {@inheritDoc}
498454 */
499- public function withExpiresAt ($ expires = 0 )
455+ public function withExpires ($ expires )
500456 {
501457 $ cookie = clone $ this ;
502458
0 commit comments