2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
|
|
|
* A set of static methods for manipulating cookies.
|
2011-12-17 02:21:09 +01:00
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2008-02-25 03:10:37 +01:00
|
|
|
* @subpackage misc
|
|
|
|
*/
|
2010-05-25 06:19:57 +02:00
|
|
|
class Cookie {
|
2012-06-29 18:32:47 +02:00
|
|
|
|
2011-12-17 02:21:09 +01:00
|
|
|
/**
|
2013-03-21 19:48:54 +01:00
|
|
|
* @config
|
2011-12-17 02:21:09 +01:00
|
|
|
* @var boolean
|
|
|
|
*/
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $report_errors = true;
|
2012-06-29 18:32:47 +02:00
|
|
|
|
|
|
|
/**
|
2014-05-04 15:34:58 +02:00
|
|
|
* Fetch the current instance of the cookie backend
|
|
|
|
*
|
|
|
|
* @return Cookie_Backend The cookie backend
|
2012-06-29 18:32:47 +02:00
|
|
|
*/
|
|
|
|
public static function get_inst() {
|
2014-05-04 15:34:58 +02:00
|
|
|
return Injector::inst()->get('Cookie_Backend');
|
2012-06-29 18:32:47 +02:00
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Set a cookie variable
|
2012-06-29 18:32:47 +02:00
|
|
|
*
|
2009-09-10 05:22:50 +02:00
|
|
|
* @param string $name The variable name
|
2012-07-10 10:06:05 +02:00
|
|
|
* @param mixed $value The variable value.
|
2011-12-17 02:21:09 +01:00
|
|
|
* @param int $expiry The expiry time, in days. Defaults to 90.
|
2009-09-10 05:22:50 +02:00
|
|
|
* @param string $path See http://php.net/set_session
|
|
|
|
* @param string $domain See http://php.net/set_session
|
|
|
|
* @param boolean $secure See http://php.net/set_session
|
2012-03-31 09:08:54 +02:00
|
|
|
* @param boolean $httpOnly See http://php.net/set_session
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2014-08-15 08:53:05 +02:00
|
|
|
public static function set($name, $value, $expiry = 90, $path = null, $domain = null, $secure = false,
|
2014-09-24 07:38:09 +02:00
|
|
|
$httpOnly = true
|
2012-10-03 16:16:19 +02:00
|
|
|
) {
|
2014-05-04 15:34:58 +02:00
|
|
|
return self::get_inst()->set($name, $value, $expiry, $path, $domain, $secure, $httpOnly);
|
2012-06-29 18:32:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-26 06:01:23 +02:00
|
|
|
* Get the cookie value by name
|
2012-07-10 10:06:05 +02:00
|
|
|
*
|
2014-09-26 06:01:23 +02:00
|
|
|
* @param string $name The name of the cookie to get
|
|
|
|
* @param boolean $includeUnsent Include cookies we've yet to send when fetching values
|
|
|
|
*
|
|
|
|
* @return string|null The cookie value or null if unset
|
2012-07-10 10:06:05 +02:00
|
|
|
*/
|
2014-09-26 06:01:23 +02:00
|
|
|
public static function get($name, $includeUnsent = true) {
|
|
|
|
return self::get_inst()->get($name, $includeUnsent);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2012-06-29 18:32:47 +02:00
|
|
|
|
2012-07-10 10:06:05 +02:00
|
|
|
/**
|
2014-09-26 06:01:23 +02:00
|
|
|
* Get all the cookies
|
|
|
|
*
|
|
|
|
* @param boolean $includeUnsent Include cookies we've yet to send
|
|
|
|
* @return array All the cookies
|
2012-07-10 10:06:05 +02:00
|
|
|
*/
|
2014-09-26 06:01:23 +02:00
|
|
|
public static function get_all($includeUnsent = true) {
|
|
|
|
return self::get_inst()->getAll($includeUnsent);
|
2008-11-22 04:33:00 +01:00
|
|
|
}
|
2012-06-29 18:32:47 +02:00
|
|
|
|
2015-08-21 04:01:10 +02:00
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
|
|
|
public static function forceExpiry($name, $path = null, $domain = null) {
|
|
|
|
Deprecation::notice('4.0', 'Use Cookie::force_expiry instead.');
|
|
|
|
|
|
|
|
return self::force_expiry($name, $path, $domain);
|
|
|
|
}
|
|
|
|
|
2012-07-10 10:06:05 +02:00
|
|
|
/**
|
2014-09-26 06:01:23 +02:00
|
|
|
* @param string
|
|
|
|
* @param string
|
|
|
|
* @param string
|
2012-07-10 10:06:05 +02:00
|
|
|
*/
|
2014-09-26 06:01:23 +02:00
|
|
|
public static function force_expiry($name, $path = null, $domain = null, $secure = false, $httpOnly = true) {
|
|
|
|
return self::get_inst()->forceExpiry($name, $path, $domain, $secure, $httpOnly);
|
2008-11-22 04:33:00 +01:00
|
|
|
}
|
2015-08-21 04:01:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
|
|
|
public static function set_report_errors($reportErrors) {
|
|
|
|
Deprecation::notice('4.0', 'Use "Cookie.report_errors" config setting instead');
|
|
|
|
Config::inst()->update('Cookie', 'report_errors', $reportErrors);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
*/
|
|
|
|
public static function report_errors() {
|
|
|
|
Deprecation::notice('4.0', 'Use "Cookie.report_errors" config setting instead');
|
|
|
|
return Config::inst()->get('Cookie', 'report_errors');
|
|
|
|
}
|
2012-02-16 02:59:56 +01:00
|
|
|
}
|