ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
CookieWrapper.php
Go to the documentation of this file.
1 <?php
2 
19 namespace ILIAS\HTTP\Cookies;
20 
23 
32 class CookieWrapper implements Cookie
33 {
34  private SetCookie $cookie;
35 
39  public function __construct(SetCookie $cookie)
40  {
41  $this->cookie = $cookie;
42  }
43 
47  public function getName(): string
48  {
49  return $this->cookie->getName();
50  }
51 
55  public function getValue(): ?string
56  {
57  return $this->cookie->getValue();
58  }
59 
63  public function getExpires(): int
64  {
65  return $this->cookie->getExpires();
66  }
67 
71  public function getMaxAge(): int
72  {
73  return $this->cookie->getMaxAge();
74  }
75 
79  public function getPath(): ?string
80  {
81  return $this->cookie->getPath();
82  }
83 
87  public function getDomain(): ?string
88  {
89  return $this->cookie->getDomain();
90  }
91 
95  public function getSecure(): bool
96  {
97  return $this->cookie->getSecure();
98  }
99 
103  public function getHttpOnly(): bool
104  {
105  return $this->cookie->getHttpOnly();
106  }
107 
108  public function getSamesite(): ?string
109  {
110  $samesite = $this->cookie->getSameSite();
111  return is_null($samesite) ? null : $samesite->asString();
112  }
113 
117  public function withValue(string $value = null): Cookie
118  {
119  $clone = clone $this;
120  $clone->cookie = $this->cookie->withValue($value);
121 
122  return $clone;
123  }
124 
128  public function withExpires($expires = null): Cookie
129  {
130  $clone = clone $this;
131  $clone->cookie = $this->cookie->withExpires($expires);
132 
133  return $clone;
134  }
135 
139  public function rememberForLongTime(): Cookie
140  {
141  $clone = clone $this;
142  $clone->cookie = $this->cookie->rememberForever();
143 
144  return $clone;
145  }
146 
150  public function expire(): Cookie
151  {
152  $clone = clone $this;
153  $clone->cookie = $this->cookie->expire();
154 
155  return $clone;
156  }
157 
161  public function withMaxAge(int $maxAge = null): Cookie
162  {
163  $clone = clone $this;
164  $clone->cookie = $this->cookie->withMaxAge($maxAge);
165 
166  return $clone;
167  }
168 
172  public function withPath(string $path = null): Cookie
173  {
174  $clone = clone $this;
175  $clone->cookie = $this->cookie->withPath($path);
176 
177  return $clone;
178  }
179 
183  public function withDomain(string $domain = null): Cookie
184  {
185  $clone = clone $this;
186  $clone->cookie = $this->cookie->withDomain($domain);
187 
188  return $clone;
189  }
190 
194  public function withSecure(bool $secure = null): Cookie
195  {
196  $clone = clone $this;
197  $clone->cookie = $this->cookie->withSecure($secure);
198 
199  return $clone;
200  }
201 
205  public function withHttpOnly(bool $httpOnly = null): Cookie
206  {
207  $clone = clone $this;
208  $clone->cookie = $this->cookie->withHttpOnly($httpOnly);
209 
210  return $clone;
211  }
212 
213  public function withSamesite(string $sameSite): Cookie
214  {
215  $clone = clone $this;
216  $clone->cookie = $this->cookie->withSameSite(SameSite::fromString($sameSite));
217 
218  return $clone;
219  }
220 
224  public function __toString(): string
225  {
226  return $this->cookie->__toString();
227  }
228 
234  public function getImplementation(): SetCookie
235  {
236  return $this->cookie;
237  }
238 }
withHttpOnly(bool $httpOnly=null)
withMaxAge(int $maxAge=null)
Maximal life time of the cookie in seconds.
withPath(string $path=null)
Sets the cookie path.
withSecure(bool $secure=null)
Sets if the cookie is a secure cookie or not.
expire()
Expire the cookie.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Cookie.php:19
$path
Definition: ltiservices.php:32
getImplementation()
Returns the underlying implementation.
withValue(string $value=null)
Sets the cookie value.
withHttpOnly(bool $httpOnly=null)
Sets if the cookie is http only.
withDomain(string $domain=null)
withExpires($expires=null)
Sets the expiration date of the cookie.
__construct(SetCookie $cookie)
CookieFacade constructor.
withSamesite(string $sameSite)
Sets the samesite attribute.
withDomain(string $domain=null)
Sets the domain name for the cookie.