Aprhont - Adding cookie-prefix, as config option, and into cookie methods

Summary: Cookie-prefix should fix phabricator instances where x.com and x.y.com have conflicting cookie names

Test Plan: Pushed branch to dev.phab.example.com, logged into phab.example.com and into dev.phab.example.com.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Differential Revision: https://secure.phabricator.com/D7979
This commit is contained in:
Alex Arwine
2014-01-17 08:07:57 -08:00
committed by epriestley
parent c40420eb74
commit e6a6c265b0
3 changed files with 29 additions and 0 deletions

View File

@@ -273,11 +273,26 @@ final class AphrontRequest {
return $this->validateCSRF();
}
final public function setCookiePrefix($prefix) {
$this->cookiePrefix = $prefix;
return $this;
}
final private function getPrefixedCookieName($name) {
if (strlen($this->cookiePrefix)) {
return $this->cookiePrefix.'_'.$name;
} else {
return $name;
}
}
final public function getCookie($name, $default = null) {
$name = $this->getPrefixedCookieName($name);
return idx($_COOKIE, $name, $default);
}
final public function clearCookie($name) {
$name = $this->getPrefixedCookieName($name);
$this->setCookie($name, '', time() - (60 * 60 * 24 * 30));
unset($_COOKIE[$name]);
}
@@ -342,6 +357,7 @@ final class AphrontRequest {
$expire = time() + (60 * 60 * 24 * 365 * 5);
}
$name = $this->getPrefixedCookieName($name);
if (php_sapi_name() == 'cli') {
// Do nothing, to avoid triggering "Cannot modify header information"