ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
FigRequestCookies.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Dflydev\FigCookies;
4 
7 
9 {
17  public static function get(RequestInterface $request, $name, $value = null)
18  {
19  $cookies = Cookies::fromRequest($request);
20  if ($cookies->has($name)) {
21  return $cookies->get($name);
22  }
23 
24  return Cookie::create($name, $value);
25  }
26 
33  public static function set(RequestInterface $request, Cookie $cookie)
34  {
35  return Cookies::fromRequest($request)
36  ->with($cookie)
37  ->renderIntoCookieHeader($request)
38  ;
39  }
40 
48  public static function modify(RequestInterface $request, $name, $modify)
49  {
50  if (! is_callable($modify)) {
51  throw new InvalidArgumentException('$modify must be callable.');
52  }
53 
54  $cookies = Cookies::fromRequest($request);
55  $cookie = $modify($cookies->has($name)
56  ? $cookies->get($name)
57  : Cookie::create($name)
58  );
59 
60  return $cookies
61  ->with($cookie)
62  ->renderIntoCookieHeader($request)
63  ;
64  }
65 
72  public static function remove(RequestInterface $request, $name)
73  {
74  return Cookies::fromRequest($request)
75  ->without($name)
76  ->renderIntoCookieHeader($request)
77  ;
78  }
79 }
static create($name, $value=null)
Create a Cookie.
Definition: Cookie.php:73
if($format !==null) $name
Definition: metadata.php:146
static modify(RequestInterface $request, $name, $modify)
Representation of an outgoing, client-side request.
static fromRequest(RequestInterface $request)
Create Cookies from a Request.
Definition: Cookies.php:121