Commit 65bbea81 authored by Taylor Otwell's avatar Taylor Otwell

Put the Cookie class on a diet.

parent d1f1c367
......@@ -2,91 +2,6 @@
class Cookie {
/**
* The cookie name.
*
* @var string
*/
public $name;
/**
* The cookie value.
*
* @var mixed
*/
public $value;
/**
* The number of minutes the cookie should live.
*
* @var int
*/
public $lifetime = 0;
/**
* The path for which the cookie is available.
*
* @var string
*/
public $path = '/';
/**
* The domain for which the cookie is available.
*
* @var string
*/
public $domain = null;
/**
* Indicates if the cookie should only be sent over HTTPS.
*
* @var bool
*/
public $secure = false;
/**
* Create a new Cookie instance.
*
* Note: Cookies can be sent using the Cookie::put method.
* However, the number of parameters that method requires
* is somewhat cumbersome. Instantiating a new Cookie class
* and setting the properties can be a little easier on the eyes.
*
* @param string $name
* @return void
*/
public function __construct($name, $value = null)
{
$this->name = $name;
$this->value = $value;
}
/**
* Create a new Cookie instance.
*
* @param string $name
* @return Cookie
*/
public static function make($name, $value = null)
{
return new static($name, $value);
}
/**
* Send the current cookie instance to the user's machine.
*
* @return bool
*/
public function send()
{
if (is_null($this->name))
{
throw new \Exception("Attempting to send cookie without a name.");
}
return static::put($this->name, $this->value, $this->lifetime, $this->path, $this->domain, $this->secure);
}
/**
* Determine if a cookie exists.
*
......@@ -107,7 +22,7 @@ class Cookie {
*/
public static function get($name, $default = null)
{
return (array_key_exists($name, $_COOKIE)) ? $_COOKIE[$name] : $default;
return Arr::get($_COOKIE, $name, $default);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment