@@ -158,26 +158,6 @@ public function __toString()
158
158
return $ str ;
159
159
}
160
160
161
- /**
162
- * Gets the name of the cookie.
163
- *
164
- * @return string
165
- */
166
- public function getName ()
167
- {
168
- return $ this ->name ;
169
- }
170
-
171
- /**
172
- * Gets the value of the cookie.
173
- *
174
- * @return string|null
175
- */
176
- public function getValue ()
177
- {
178
- return $ this ->value ;
179
- }
180
-
181
161
/**
182
162
* Creates a cookie copy with a new value.
183
163
*
@@ -191,16 +171,6 @@ public function withValue(?string $value): self
191
171
return $ cookie ;
192
172
}
193
173
194
- /**
195
- * Gets the domain that the cookie is available to.
196
- *
197
- * @return string|null
198
- */
199
- public function getDomain ()
200
- {
201
- return $ this ->domain ;
202
- }
203
-
204
174
/**
205
175
* Creates a cookie copy with a new domain that the cookie is available to.
206
176
*
@@ -214,16 +184,6 @@ public function withDomain(?string $domain): self
214
184
return $ cookie ;
215
185
}
216
186
217
- /**
218
- * Gets the time the cookie expires.
219
- *
220
- * @return int
221
- */
222
- public function getExpiresTime ()
223
- {
224
- return $ this ->expire ;
225
- }
226
-
227
187
/**
228
188
* Creates a cookie copy with a new time the cookie expires.
229
189
*
@@ -251,154 +211,194 @@ public function withExpires($expire = 0): self
251
211
}
252
212
253
213
/**
254
- * Gets the max-age attribute .
214
+ * Creates a cookie copy with a new path on the server in which the cookie will be available on .
255
215
*
256
- * @return int
216
+ * @return static
257
217
*/
258
- public function getMaxAge ()
218
+ public function withPath ( string $ path ): self
259
219
{
260
- $ maxAge = $ this ->expire - time ();
220
+ $ cookie = clone $ this ;
221
+ $ cookie ->path = '' === $ path ? '/ ' : $ path ;
261
222
262
- return 0 >= $ maxAge ? 0 : $ maxAge ;
223
+ return $ cookie ;
263
224
}
264
225
265
226
/**
266
- * Gets the path on the server in which the cookie will be available on .
227
+ * Creates a cookie copy that only be transmitted over a secure HTTPS connection from the client .
267
228
*
268
- * @return string
229
+ * @return static
269
230
*/
270
- public function getPath ()
231
+ public function withSecure ( bool $ secure = true ): self
271
232
{
272
- return $ this ->path ;
233
+ $ cookie = clone $ this ;
234
+ $ cookie ->secure = $ secure ;
235
+
236
+ return $ cookie ;
273
237
}
274
238
275
239
/**
276
- * Creates a cookie copy with a new path on the server in which the cookie will be available on .
240
+ * Creates a cookie copy that be accessible only through the HTTP protocol .
277
241
*
278
242
* @return static
279
243
*/
280
- public function withPath ( string $ path ): self
244
+ public function withHttpOnly ( bool $ httpOnly = true ): self
281
245
{
282
246
$ cookie = clone $ this ;
283
- $ cookie ->path = '' === $ path ? ' / ' : $ path ;
247
+ $ cookie ->httpOnly = $ httpOnly ;
284
248
285
249
return $ cookie ;
286
250
}
287
251
288
252
/**
289
- * Checks whether the cookie should only be transmitted over a secure HTTPS connection from the client .
253
+ * Creates a cookie copy that uses no url encoding .
290
254
*
291
- * @return bool
255
+ * @return static
292
256
*/
293
- public function isSecure ()
257
+ public function withRaw ( bool $ raw = true ): self
294
258
{
295
- return $ this ->secure ?? $ this ->secureDefault ;
259
+ if ($ raw && false !== strpbrk ($ this ->name , self ::$ reservedCharsList )) {
260
+ throw new \InvalidArgumentException (sprintf ('The cookie name "%s" contains invalid characters. ' , $ this ->name ));
261
+ }
262
+
263
+ $ cookie = clone $ this ;
264
+ $ cookie ->raw = $ raw ;
265
+
266
+ return $ cookie ;
296
267
}
297
268
298
269
/**
299
- * Creates a cookie copy that only be transmitted over a secure HTTPS connection from the client .
270
+ * Creates a cookie copy with SameSite attribute .
300
271
*
301
272
* @return static
302
273
*/
303
- public function withSecure ( bool $ secure = true ): self
274
+ public function withSameSite (? string $ sameSite ): self
304
275
{
276
+ if ('' === $ sameSite ) {
277
+ $ sameSite = null ;
278
+ } elseif (null !== $ sameSite ) {
279
+ $ sameSite = strtolower ($ sameSite );
280
+ }
281
+
282
+ if (!\in_array ($ sameSite , [self ::SAMESITE_LAX , self ::SAMESITE_STRICT , self ::SAMESITE_NONE , null ], true )) {
283
+ throw new \InvalidArgumentException ('The "sameSite" parameter value is not valid. ' );
284
+ }
285
+
305
286
$ cookie = clone $ this ;
306
- $ cookie ->secure = $ secure ;
287
+ $ cookie ->sameSite = $ sameSite ;
307
288
308
289
return $ cookie ;
309
290
}
310
291
311
292
/**
312
- * Checks whether the cookie will be made accessible only through the HTTP protocol .
293
+ * Gets the name of the cookie .
313
294
*
314
- * @return bool
295
+ * @return string
315
296
*/
316
- public function isHttpOnly ()
297
+ public function getName ()
317
298
{
318
- return $ this ->httpOnly ;
299
+ return $ this ->name ;
319
300
}
320
301
321
302
/**
322
- * Creates a cookie copy that be accessible only through the HTTP protocol .
303
+ * Gets the value of the cookie .
323
304
*
324
- * @return static
305
+ * @return string|null
325
306
*/
326
- public function withHttpOnly ( bool $ httpOnly = true ): self
307
+ public function getValue ()
327
308
{
328
- $ cookie = clone $ this ;
329
- $ cookie ->httpOnly = $ httpOnly ;
330
-
331
- return $ cookie ;
309
+ return $ this ->value ;
332
310
}
333
311
334
312
/**
335
- * Whether this cookie is about to be cleared .
313
+ * Gets the domain that the cookie is available to.
336
314
*
337
- * @return bool
315
+ * @return string|null
338
316
*/
339
- public function isCleared ()
317
+ public function getDomain ()
340
318
{
341
- return 0 !== $ this ->expire && $ this -> expire < time () ;
319
+ return $ this ->domain ;
342
320
}
343
321
344
322
/**
345
- * Checks if the cookie value should be sent with no url encoding .
323
+ * Gets the time the cookie expires .
346
324
*
347
- * @return bool
325
+ * @return int
348
326
*/
349
- public function isRaw ()
327
+ public function getExpiresTime ()
350
328
{
351
- return $ this ->raw ;
329
+ return $ this ->expire ;
352
330
}
353
331
354
332
/**
355
- * Creates a cookie copy that uses no url encoding .
333
+ * Gets the max-age attribute .
356
334
*
357
- * @return static
335
+ * @return int
358
336
*/
359
- public function withRaw ( bool $ raw = true ): self
337
+ public function getMaxAge ()
360
338
{
361
- if ($ raw && false !== strpbrk ($ this ->name , self ::$ reservedCharsList )) {
362
- throw new \InvalidArgumentException (sprintf ('The cookie name "%s" contains invalid characters. ' , $ this ->name ));
363
- }
339
+ $ maxAge = $ this ->expire - time ();
364
340
365
- $ cookie = clone $ this ;
366
- $ cookie -> raw = $ raw ;
341
+ return 0 >= $ maxAge ? 0 : $ maxAge ;
342
+ }
367
343
368
- return $ cookie ;
344
+ /**
345
+ * Gets the path on the server in which the cookie will be available on.
346
+ *
347
+ * @return string
348
+ */
349
+ public function getPath ()
350
+ {
351
+ return $ this ->path ;
369
352
}
370
353
371
354
/**
372
- * Gets the SameSite attribute .
355
+ * Checks whether the cookie should only be transmitted over a secure HTTPS connection from the client .
373
356
*
374
- * @return string|null
357
+ * @return bool
375
358
*/
376
- public function getSameSite ()
359
+ public function isSecure ()
377
360
{
378
- return $ this ->sameSite ;
361
+ return $ this ->secure ?? $ this -> secureDefault ;
379
362
}
380
363
381
364
/**
382
- * Creates a cookie copy with SameSite attribute .
365
+ * Checks whether the cookie will be made accessible only through the HTTP protocol .
383
366
*
384
- * @return static
367
+ * @return bool
385
368
*/
386
- public function withSameSite (? string $ sameSite ): self
369
+ public function isHttpOnly ()
387
370
{
388
- if ('' === $ sameSite ) {
389
- $ sameSite = null ;
390
- } elseif (null !== $ sameSite ) {
391
- $ sameSite = strtolower ($ sameSite );
392
- }
371
+ return $ this ->httpOnly ;
372
+ }
393
373
394
- if (!\in_array ($ sameSite , [self ::SAMESITE_LAX , self ::SAMESITE_STRICT , self ::SAMESITE_NONE , null ], true )) {
395
- throw new \InvalidArgumentException ('The "sameSite" parameter value is not valid. ' );
396
- }
374
+ /**
375
+ * Whether this cookie is about to be cleared.
376
+ *
377
+ * @return bool
378
+ */
379
+ public function isCleared ()
380
+ {
381
+ return 0 !== $ this ->expire && $ this ->expire < time ();
382
+ }
397
383
398
- $ cookie = clone $ this ;
399
- $ cookie ->sameSite = $ sameSite ;
384
+ /**
385
+ * Checks if the cookie value should be sent with no url encoding.
386
+ *
387
+ * @return bool
388
+ */
389
+ public function isRaw ()
390
+ {
391
+ return $ this ->raw ;
392
+ }
400
393
401
- return $ cookie ;
394
+ /**
395
+ * Gets the SameSite attribute.
396
+ *
397
+ * @return string|null
398
+ */
399
+ public function getSameSite ()
400
+ {
401
+ return $ this ->sameSite ;
402
402
}
403
403
404
404
/**
0 commit comments