2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
2016-08-19 00:51:35 +02:00
|
|
|
|
|
|
|
namespace SilverStripe\Control;
|
|
|
|
|
|
|
|
use SilverStripe\Core\Config\Configurable;
|
|
|
|
use SilverStripe\Core\Injector\Injector;
|
|
|
|
|
2008-02-25 03:10:37 +01:00
|
|
|
/**
|
|
|
|
* A set of static methods for manipulating cookies.
|
|
|
|
*/
|
2016-11-29 00:31:16 +01:00
|
|
|
class Cookie
|
|
|
|
{
|
|
|
|
use Configurable;
|
2012-06-29 18:32:47 +02:00
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
/**
|
|
|
|
* @config
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private static $report_errors = true;
|
2012-06-29 18:32:47 +02:00
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
/**
|
|
|
|
* Fetch the current instance of the cookie backend.
|
|
|
|
*
|
|
|
|
* @return Cookie_Backend
|
|
|
|
*/
|
|
|
|
public static function get_inst()
|
|
|
|
{
|
|
|
|
return Injector::inst()->get('SilverStripe\\Control\\Cookie_Backend');
|
|
|
|
}
|
2012-06-29 18:32:47 +02:00
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
/**
|
|
|
|
* Set a cookie variable.
|
|
|
|
*
|
|
|
|
* Expiry time is set in days, and defaults to 90.
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param mixed $value
|
2020-09-10 02:34:33 +02:00
|
|
|
* @param float $expiry
|
2016-11-29 00:31:16 +01:00
|
|
|
* @param string $path
|
|
|
|
* @param string $domain
|
|
|
|
* @param bool $secure
|
|
|
|
* @param bool $httpOnly
|
|
|
|
*
|
|
|
|
* See http://php.net/set_session
|
|
|
|
*/
|
|
|
|
public static function set(
|
|
|
|
$name,
|
|
|
|
$value,
|
|
|
|
$expiry = 90,
|
|
|
|
$path = null,
|
|
|
|
$domain = null,
|
|
|
|
$secure = false,
|
|
|
|
$httpOnly = true
|
|
|
|
) {
|
|
|
|
return self::get_inst()->set($name, $value, $expiry, $path, $domain, $secure, $httpOnly);
|
|
|
|
}
|
2012-06-29 18:32:47 +02:00
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
/**
|
|
|
|
* Get the cookie value by name. Returns null if not set.
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @param bool $includeUnsent
|
|
|
|
*
|
|
|
|
* @return null|string
|
|
|
|
*/
|
|
|
|
public static function get($name, $includeUnsent = true)
|
|
|
|
{
|
|
|
|
return self::get_inst()->get($name, $includeUnsent);
|
|
|
|
}
|
2012-06-29 18:32:47 +02:00
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
/**
|
|
|
|
* Get all the cookies.
|
|
|
|
*
|
|
|
|
* @param bool $includeUnsent
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public static function get_all($includeUnsent = true)
|
|
|
|
{
|
|
|
|
return self::get_inst()->getAll($includeUnsent);
|
|
|
|
}
|
2012-06-29 18:32:47 +02:00
|
|
|
|
2016-11-29 00:31:16 +01:00
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
* @param null|string $path
|
|
|
|
* @param null|string $domain
|
|
|
|
* @param bool $secure
|
|
|
|
* @param bool $httpOnly
|
|
|
|
*/
|
|
|
|
public static function force_expiry($name, $path = null, $domain = null, $secure = false, $httpOnly = true)
|
|
|
|
{
|
|
|
|
return self::get_inst()->forceExpiry($name, $path, $domain, $secure, $httpOnly);
|
|
|
|
}
|
2012-02-16 02:59:56 +01:00
|
|
|
}
|