ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Dflydev\FigCookies\SetCookies Class Reference
+ Collaboration diagram for Dflydev\FigCookies\SetCookies:

Public Member Functions

 __construct (array $setCookies=[])
 
 has ($name)
 
 get ($name)
 
 getAll ()
 
 with (SetCookie $setCookie)
 
 without ($name)
 
 renderIntoSetCookieHeader (ResponseInterface $response)
 Render SetCookies into a Response. More...
 

Static Public Member Functions

static fromSetCookieStrings ($setCookieStrings)
 Create SetCookies from a collection of SetCookie header value strings. More...
 
static fromResponse (ResponseInterface $response)
 Create SetCookies from a Response. More...
 

Data Fields

const SET_COOKIE_HEADER = 'Set-Cookie'
 The name of the Set-Cookie header. More...
 

Private Attributes

 $setCookies = []
 

Detailed Description

Definition at line 7 of file SetCookies.php.

Constructor & Destructor Documentation

◆ __construct()

Dflydev\FigCookies\SetCookies::__construct ( array  $setCookies = [])
Parameters
SetCookie[]$setCookies

Definition at line 22 of file SetCookies.php.

References Dflydev\FigCookies\SetCookies\$setCookies.

23  {
24  foreach ($setCookies as $setCookie) {
25  $this->setCookies[$setCookie->getName()] = $setCookie;
26  }
27  }

Member Function Documentation

◆ fromResponse()

static Dflydev\FigCookies\SetCookies::fromResponse ( ResponseInterface  $response)
static

Create SetCookies from a Response.

Parameters
ResponseInterface$response
Returns
SetCookies

Definition at line 124 of file SetCookies.php.

References Psr\Http\Message\MessageInterface\getHeader().

Referenced by ILIAS\HTTP\Cookies\CookieJarFactoryImpl\fromResponse(), Dflydev\FigCookies\FigResponseCookies\get(), Dflydev\FigCookies\SetCookiesTest\it_creates_from_response(), Dflydev\FigCookies\SetCookiesTest\it_gets_and_updates_set_cookie_value_on_request(), Dflydev\FigCookies\FigResponseCookies\modify(), Dflydev\FigCookies\FigResponseCookies\remove(), and Dflydev\FigCookies\FigResponseCookies\set().

125  {
126  return new static(array_map(function ($setCookieString) {
127  return SetCookie::fromSetCookieString($setCookieString);
128  }, $response->getHeader(static::SET_COOKIE_HEADER)));
129  }
$response
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fromSetCookieStrings()

static Dflydev\FigCookies\SetCookies::fromSetCookieStrings (   $setCookieStrings)
static

Create SetCookies from a collection of SetCookie header value strings.

Parameters
string[]$setCookieStrings
Returns
static

Definition at line 111 of file SetCookies.php.

Referenced by ILIAS\HTTP\Cookies\CookieJarFactoryImpl\fromCookieStrings(), Dflydev\FigCookies\SetCookiesTest\it_creates_from_set_cookie_strings(), Dflydev\FigCookies\SetCookiesTest\it_gets_set_cookie_by_name(), Dflydev\FigCookies\SetCookiesTest\it_knows_which_set_cookies_are_available(), and Dflydev\FigCookies\SetCookiesTest\it_renders_added_and_removed_set_cookies_header().

112  {
113  return new static(array_map(function ($setCookieString) {
114  return SetCookie::fromSetCookieString($setCookieString);
115  }, $setCookieStrings));
116  }
+ Here is the caller graph for this function:

◆ get()

Dflydev\FigCookies\SetCookies::get (   $name)
Parameters
string$name
Returns
SetCookie|null

Definition at line 42 of file SetCookies.php.

References $name, and Dflydev\FigCookies\SetCookies\has().

43  {
44  if (! $this->has($name)) {
45  return null;
46  }
47 
48  return $this->setCookies[$name];
49  }
+ Here is the call graph for this function:

◆ getAll()

Dflydev\FigCookies\SetCookies::getAll ( )
Returns
SetCookie[]

Definition at line 54 of file SetCookies.php.

55  {
56  return array_values($this->setCookies);
57  }

◆ has()

Dflydev\FigCookies\SetCookies::has (   $name)
Parameters
string$name
Returns
bool

Definition at line 33 of file SetCookies.php.

References $name.

Referenced by Dflydev\FigCookies\SetCookies\get().

34  {
35  return isset($this->setCookies[$name]);
36  }
+ Here is the caller graph for this function:

◆ renderIntoSetCookieHeader()

Dflydev\FigCookies\SetCookies::renderIntoSetCookieHeader ( ResponseInterface  $response)

Render SetCookies into a Response.

Parameters
ResponseInterface$response
Returns
ResponseInterface

Definition at line 95 of file SetCookies.php.

References $response, Psr\Http\Message\MessageInterface\withAddedHeader(), and Psr\Http\Message\MessageInterface\withoutHeader().

96  {
97  $response = $response->withoutHeader(static::SET_COOKIE_HEADER);
98  foreach ($this->setCookies as $setCookie) {
99  $response = $response->withAddedHeader(static::SET_COOKIE_HEADER, (string) $setCookie);
100  }
101 
102  return $response;
103  }
$response
+ Here is the call graph for this function:

◆ with()

Dflydev\FigCookies\SetCookies::with ( SetCookie  $setCookie)
Parameters
SetCookie$setCookie
Returns
SetCookies

Definition at line 63 of file SetCookies.php.

References Dflydev\FigCookies\SetCookie\getName().

64  {
65  $clone = clone($this);
66 
67  $clone->setCookies[$setCookie->getName()] = $setCookie;
68 
69  return $clone;
70  }
+ Here is the call graph for this function:

◆ without()

Dflydev\FigCookies\SetCookies::without (   $name)
Parameters
string$name
Returns
SetCookies

Definition at line 76 of file SetCookies.php.

References $name.

77  {
78  $clone = clone($this);
79 
80  if (! $clone->has($name)) {
81  return $clone;
82  }
83 
84  unset($clone->setCookies[$name]);
85 
86  return $clone;
87  }

Field Documentation

◆ $setCookies

Dflydev\FigCookies\SetCookies::$setCookies = []
private

Definition at line 17 of file SetCookies.php.

Referenced by Dflydev\FigCookies\SetCookies\__construct().

◆ SET_COOKIE_HEADER


The documentation for this class was generated from the following file: