diff options
author | Morris Jobke <hey@morrisjobke.de> | 2014-11-28 10:16:22 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2014-11-28 10:16:22 +0100 |
commit | b188710af33fde461a57e81dfc4aaf1cf7c6fda5 (patch) | |
tree | 3d66021b2507fc28e887b5c4b647a65ae11ef654 /lib/public | |
parent | 7a9af8c40c4ff2c2005a304a6474e9f328a3be5c (diff) | |
parent | e35feadac2ed68f0aad911713cb3d5f8725707e6 (diff) | |
download | nextcloud-server-b188710af33fde461a57e81dfc4aaf1cf7c6fda5.tar.gz nextcloud-server-b188710af33fde461a57e81dfc4aaf1cf7c6fda5.zip |
Merge pull request #12472 from owncloud/modifyCookies
Add functions to modify cookies to response class
Diffstat (limited to 'lib/public')
-rw-r--r-- | lib/public/appframework/http/response.php | 73 | ||||
-rw-r--r-- | lib/public/iservercontainer.php | 7 |
2 files changed, 75 insertions, 5 deletions
diff --git a/lib/public/appframework/http/response.php b/lib/public/appframework/http/response.php index 354911fee21..67e72cff6d9 100644 --- a/lib/public/appframework/http/response.php +++ b/lib/public/appframework/http/response.php @@ -46,8 +46,15 @@ class Response { /** + * Cookies that will be need to be constructed as header + * @var array + */ + private $cookies = array(); + + + /** * HTTP status code - defaults to STATUS OK - * @var string + * @var int */ private $status = Http::STATUS_OK; @@ -70,6 +77,7 @@ class Response { * Caches the response * @param int $cacheSeconds the amount of seconds that should be cached * if 0 then caching will be disabled + * @return $this */ public function cacheFor($cacheSeconds) { @@ -83,13 +91,68 @@ class Response { return $this; } + /** + * Adds a new cookie to the response + * @param string $name The name of the cookie + * @param string $value The value of the cookie + * @param \DateTime|null $expireDate Date on that the cookie should expire, if set + * to null cookie will be considered as session + * cookie. + * @return $this + */ + public function addCookie($name, $value, \DateTime $expireDate = null) { + $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate); + return $this; + } + + + /** + * Set the specified cookies + * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null)) + * @return $this + */ + public function setCookies(array $cookies) { + $this->cookies = $cookies; + return $this; + } + + + /** + * Invalidates the specified cookie + * @param string $name + * @return $this + */ + public function invalidateCookie($name) { + $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00')); + return $this; + } + + /** + * Invalidates the specified cookies + * @param array $cookieNames array('foo', 'bar') + * @return $this + */ + public function invalidateCookies(array $cookieNames) { + foreach($cookieNames as $cookieName) { + $this->invalidateCookie($cookieName); + } + return $this; + } + + /** + * Returns the cookies + * @return array + */ + public function getCookies() { + return $this->cookies; + } /** * Adds a new header to the response that will be called before the render * function * @param string $name The name of the HTTP header * @param string $value The value, null will delete it - * @return Response Reference to this object + * @return $this */ public function addHeader($name, $value) { $name = trim($name); // always remove leading and trailing whitespace @@ -108,10 +171,10 @@ class Response { /** * Set the headers - * @param array key value header pairs - * @return Response Reference to this object + * @param array $headers value header pairs + * @return $this */ - public function setHeaders($headers) { + public function setHeaders(array $headers) { $this->headers = $headers; return $this; diff --git a/lib/public/iservercontainer.php b/lib/public/iservercontainer.php index b734d1b4161..301f47c68fa 100644 --- a/lib/public/iservercontainer.php +++ b/lib/public/iservercontainer.php @@ -298,4 +298,11 @@ interface IServerContainer { * @return \OCP\App\IAppManager */ function getAppManager(); + + /** + * Get the webroot + * + * @return string + */ + function getWebRoot(); } |