123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php namespace System;
- class Cookie {
-
- public $name;
-
- public $value;
-
- public $lifetime = 0;
-
- public $path = '/';
-
- public $domain = null;
-
- public $secure = false;
-
- public function __construct($name, $value = null)
- {
- $this->name = $name;
- $this->value = $value;
- }
-
- public static function make($name, $value = null)
- {
- return new static($name, $value);
- }
-
- 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);
- }
-
- public static function has($name)
- {
- return ! is_null(static::get($name));
- }
-
- public static function get($name, $default = null)
- {
- return Arr::get($_COOKIE, $name, $default);
- }
-
- public static function forever($name, $value, $path = '/', $domain = null, $secure = false)
- {
- return static::put($name, $value, 2628000, $path, $domain, $secure);
- }
-
- public static function put($name, $value, $minutes = 0, $path = '/', $domain = null, $secure = false)
- {
- if ($minutes < 0)
- {
- unset($_COOKIE[$name]);
- }
- return setcookie($name, $value, ($minutes != 0) ? time() + ($minutes * 60) : 0, $path, $domain, $secure);
- }
-
- public static function forget($name)
- {
- return static::put($key, null, -60);
- }
- }
|