You are here

public function CookieJar::get in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/browser-kit/CookieJar.php \Symfony\Component\BrowserKit\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).

Parameters

string $name The cookie name:

string $path The cookie path:

string $domain The cookie domain:

Return value

Cookie|null A Cookie instance or null if the cookie does not exist

File

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

Class

CookieJar
CookieJar.

Namespace

Symfony\Component\BrowserKit

Code

public function get($name, $path = '/', $domain = null) {
  $this
    ->flushExpiredCookies();
  if (!empty($domain)) {
    foreach ($this->cookieJar as $cookieDomain => $pathCookies) {
      if ($cookieDomain) {
        $cookieDomain = '.' . ltrim($cookieDomain, '.');
        if ($cookieDomain != substr('.' . $domain, -strlen($cookieDomain))) {
          continue;
        }
      }
      foreach ($pathCookies as $cookiePath => $namedCookies) {
        if ($cookiePath != substr($path, 0, strlen($cookiePath))) {
          continue;
        }
        if (isset($namedCookies[$name])) {
          return $namedCookies[$name];
        }
      }
    }
    return;
  }

  // avoid relying on this behavior that is mainly here for BC reasons
  foreach ($this->cookieJar as $cookies) {
    if (isset($cookies[$path][$name])) {
      return $cookies[$path][$name];
    }
  }
}