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

Breadcrumb

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

function CookieJar::get

Gets a cookie by name.

You should never use an empty domain, but if you do so, this method returns the first cookie for the given name/path (this behavior ensures a BC behavior with previous versions of Symfony).

File

vendor/symfony/browser-kit/CookieJar.php, line 38

Class

CookieJar
CookieJar.

Namespace

Symfony\Component\BrowserKit

Code

public function get(string $name, string $path = '/', ?string $domain = null) : ?Cookie {
    $this->flushExpiredCookies();
    foreach ($this->cookieJar as $cookieDomain => $pathCookies) {
        if ($cookieDomain && $domain) {
            $cookieDomain = '.' . ltrim($cookieDomain, '.');
            if (!str_ends_with('.' . $domain, $cookieDomain)) {
                continue;
            }
        }
        foreach ($pathCookies as $cookiePath => $namedCookies) {
            if (!str_starts_with($path, $cookiePath)) {
                continue;
            }
            if (isset($namedCookies[$name])) {
                return $namedCookies[$name];
            }
        }
    }
    return null;
}
RSS feed
Powered by Drupal