You are here

public function CookieJar::clear in Zircon Profile 8.0

Same name in this branch
  1. 8.0 vendor/symfony/browser-kit/CookieJar.php \Symfony\Component\BrowserKit\CookieJar::clear()
  2. 8.0 vendor/guzzlehttp/guzzle/src/Cookie/CookieJar.php \GuzzleHttp\Cookie\CookieJar::clear()
Same name and namespace in other branches
  1. 8 vendor/guzzlehttp/guzzle/src/Cookie/CookieJar.php \GuzzleHttp\Cookie\CookieJar::clear()

Remove cookies currently held in the cookie jar.

Invoking this method without arguments will empty the whole cookie jar. If given a $domain argument only cookies belonging to that domain will be removed. If given a $domain and $path argument, cookies belonging to the specified path within that domain are removed. If given all three arguments, then the cookie with the specified name, path and domain is removed.

Parameters

string $domain Clears cookies matching a domain:

string $path Clears cookies matching a domain and path:

string $name Clears cookies matching a domain, path, and name:

Return value

CookieJarInterface

Overrides CookieJarInterface::clear

1 call to CookieJar::clear()
CookieJar::removeCookieIfEmpty in vendor/guzzlehttp/guzzle/src/Cookie/CookieJar.php
If a cookie already exists and the server asks to set it again with a null value, the cookie must be deleted.

File

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

Class

CookieJar
Cookie jar that stores cookies an an array

Namespace

GuzzleHttp\Cookie

Code

public function clear($domain = null, $path = null, $name = null) {
  if (!$domain) {
    $this->cookies = [];
    return;
  }
  elseif (!$path) {
    $this->cookies = array_filter($this->cookies, function (SetCookie $cookie) use ($path, $domain) {
      return !$cookie
        ->matchesDomain($domain);
    });
  }
  elseif (!$name) {
    $this->cookies = array_filter($this->cookies, function (SetCookie $cookie) use ($path, $domain) {
      return !($cookie
        ->matchesPath($path) && $cookie
        ->matchesDomain($domain));
    });
  }
  else {
    $this->cookies = array_filter($this->cookies, function (SetCookie $cookie) use ($path, $domain, $name) {
      return !($cookie
        ->getName() == $name && $cookie
        ->matchesPath($path) && $cookie
        ->matchesDomain($domain));
    });
  }
}