ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
FigResponseCookies.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Dflydev\FigCookies;
4 
7 
9 {
17  public static function get(ResponseInterface $response, $name, $value = null)
18  {
19  $setCookies = SetCookies::fromResponse($response);
20  if ($setCookies->has($name)) {
21  return $setCookies->get($name);
22  }
23 
24  return SetCookie::create($name, $value);
25  }
26 
33  public static function set(ResponseInterface $response, SetCookie $setCookie)
34  {
35  return SetCookies::fromResponse($response)
36  ->with($setCookie)
37  ->renderIntoSetCookieHeader($response)
38  ;
39  }
40 
47  public static function expire(ResponseInterface $response, $cookieName)
48  {
49  return static::set($response, SetCookie::createExpired($cookieName));
50  }
51 
59  public static function modify(ResponseInterface $response, $name, $modify)
60  {
61  if (! is_callable($modify)) {
62  throw new InvalidArgumentException('$modify must be callable.');
63  }
64 
65  $setCookies = SetCookies::fromResponse($response);
66  $setCookie = $modify($setCookies->has($name)
67  ? $setCookies->get($name)
68  : SetCookie::create($name)
69  );
70 
71  return $setCookies
72  ->with($setCookie)
73  ->renderIntoSetCookieHeader($response)
74  ;
75  }
76 
83  public static function remove(ResponseInterface $response, $name)
84  {
85  return SetCookies::fromResponse($response)
86  ->without($name)
87  ->renderIntoSetCookieHeader($response)
88  ;
89  }
90 }
static fromResponse(ResponseInterface $response)
Create SetCookies from a Response.
Definition: SetCookies.php:124
static create($name, $value=null)
Definition: SetCookie.php:173
$cookieName
static expire(ResponseInterface $response, $cookieName)
static modify(ResponseInterface $response, $name, $modify)
Representation of an outgoing, server-side response.
$response