8000 move withers up · symfony/symfony@8ae8fbb · GitHub
[go: up one dir, main page]

Skip to content

Commit 8ae8fbb

Browse files
committed
move withers up
1 parent c6e60e4 commit 8ae8fbb

File tree

1 file changed

+131
-131
lines changed

1 file changed

+131
-131
lines changed

src/Symfony/Component/HttpFoundation/Cookie.php

Lines changed: 131 additions & 131 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,137 @@ public function __construct(string $name, string $value = null, $expire = 0, ?st
110110
$this->sameSite = $this->withSameSite($sameSite)->sameSite;
111111
}
112112

113+
/**
114+
* Creates a cookie copy with a new value.
115+
*
116+
* @return static
117+
*/
118+
public function withValue(?string $value): self
119+
{
120+
$cookie = clone $this;
121+
$cookie->value = $value;
122+
123+
return $cookie;
124+
}
125+
126+
/**
127+
* Creates a cookie copy with a new domain that the cookie is available to.
128+
*
129+
* @return static
130+
*/
131+
public function withDomain(?string $domain): self
132+
{
133+
$cookie = clone $this;
134+
$cookie->domain = $domain;
135+
136+
return $cookie;
137+
}
138+
139+
/**
140+
* Creates a cookie copy with a new time the cookie expires.
141+
*
142+
* @param int|string|\DateTimeInterface $expire
143+
*
144+
* @return static
145+
*/
146+
public function withExpires($expire = 0): self
147+
{
148+
// convert expiration time to a Unix timestamp
149+
if ($expire instanceof \DateTimeInterface) {
150+
$expire = $expire->format('U');
151+
} elseif (!is_numeric($expire)) {
152+
$expire = strtotime($expire);
153+
154+
if (false === $expire) {
155+
throw new \InvalidArgumentException('The cookie expiration time is not valid.');
156+
}
157+
}
158+
159+
$cookie = clone $this;
160+
$cookie->expire = 0 < $expire ? (int) $expire : 0;
161+
162+
return $cookie;
163+
}
164+
165+
/**
166+
* Creates a cookie copy with a new path on the server in which the cookie will be available on.
167+
*
168+
* @return static
169+
*/
170+
public function withPath(string $path): self
171+
{
172+
$cookie = clone $this;
173+
$cookie->path = '' === $path ? '/' : $path;
174+
175+
return $cookie;
176+
}
177+
178+
/**
179+
* Creates a cookie copy that only be transmitted over a secure HTTPS connection from the client.
180+
*
181+
* @return static
182+
*/
183+
public function withSecure(bool $secure = true): self
184+
{
185+
$cookie = clone $this;
186+
$cookie->secure = $secure;
187+
188+
return $cookie;
189+
}
190+
191+
/**
192+
* Creates a cookie copy that be accessible only through the HTTP protocol.
193+
*
194+
* @return static
195+
*/
196+
public function withHttpOnly(bool $httpOnly = true): self
197+
{
198+
$cookie = clone $this;
199+
$cookie->httpOnly = $httpOnly;
200+
201+
return $cookie;
202+
}
203+
204+
/**
205+
* Creates a cookie copy that uses no url encoding.
206+
*
207+
* @return static
208+
*/
209+
public function withRaw(bool $raw = true): self
210+
{
211+
if ($raw && false !== strpbrk($this->name, self::$reservedCharsList)) {
212+
throw new \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $this->name));
213+
}
214+
215+
$cookie = clone $this;
216+
$cookie->raw = $raw;
217+
218+
return $cookie;
219+
}
220+
221+
/**
222+
* Creates a cookie copy with SameSite attribute.
223+
*
224+
* @return static
225+
*/
226+
public function withSameSite(?string $sameSite): self
227+
{
228+
if ('' === $sameSite) {
229+
$sameSite = null;
230+
} elseif (null !== $sameSite) {
231+
$sameSite = strtolower($sameSite);
232+
}
233+
234+
if (!\in_array($sameSite, [self::SAMESITE_LAX, self::SAMESITE_STRICT, self::SAMESITE_NONE, null], true)) {
235+
throw new \InvalidArgumentException('The "sameSite" parameter value is not valid.');
236+
}
237+
238+
$cookie = clone $this;
239+
$cookie->sameSite = $sameSite;
240+
241+
return $cookie;
242+
}
243+
113244
/**
114245
* Returns the cookie as a string.
115246
*
@@ -178,19 +309,6 @@ public function getValue()
178309
return $this->value;
179310
}
180311

181-
/**
182-
* Creates a cookie copy with a new value.
183-
*
184-
* @return static
185-
*/
186-
public function withValue(?string $value): self
187-
{
188-
$cookie = clone $this;
189-
$cookie->value = $value;
190-
191-
return $cookie;
192-
}
193-
194312
/**
195313
* Gets the domain that the cookie is available to.
196314
*
@@ -201,19 +319,6 @@ public function getDomain()
201319
return $this->domain;
202320
}
203321

204-
/**
205-
* Creates a cookie copy with a new domain that the cookie is available to.
206-
*
207-
* @return static
208-
*/
209-
public function withDomain(?string $domain): self
210-
{
211-
$cookie = clone $this;
212-
$cookie->domain = $domain;
213-
214-
return $cookie;
215-
}
216-
217322
/**
218323
* Gets the time the cookie expires.
219324
*
@@ -224,32 +329,6 @@ public function getExpiresTime()
224329
return $this->expire;
225330
}
226331

227-
/**
228-
* Creates a cookie copy with a new time the cookie expires.
229-
*
230-
* @param int|string|\DateTimeInterface $expire
231-
*
232-
* @return static
233-
*/
234-
public function withExpires($expire = 0): self
235-
{
236-
// convert expiration time to a Unix timestamp
237-
if ($expire instanceof \DateTimeInterface) {
238-
$expire = $expire->format('U');
239-
} elseif (!is_numeric($expire)) {
240-
$expire = strtotime($expire);
241-
242-
if (false === $expire) {
243-
throw new \InvalidArgumentException('The cookie expiration time is not valid.');
244-
}
245-
}
246-
247-
$cookie = clone $this;
248-
$cookie->expire = 0 < $expire ? (int) $expire : 0;
249-
250-
return $cookie;
251-
}
252-
253332
/**
254333
* Gets the max-age attribute.
255334
*
@@ -272,19 +351,6 @@ public function getPath()
272351
return $this->path;
273352
}
274353

275-
/**
276-
* Creates a cookie copy with a new path on the server in which the cookie will be available on.
277-
*
278-
* @return static
279-
*/
280-
public function withPath(string $path): self
281-
{
282-
$cookie = clone $this;
283-
$cookie->path = '' === $path ? '/' : $path;
284-
285-
return $cookie;
286-
}
287-
288354
/**
289355
* Checks whether the cookie should only be transmitted over a secure HTTPS connection from the client.
290356
*
@@ -295,19 +361,6 @@ public function isSecure()
295361
return $this->secure ?? $this->secureDefault;
296362
}
297363

298-
/**
299-
* Creates a cookie copy that only be transmitted over a secure HTTPS connection from the client.
300-
*
301-
* @return static
302-
*/
303-
public function withSecure(bool $secure = true): self
304-
{
305-
$cookie = clone $this;
306-
$cookie->secure = $secure;
307-
308-
return $cookie;
309-
}
310-
311364
/**
312365
* Checks whether the cookie will be made accessible only through the HTTP protocol.
313366
*
@@ -318,19 +371,6 @@ public function isHttpOnly()
318371
return $this->httpOnly;
319372
}
320373

321-
/**
322-
* Creates a cookie copy that be accessible only through the HTTP protocol.
323-
*
324-
* @return static
325-
*/
326-
public function withHttpOnly(bool $httpOnly = true): self
327-
{
328-
$cookie = clone $this;
329-
$cookie->httpOnly = $httpOnly;
330-
331-
return $cookie;
332-
}
333-
334374
/**
335375
* Whether this cookie is about to be cleared.
336376
*
@@ -351,23 +391,6 @@ public function isRaw()
351391
return $this->raw;
352392
}
353393

354-
/**
355-
* Creates a cookie copy that uses no url encoding.
356-
*
357-
* @return static
358-
*/
359-
public function withRaw(bool $raw = true): self
360-
{
361-
if ($raw && false !== strpbrk($this->name, self::$reservedCharsList)) {
362-
throw new \InvalidArgumentException(sprintf('The cookie name "%s" contains invalid characters.', $this->name));
363-
}
364-
365-
$cookie = clone $this;
366-
$cookie->raw = $raw;
367-
368-
return $cookie;
369-
}
370-
371394
/**
372395
* Gets the SameSite attribute.
373396
*
@@ -378,29 +401,6 @@ public function getSameSite()
378401
return $this->sameSite;
379402
}
380403

381-
/**
382-
* Creates a cookie copy with SameSite attribute.
383-
*
384-
* @return static
385-
*/
386-
public function withSameSite(?string $sameSite): self
387-
{
388-
if ('' === $sameSite) {
389-
$sameSite = null;
390-
} elseif (null !== $sameSite) {
391-
$sameSite = strtolower($sameSite);
392-
}
393-
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-
}
397-
398-
$cookie = clone $this;
399-
$cookie->sameSite = $sameSite;
400-
401-
return $cookie;
402-
}
403-
404404
/**
405405
* @param bool $default The default value of the "secure" flag when it is set to null
406406
*/

0 commit comments

Comments
 (0)
0