11use InvalidArgumentException;
 
   56        $this->requestCookies = $cookies;
 
   66        $this->defaults = array_replace($this->defaults, $settings);
 
   88    public function set(
$name, $value)
 
   90        if (!is_array($value)) {
 
   91            $value = [
'value' => (string)$value];
 
   93        $this->responseCookies[
$name] = array_replace($this->defaults, $value);
 
  104        foreach ($this->responseCookies as 
$name => $properties) {
 
  121        $result = urlencode(
$name) . 
'=' . urlencode($properties[
'value']);
 
  123        if (isset($properties[
'domain'])) {
 
  124            $result .= 
'; domain=' . $properties[
'domain'];
 
  127        if (isset($properties[
'path'])) {
 
  128            $result .= 
'; path=' . $properties[
'path'];
 
  131        if (isset($properties[
'expires'])) {
 
  132            if (is_string($properties[
'expires'])) {
 
  133                $timestamp = strtotime($properties[
'expires']);
 
  142        if (isset($properties[
'secure']) && $properties[
'secure']) {
 
  146        if (isset($properties[
'hostonly']) && $properties[
'hostonly']) {
 
  150        if (isset($properties[
'httponly']) && $properties[
'httponly']) {
 
  154        if (isset($properties[
'samesite']) && in_array(strtolower($properties[
'samesite']), [
'lax', 
'strict'], 
true)) {
 
  156            $result .= 
'; SameSite=' . $properties[
'samesite'];
 
  174        if (is_array(
$header) === 
true) {
 
  178        if (is_string(
$header) === 
false) {
 
  179            throw new InvalidArgumentException(
'Cannot parse Cookie data. Header value must be a string.');
 
  183        $pieces = preg_split(
'@[;]\s*@', 
$header);
 
  186        foreach ($pieces as $cookie) {
 
  187            $cookie = explode(
'=', $cookie, 2);
 
  189            if (count($cookie) === 2) {
 
  190                $key = urldecode($cookie[0]);
 
  191                $value = urldecode($cookie[1]);
 
  193                if (!isset($cookies[
$key])) {
 
  194                    $cookies[
$key] = $value;
 
foreach($mandatory_scripts as $file) $timestamp
An exception for terminatinating execution or to throw for unit testing.
toHeaders()
Convert to Set-Cookie headers.
static parseHeader($header)
Parse HTTP request Cookie: header and extract into a PHP associative array.
toHeader($name, array $properties)
Convert to Set-Cookie header.
setDefaults(array $settings)
Set default cookie properties.
__construct(array $cookies=[])
Create new cookies helper.
Slim Framework (https://slimframework.com)