Cookie 设置、获取、删除

@param string $name cookie名称
@param mixed $value cookie值
@param mixed $option 可选参数 可能会是 null|integer|string

@return mixed
775872
public static function set($name, $value = '', $option = null) {
        self::driver()->set($name, $value, $option);
    }
1254965
public function update($name, $value)
    {

        $cookie_name = $this->getName($name);

        if (isset($_COOKIE[$cookie_name])) {

            $old_cookie_value = $this->authcode($_COOKIE[$cookie_name], 'DECODE', $this->_securekey);
            $old_cookie_value = $this->unpack($old_cookie_value);

            if (isset($old_cookie_value[1]) && $old_cookie_vlaue[1] > 0) { // 获取之前的过期时间

                $cookie_expire = $old_cookie_value[1];

                // 更新数据
                $cookie_value = $this->pack($value, $cookie_expire);
                $cookie_value = $this->authcode($cookie_value, 'ENCODE', $this->_securekey);

                if ($cookie_name && $cookie_value && $cookie_expire) {
                    setcookie($cookie_name, $cookie_value, $cookie_expire, '/');
                    return true;
                }
            }
        }
        return false;
    }
950578
public function color($name, $value = null, $options = array())
    {
		return $this->input('color', $name, $value, $options);
    }
641626
public static function set($cacheName, $value = null, $option = array(), $alias = null)
	{
		$obj = self::getInstance($alias);
		if ($obj)
		{
			return $obj->set($cacheName, $value, $option);
		}
		else
		{
			return false;
		}
	}
942124
public function cookie($name, $value = null, $expiry = null, array $options = [])
    {
        if (! is_null($value)) {
            return $this->addCookie($name, $value, $expiry, $options);
        }

        if ($cookie = $this->driver->manage()->getCookieNamed($name)) {
            return decrypt(rawurldecode($cookie['value']), $unserialize = false);
        }
    }
1310593
public function cookie($key = '', $value = '', $options = null)
    {
        $defaultOptions = [
            'prefix' => '',
            'expire' => 86400,
            'path' => '/',
            'secure' => false,
            'httponly' => false,
        ];

        if (!is_null($options)) {
            if (is_numeric($options)) {
                $options = ['expire' => $options];
            } elseif (is_string($options)) {
                parse_str($options, $options);
            }

            $options = array_merge($defaultOptions, array_change_key_case($options));
        }

        if (!empty($options['httponly'])) {
            ini_set('session.cookie_httponly', 1);
        }

        if (is_null($key)) {
            if (empty($_COOKIE)) {
                return null;
            }

            $prefix = empty($value) ? $options['prefix'] : $value;
            if (!empty($prefix)) {
                foreach ($_COOKIE as $key => $val) {
                    if (0 === stripos($key, $prefix)) {
                        setcookie($key, '', time() - 3600, $options['path'], $options['domain'], $options['secure'], $options['httponly']);
                        unset($_COOKIE[$key]);
                    }
                }
            }

            return null;
        } elseif ('' === $key) {
            // Get All Cookie
            return $_COOKIE;
        }

        $key = $options['prefix'] . str_replace('.', '_', $key);
        if ('' === $value) {
            if (isset($_COOKIE[$key])) {
                $value = $_COOKIE[$key];
                if (0 === strpos($value, 'kotori:')) {
                    $value = substr($value, 6);
                    return array_map('urldecode', json_decode(MAGIC_QUOTES_GPC ? stripslashes($value) : $value, true));
                } else {
                    return $value;
                }
            } else {
                return null;
            }
        } else {
            if (is_null($value)) {
                setcookie($key, '', time() - 3600, $options['path'], $options['domain'], $options['secure'], $options['httponly']);
                unset($_COOKIE[$key]); // Delete Cookie
            } else {
                // Set Cookie
                if (is_array($value)) {
                    $value = 'kotori:' . json_encode(array_map('urlencode', $value));
                }

                $expire = !empty($options['expire']) ? time() + intval($options['expire']) : 0;
                setcookie($key, $value, $expire, $options['path'], $options['domain'], $options['secure'], $options['httponly']);
                $_COOKIE[$key] = $value;
            }
        }

        return null;
    }
75918
public function setOption($name, $value)
    {
        if (! in_array($name, $this->validOptions)) {
            throw new Error('Invalid option ' . $name . '. Valid options are : ' . join(', ', $this->validOptions));
        }
        // Check duplicate fields in header
        if ('header' == $name) {
            $cnt = array_count_values($value);
            $duplicates = array();
            foreach ($cnt as $f => $c) {
                if ($c > 1) {
                    $duplicates[$f] = $c;
                }
            }
            if (sizeof($duplicates) > 0) {
                $msg = 'Duplicate fields found in header : ' . join(', ', array_keys($duplicates));
                throw new Error($msg);
            }
        }
        $this->$name = $value;

        return $this;
    }
314316
protected function setCookie($name, $value, $expire, $option = [])
    {
        WorkerHttp::setCookie($name, $value, $expire, $option['path'], $option['domain'], $option['secure'], $option['httponly']);
    }
284473
public static function set($name, $value, $expired = null)
    {
        // 处理过期时间
        if (null === $expired)
        {
            $expired = Cookie::$expiration;
        }
        if ($expired !== 0)
        {
            $expired += time();
        }

        // Add the salt to the cookie value
        $value = Cookie::salt($name, $value) . '~' . $value;

        return Base::getHttp()->setCookie($name, $value, $expired, Cookie::$path, Cookie::$domain, Cookie::$secure, Cookie::$httpOnly);
    }
312213
public static function email($name, $value = null, array $options = [])
    {
        self::exclure($options);

        return self::input('email', $name, $value, $options);
    }
490693
public function setCookie($name, $value = null) {
    if ($value === null) {
      $this->browser->removeCookie($name);
    }
    //TODO: set the cookie with domain, not with url, meaning www.aaa.com or .aaa.com
    if ($value !== null) {
      $urlData = parse_url($this->getCurrentUrl());
      $cookie = array("name" => $name, "value" => $value, "domain" => $urlData["host"]);
      $this->browser->setCookie($cookie);
    }
  }
1309085
public function setOption($name, $value) {
		$all = [];
		for ($i = 1; $i <= $this->connection_count; $i++) {
			$connection = $this->getConnection();
			$connection->setOption($name, $value);
			$all[] = $connection;
		}
		foreach ($all as $v) {
			$this->freeConnection($v);
		}
	}
292546
public static function url($name, $value = null, array $options = [])
    {
        self::exclure($options);

        return self::input('url', $name, $value, $options);
    }
287735
public function option($name, $value = '')
    {
        if (is_array($name)) {
            $this->option = array_merge($this->option, $name);
        } else {
            $this->option[$name] = $value;
        }

        return $this;
    }
468623
public function setRawCookie($name, $value = '', array $options = [])
    {
        $this->assignCookieHeader($name, $value, $options);

        return $this;
    }
804842
public static function forever($name, $value = '', $option = null) {
        self::driver()->forever($name, $value, $option);
    }
1343608
private function setCookie(string $name, $value)
    {
        $expiry = $this->transient ? 0 : (time() + 2629743);
        $sessionParameters = session_get_cookie_params();
        setcookie(
            $name,
            $value,
            $expiry,
            '/',
            $sessionParameters['domain'],
            $this->secure,
            true
        );
    }