merged branch fabpot/cookies (PR #7879)
This PR was merged into the 2.1 branch.
Discussion
----------
[BrowserKit] fixed BC break done recently
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
This PR tries to avoid a BC break that was introduced recently in the management of cookies (see #7738).
see fabpot/Silex#684
Commits
-------
25b8b84
[BrowserKit] fixed BC break done recently
This commit is contained in:
commit
02e9b19f29
@ -37,6 +37,11 @@ class CookieJar
|
||||
/**
|
||||
* 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
|
||||
@ -49,12 +54,27 @@ class CookieJar
|
||||
{
|
||||
$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
|
||||
@ -67,13 +87,23 @@ class CookieJar
|
||||
$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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user