2011-06-08 23:45:08 -05:00
|
|
|
<?php namespace System;
|
|
|
|
|
|
|
|
|
|
class Cookie {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine if a cookie exists.
|
|
|
|
|
*
|
2011-06-15 10:23:38 -07:00
|
|
|
* @param string $name
|
2011-06-08 23:45:08 -05:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2011-06-15 10:23:38 -07:00
|
|
|
public static function has($name)
|
2011-06-08 23:45:08 -05:00
|
|
|
{
|
2011-06-16 22:45:33 -05:00
|
|
|
return ! is_null(static::get($name));
|
2011-06-08 23:45:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the value of a cookie.
|
|
|
|
|
*
|
2011-06-15 10:23:38 -07:00
|
|
|
* @param string $name
|
2011-06-08 23:45:08 -05:00
|
|
|
* @param mixed $default
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2011-06-15 10:23:38 -07:00
|
|
|
public static function get($name, $default = null)
|
2011-06-08 23:45:08 -05:00
|
|
|
{
|
2011-07-06 14:04:48 -07:00
|
|
|
return Arr::get($_COOKIE, $name, $default);
|
2011-06-08 23:45:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a "permanent" cookie. The cookie will last 5 years.
|
|
|
|
|
*
|
2011-07-21 23:54:25 -05:00
|
|
|
* @param string $name
|
|
|
|
|
* @param string $value
|
|
|
|
|
* @param string $path
|
|
|
|
|
* @param string $domain
|
|
|
|
|
* @param bool $secure
|
|
|
|
|
* @param bool $http_only
|
2011-06-08 23:45:08 -05:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2011-07-21 23:54:25 -05:00
|
|
|
public static function forever($name, $value, $path = '/', $domain = null, $secure = false, $http_only = false)
|
2011-06-08 23:45:08 -05:00
|
|
|
{
|
2011-07-21 23:54:25 -05:00
|
|
|
return static::put($name, $value, 2628000, $path, $domain, $secure, $http_only);
|
2011-06-08 23:45:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2011-06-16 20:29:21 -05:00
|
|
|
* Set the value of a cookie. If a negative number of minutes is
|
|
|
|
|
* specified, the cookie will be deleted.
|
2011-06-08 23:45:08 -05:00
|
|
|
*
|
2011-07-21 23:54:25 -05:00
|
|
|
* @param string $name
|
|
|
|
|
* @param string $value
|
|
|
|
|
* @param int $minutes
|
|
|
|
|
* @param string $path
|
|
|
|
|
* @param string $domain
|
|
|
|
|
* @param bool $secure
|
|
|
|
|
* @param bool $http_only
|
2011-06-08 23:45:08 -05:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2011-07-21 23:54:25 -05:00
|
|
|
public static function put($name, $value, $minutes = 0, $path = '/', $domain = null, $secure = false, $http_only = false)
|
2011-06-08 23:45:08 -05:00
|
|
|
{
|
|
|
|
|
if ($minutes < 0)
|
|
|
|
|
{
|
2011-06-15 10:23:38 -07:00
|
|
|
unset($_COOKIE[$name]);
|
2011-06-08 23:45:08 -05:00
|
|
|
}
|
|
|
|
|
|
2011-07-21 23:54:25 -05:00
|
|
|
return setcookie($name, $value, ($minutes != 0) ? time() + ($minutes * 60) : 0, $path, $domain, $secure, $http_only);
|
2011-06-08 23:45:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete a cookie.
|
|
|
|
|
*
|
2011-06-15 10:23:38 -07:00
|
|
|
* @param string $name
|
2011-06-08 23:45:08 -05:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2011-06-15 10:23:38 -07:00
|
|
|
public static function forget($name)
|
2011-06-08 23:45:08 -05:00
|
|
|
{
|
2011-07-26 10:01:55 -03:00
|
|
|
return static::put($name, null, -60);
|
2011-06-08 23:45:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|