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

Breadcrumb

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

function CookieJar::setCookie

Overrides CookieJarInterface::setCookie

4 calls to CookieJar::setCookie()
CookieJar::extractCookies in vendor/guzzlehttp/guzzle/src/Cookie/CookieJar.php
Extract cookies from an HTTP response and store them in the CookieJar.
CookieJar::__construct in vendor/guzzlehttp/guzzle/src/Cookie/CookieJar.php
FileCookieJar::load in vendor/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php
Load cookies from a JSON formatted file.
SessionCookieJar::load in vendor/guzzlehttp/guzzle/src/Cookie/SessionCookieJar.php
Load the contents of the client session into the data array

File

vendor/guzzlehttp/guzzle/src/Cookie/CookieJar.php, line 149

Class

CookieJar
Cookie jar that stores cookies as an array

Namespace

GuzzleHttp\Cookie

Code

public function setCookie(SetCookie $cookie) : bool {
    // If the name string is empty (but not 0), ignore the set-cookie
    // string entirely.
    $name = $cookie->getName();
    if (!$name && $name !== '0') {
        return false;
    }
    // Only allow cookies with set and valid domain, name, value
    $result = $cookie->validate();
    if ($result !== true) {
        if ($this->strictMode) {
            throw new \RuntimeException('Invalid cookie: ' . $result);
        }
        $this->removeCookieIfEmpty($cookie);
        return false;
    }
    // Resolve conflicts with previously set cookies
    foreach ($this->cookies as $i => $c) {
        // Two cookies are identical, when their path, and domain are
        // identical.
        if ($c->getPath() != $cookie->getPath() || $c->getDomain() != $cookie->getDomain() || $c->getName() != $cookie->getName()) {
            continue;
        }
        // The previously set cookie is a discard cookie and this one is
        // not so allow the new cookie to be set
        if (!$cookie->getDiscard() && $c->getDiscard()) {
            unset($this->cookies[$i]);
            continue;
        }
        // If the new cookie's expiration is further into the future, then
        // replace the old cookie
        if ($cookie->getExpires() > $c->getExpires()) {
            unset($this->cookies[$i]);
            continue;
        }
        // If the value has changed, we better change it
        if ($cookie->getValue() !== $c->getValue()) {
            unset($this->cookies[$i]);
            continue;
        }
        // The cookie exists, so no need to continue
        return false;
    }
    $this->cookies[] = $cookie;
    return true;
}

API Navigation

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