Skip to content

Commit

Permalink
[BrowserKit] fixed BC break done recently
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Apr 29, 2013
1 parent 372a76a commit 25b8b84
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions src/Symfony/Component/BrowserKit/CookieJar.php
Expand Up @@ -37,6 +37,11 @@ public function set(Cookie $cookie)
/**
* 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).
*
* @param string $name The cookie name
* @param string $path The cookie path
* @param string $domain The cookie domain
Expand All @@ -49,12 +54,27 @@ public function get($name, $path = '/', $domain = null)
{
$this->flushExpiredCookies();

return isset($this->cookieJar[$domain][$path][$name]) ? $this->cookieJar[$domain][$path][$name] : null;
if (!empty($domain)) {
return isset($this->cookieJar[$domain][$path][$name]) ? $this->cookieJar[$domain][$path][$name] : null;
}

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

return null;
}

/**
* Removes a cookie by name.
*
* You should never use an empty domain, but if you do so,
* all cookies for the given name/path expire (this behavior
* ensures a BC behavior with previous versions of Symfony).
*
* @param string $name The cookie name
* @param string $path The cookie path
* @param string $domain The cookie domain
Expand All @@ -67,13 +87,23 @@ public function expire($name, $path = '/', $domain = null)
$path = '/';
}

unset($this->cookieJar[$domain][$path][$name]);
if (empty($domain)) {
// an empty domain means any domain
// this should never happen but it allows for a better BC
$domains = array_keys($this->cookieJar);
} else {
$domains = array($domain);
}

if (empty($this->cookieJar[$domain][$path])) {
unset($this->cookieJar[$domain][$path]);
foreach ($domains as $domain) {
unset($this->cookieJar[$domain][$path][$name]);

if (empty($this->cookieJar[$domain])) {
unset($this->cookieJar[$domain]);
if (empty($this->cookieJar[$domain][$path])) {
unset($this->cookieJar[$domain][$path]);

if (empty($this->cookieJar[$domain])) {
unset($this->cookieJar[$domain]);
}
}
}
}
Expand Down

0 comments on commit 25b8b84

Please sign in to comment.