key = $key ? $key : $this->key; $this->method = $method ? $method : $this->method; $this->method = ucwords($this->method); $this->project = defined('MAZE_PROJECT') ? MAZE_PROJECT : 'default'; $this->key($this->key); return $this; } /** * add * @param string $key * @param mixed $value * * @return mixed */ public function add($key, $value, $time = 3600) { $key = $this->project . '_' . $key; $value = Security::encode(base64_encode(serialize($value)), $this->key); $method = '_set' . $this->method; $this->$method($key, $value, $time); return $value; } /** * get * @param string $key * @param mixed $type * * @return mixed */ public function get($key, $type = false) { $key = $this->project . '_' . $key; $method = '_get' . $this->method; $value = $this->$method($key); $type == false && $value = Security::decode($value, $this->key); $value = unserialize(base64_decode($value)); return $value; } /** * un * @param string $key * * @return mixed */ public function un($key) { $key = $this->project . '_' . $key; $method = '_unset' . $this->method; return $this->$method($key); } /** * key * @param string $key * * @return mixed */ private function key($key) { $this->key = $this->prefix . '_' . $this->method . '_' . $key; } /** * _setCookie * @param string $key * @param string $value * * @return mixed */ private function _setCookie($key, $value, $time = 3600) { return setCookie($this->prefix . $key, $value, time() + $time, "/", Config::$global['host']['cookie']); } /** * _getCookie * @param string $key * * @return mixed */ private function _getCookie($key) { return isset($_COOKIE[$this->prefix . $key]) ? $_COOKIE[$this->prefix . $key] : false; } /** * _unsetCookie * @param string $key * * @return mixed */ private function _unsetCookie($key) { return setCookie($this->prefix . $key, false, time() - 3600, "/", Config::$global['host']['cookie']); } /** * _setSession * @param string $key * @param string $value * * @return mixed */ private function _setSession($key, $value, $time = 3600) { return $_SESSION[$this->prefix . $key] = $value; } /** * _getSession * @param string $key * * @return mixed */ private function _getSession($key) { return (isset($_SESSION[$this->prefix . $key]) && $_SESSION[$this->prefix . $key]) ? $_SESSION[$this->prefix . $key] : false; } /** * _unsetSession * @param string $key * * @return mixed */ private function _unsetSession($key) { unset($_SESSION[$this->prefix . $key]); return true; } }