Skip to content

Commit 75ba93d

Browse files
committed
Creates new cookie instance with dummy name to bypass constructor validation
1 parent d6e6ec8 commit 75ba93d

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

src/Cookie.php

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,6 @@ final class Cookie
5353
*/
5454
private $expires;
5555

56-
/**
57-
* Validation state.
58-
*
59-
* @var bool
60-
*/
61-
private $valid;
62-
6356
/**
6457
* @param string $name
6558
* @param string|null $value
@@ -68,8 +61,7 @@ final class Cookie
6861
* @param string|null $path
6962
* @param bool $secure
7063
* @param bool $httpOnly
71-
* @param \DateTime|null $expires Expires attribute is HTTP 1.0 only and should be avoided.
72-
* @param bool $requireValidation deprecated since version 1.5. Will be removed in 2.0
64+
* @param \DateTime|null $expires Expires attribute is HTTP 1.0 only and should be avoided.
7365
*
7466
* @throws \InvalidArgumentException If name, value or max age is not valid. Attributes validation during instantiation is deprecated since 1.5 and will be removed in 2.0.
7567
*/
@@ -81,15 +73,15 @@ public function __construct(
8173
$path = null,
8274
$secure = false,
8375
$httpOnly = false,
84-
\DateTime $expires = null,
85-
$requireValidation = true
76+
\DateTime $expires = null
8677
) {
87-
if ($requireValidation) {
88-
@trigger_error('Attributes validation during instantiation is deprecated since 1.5 and will be removed in 2.0', E_USER_DEPRECATED);
78+
try {
8979
$this->validateName($name);
9080
$this->validateValue($value);
9181
$this->validateMaxAge($maxAge);
92-
$this->valid = true;
82+
} catch (\InvalidArgumentException $e) {
83+
@trigger_error('Attributes validation during instantiation is deprecated since 1.5 and will be removed in 2.0', E_USER_DEPRECATED);
84+
throw $e;
9385
}
9486

9587
$this->name = $name;
@@ -112,7 +104,12 @@ public static function createWithoutValidation(
112104
$httpOnly = false,
113105
\DateTime $expires = null
114106
) {
115-
return new self($name, $value, $maxAge, $domain, $path, $secure, $httpOnly, $expires, false);
107+
$cookie = new self('name', null, null, $domain, $path, $secure, $httpOnly, $expires);
108+
$cookie->name = $name;
109+
$cookie->value = $value;
110+
$cookie->maxAge = $maxAge;
111+
112+
return $cookie;
116113
}
117114

118115
/**
@@ -413,18 +410,15 @@ public function match(Cookie $cookie)
413410
*/
414411
public function isValid()
415412
{
416-
if (null === $this->valid) {
417-
try {
418-
$this->validateName($this->name);
419-
$this->validateValue($this->value);
420-
$this->validateMaxAge($this->maxAge);
421-
$this->valid = true;
422-
} catch (\InvalidArgumentException $e) {
423-
$this->valid = false;
424-
}
413+
try {
414+
$this->validateName($this->name);
415+
$this->validateValue($this->value);
416+
$this->validateMaxAge($this->maxAge);
417+
} catch (\InvalidArgumentException $e) {
418+
return false;
425419
}
426420

427-
return $this->valid;
421+
return true;
428422
}
429423

430424
/**

0 commit comments

Comments
 (0)