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
|
2015-11-13 23:44:49 +01:00
|
|
|
*
|
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
|
2015-11-13 23:44:49 +01:00
|
|
|
*
|
|
|
|
* @var bool
|
2011-12-17 02:21:09 +01:00
|
|
|
*/
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $report_errors = true;
|
2012-06-29 18:32:47 +02:00
|
|
|
|
|
|
|
/**
|
2015-11-13 23:44:49 +01:00
|
|
|
* Fetch the current instance of the cookie backend.
|
2014-05-04 15:34:58 +02:00
|
|
|
*
|
2015-11-13 23:44:49 +01:00
|
|
|
* @return 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
|
|
|
/**
|
2015-11-13 23:44:49 +01:00
|
|
|
* Set a cookie variable.
|
|
|
|
*
|
|
|
|
* Expiry time is set in days, and defaults to 90.
|
2012-06-29 18:32:47 +02:00
|
|
|
*
|
2015-11-13 23:44:49 +01:00
|
|
|
* @param string $name
|
|
|
|
* @param mixed $value
|
|
|
|
* @param int $expiry
|
|
|
|
* @param string $path
|
|
|
|
* @param string $domain
|
|
|
|
* @param bool $secure
|
|
|
|
* @param bool $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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-11-13 23:44:49 +01:00
|
|
|
* Get the cookie value by name. Returns null if not set.
|
2012-07-10 10:06:05 +02:00
|
|
|
*
|
2015-11-13 23:44:49 +01:00
|
|
|
* @param string $name
|
|
|
|
* @param bool $includeUnsent
|
2014-09-26 06:01:23 +02:00
|
|
|
*
|
2015-11-13 23:44:49 +01:00
|
|
|
* @return null|string
|
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
|
|
|
/**
|
2015-11-13 23:44:49 +01:00
|
|
|
* Get all the cookies.
|
|
|
|
*
|
|
|
|
* @param bool $includeUnsent
|
2014-09-26 06:01:23 +02:00
|
|
|
*
|
2015-11-13 23:44:49 +01:00
|
|
|
* @return array
|
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
|
|
|
|
2012-07-10 10:06:05 +02:00
|
|
|
/**
|
2015-11-13 23:44:49 +01:00
|
|
|
* @param string $name
|
|
|
|
* @param null|string $path
|
|
|
|
* @param null|string $domain
|
|
|
|
* @param bool $secure
|
|
|
|
* @param bool $httpOnly
|
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
|
|
|
}
|
2012-02-16 02:59:56 +01:00
|
|
|
}
|