Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SetCookie.php

function SetCookie::__construct

Parameters

array $data Array of cookie data provided by a Cookie parser:

File

vendor/guzzlehttp/guzzle/src/Cookie/SetCookie.php, line 81

Class

SetCookie
Set-Cookie object

Namespace

GuzzleHttp\Cookie

Code

public function __construct(array $data = []) {
    $this->data = self::$defaults;
    if (isset($data['Name'])) {
        $this->setName($data['Name']);
    }
    if (isset($data['Value'])) {
        $this->setValue($data['Value']);
    }
    if (isset($data['Domain'])) {
        $this->setDomain($data['Domain']);
    }
    if (isset($data['Path'])) {
        $this->setPath($data['Path']);
    }
    if (isset($data['Max-Age'])) {
        $this->setMaxAge($data['Max-Age']);
    }
    if (isset($data['Expires'])) {
        $this->setExpires($data['Expires']);
    }
    if (isset($data['Secure'])) {
        $this->setSecure($data['Secure']);
    }
    if (isset($data['Discard'])) {
        $this->setDiscard($data['Discard']);
    }
    if (isset($data['HttpOnly'])) {
        $this->setHttpOnly($data['HttpOnly']);
    }
    // Set the remaining values that don't have extra validation logic
    foreach (array_diff(array_keys($data), array_keys(self::$defaults)) as $key) {
        $this->data[$key] = $data[$key];
    }
    // Extract the Expires value and turn it into a UNIX timestamp if needed
    if (!$this->getExpires() && $this->getMaxAge()) {
        // Calculate the Expires date
        $this->setExpires(\time() + $this->getMaxAge());
    }
    elseif (null !== ($expires = $this->getExpires()) && !\is_numeric($expires)) {
        $this->setExpires($expires);
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal