Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit e56f731

Browse files
committed
Merge branch 'improvement/185'
Close #185
2 parents 0b0b7bd + 1c049b0 commit e56f731

File tree

1 file changed

+56
-55
lines changed

1 file changed

+56
-55
lines changed

src/Header/SetCookie.php

Lines changed: 56 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
33
* @see https://github.com/zendframework/zend-http for the canonical source repository
4-
* @copyright Copyright (c) 2005-2017 Zend Technologies USA Inc. (http://www.zend.com)
4+
* @copyright Copyright (c) 2005-2019 Zend Technologies USA Inc. (https://www.zend.com)
55
* @license https://github.com/zendframework/zend-http/blob/master/LICENSE.md New BSD License
66
*/
77

@@ -190,15 +190,15 @@ public static function fromString($headerLine, $bypassHeaderFieldName = false)
190190
*
191191
* @todo Add validation of each one of the parameters (legal domain, etc.)
192192
*
193-
* @param string $name
194-
* @param string $value
195-
* @param int|string|DateTime $expires
196-
* @param string $path
197-
* @param string $domain
198-
* @param bool $secure
199-
* @param bool $httponly
200-
* @param string $maxAge
201-
* @param int $version
193+
* @param string|null $name
194+
* @param string|null $value
195+
* @param int|string|DateTime|null $expires
196+
* @param string|null $path
197+
* @param string|null $domain
198+
* @param bool $secure
199+
* @param bool $httponly
200+
* @param int|null $maxAge
201+
* @param int|null $version
202202
*/
203203
public function __construct(
204204
$name = null,
@@ -302,9 +302,9 @@ public function getFieldValue()
302302
}
303303

304304
/**
305-
* @param string $name
305+
* @param string|null $name
306+
* @return $this
306307
* @throws Exception\InvalidArgumentException
307-
* @return SetCookie
308308
*/
309309
public function setName($name)
310310
{
@@ -314,16 +314,16 @@ public function setName($name)
314314
}
315315

316316
/**
317-
* @return string
317+
* @return string|null
318318
*/
319319
public function getName()
320320
{
321321
return $this->name;
322322
}
323323

324324
/**
325-
* @param string $value
326-
* @return SetCookie
325+
* @param string|null $value
326+
* @return $this
327327
*/
328328
public function setValue($value)
329329
{
@@ -332,19 +332,17 @@ public function setValue($value)
332332
}
333333

334334
/**
335-
* @return string
335+
* @return string|null
336336
*/
337337
public function getValue()
338338
{
339339
return $this->value;
340340
}
341341

342342
/**
343-
* Set version
344-
*
345-
* @param int $version
343+
* @param int|null $version
344+
* @return $this
346345
* @throws Exception\InvalidArgumentException
347-
* @return SetCookie
348346
*/
349347
public function setVersion($version)
350348
{
@@ -356,20 +354,16 @@ public function setVersion($version)
356354
}
357355

358356
/**
359-
* Get version
360-
*
361-
* @return int
357+
* @return int|null
362358
*/
363359
public function getVersion()
364360
{
365361
return $this->version;
366362
}
367363

368364
/**
369-
* Set Max-Age
370-
*
371-
* @param int $maxAge
372-
* @return SetCookie
365+
* @param int $maxAge
366+
* @return $this
373367
*/
374368
public function setMaxAge($maxAge)
375369
{
@@ -382,22 +376,16 @@ public function setMaxAge($maxAge)
382376
}
383377

384378
/**
385-
* Get Max-Age
386-
*
387-
* @return int
379+
* @return int|null
388380
*/
389381
public function getMaxAge()
390382
{
391383
return $this->maxAge;
392384
}
393385

394386
/**
395-
* Set Expires
396-
*
397-
* @param int|string|DateTime $expires
398-
*
399-
* @return self
400-
*
387+
* @param int|string|DateTime|null $expires
388+
* @return $this
401389
* @throws Exception\InvalidArgumentException
402390
*/
403391
public function setExpires($expires)
@@ -435,13 +423,13 @@ public function setExpires($expires)
435423
}
436424

437425
/**
438-
* @param bool $inSeconds
439-
* @return int|string
426+
* @param bool $inSeconds
427+
* @return int|string|null
440428
*/
441429
public function getExpires($inSeconds = false)
442430
{
443431
if ($this->expires === null) {
444-
return;
432+
return null;
445433
}
446434
if ($inSeconds) {
447435
return $this->expires;
@@ -450,8 +438,8 @@ public function getExpires($inSeconds = false)
450438
}
451439

452440
/**
453-
* @param string $domain
454-
* @return SetCookie
441+
* @param string|null $domain
442+
* @return $this
455443
*/
456444
public function setDomain($domain)
457445
{
@@ -461,16 +449,16 @@ public function setDomain($domain)
461449
}
462450

463451
/**
464-
* @return string
452+
* @return string|null
465453
*/
466454
public function getDomain()
467455
{
468456
return $this->domain;
469457
}
470458

471459
/**
472-
* @param string $path
473-
* @return SetCookie
460+
* @param string|null $path
461+
* @return $this
474462
*/
475463
public function setPath($path)
476464
{
@@ -480,16 +468,16 @@ public function setPath($path)
480468
}
481469

482470
/**
483-
* @return string
471+
* @return string|null
484472
*/
485473
public function getPath()
486474
{
487475
return $this->path;
488476
}
489477

490478
/**
491-
* @param bool $secure
492-
* @return SetCookie
479+
* @param bool|null $secure
480+
* @return $this
493481
*/
494482
public function setSecure($secure)
495483
{
@@ -504,7 +492,7 @@ public function setSecure($secure)
504492
* Set whether the value for this cookie should be quoted
505493
*
506494
* @param bool $quotedValue
507-
* @return SetCookie
495+
* @return $this
508496
*/
509497
public function setQuoteFieldValue($quotedValue)
510498
{
@@ -513,16 +501,16 @@ public function setQuoteFieldValue($quotedValue)
513501
}
514502

515503
/**
516-
* @return bool
504+
* @return bool|null
517505
*/
518506
public function isSecure()
519507
{
520508
return $this->secure;
521509
}
522510

523511
/**
524-
* @param bool $httponly
525-
* @return SetCookie
512+
* @param bool|null $httponly
513+
* @return $this
526514
*/
527515
public function setHttponly($httponly)
528516
{
@@ -534,7 +522,7 @@ public function setHttponly($httponly)
534522
}
535523

536524
/**
537-
* @return bool
525+
* @return bool|null
538526
*/
539527
public function isHttponly()
540528
{
@@ -546,7 +534,7 @@ public function isHttponly()
546534
*
547535
* Always returns false if the cookie is a session cookie (has no expiry time)
548536
*
549-
* @param int $now Timestamp to consider as "now"
537+
* @param int|null $now Timestamp to consider as "now"
550538
* @return bool
551539
*/
552540
public function isExpired($now = null)
@@ -582,6 +570,12 @@ public function hasQuoteFieldValue()
582570
return $this->quoteFieldValue;
583571
}
584572

573+
/**
574+
* @param string $requestDomain
575+
* @param string $path
576+
* @param bool $isSecure
577+
* @return bool
578+
*/
585579
public function isValidForRequest($requestDomain, $path, $isSecure = false)
586580
{
587581
if ($this->getDomain() && (strrpos($requestDomain, $this->getDomain()) === false)) {
@@ -604,7 +598,7 @@ public function isValidForRequest($requestDomain, $path, $isSecure = false)
604598
*
605599
* @param string|\Zend\Uri\Uri $uri URI to check against (secure, domain, path)
606600
* @param bool $matchSessionCookies Whether to send session cookies
607-
* @param int $now Override the current time when checking for expiry time
601+
* @param int|null $now Override the current time when checking for expiry time
608602
* @return bool
609603
* @throws Exception\InvalidArgumentException If URI does not have HTTP or HTTPS scheme.
610604
*/
@@ -651,7 +645,6 @@ public function match($uri, $matchSessionCookies = true, $now = null)
651645
*
652646
* @param string $cookieDomain
653647
* @param string $host
654-
*
655648
* @return bool
656649
*/
657650
public static function matchCookieDomain($cookieDomain, $host)
@@ -677,11 +670,19 @@ public static function matchCookiePath($cookiePath, $path)
677670
return (strpos($path, $cookiePath) === 0);
678671
}
679672

673+
/**
674+
* @return string
675+
*/
680676
public function toString()
681677
{
682678
return 'Set-Cookie: ' . $this->getFieldValue();
683679
}
684680

681+
/**
682+
* @param array $headers
683+
* @return string
684+
* @throws Exception\RuntimeException
685+
*/
685686
public function toStringMultipleHeaders(array $headers)
686687
{
687688
$headerLine = $this->toString();

0 commit comments

Comments
 (0)