123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- <?php namespace Maze\Session;
- use Maze\Security\Internal as Security;
- use Maze\Config\Load as Config;
- @header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
- @session_start();
- ini_set('session.cookie_domain', Config::$global['host']['cookie']);
- class Save
- {
- /**
- * key
- *
- * @var string
- */
- private $key = '';
-
- /**
- * prefix
- *
- * @var string
- */
- private $prefix = 'maze';
-
- /**
- * project
- *
- * @var string
- */
- private $project = '';
- /**
- * method
- *
- * @var string
- */
- private $method = 'session';
- /**
- * __construct
- * @param string $key
- * @param string $method
- *
- * @return mixed
- */
- public function __construct($key = false, $method = 'session')
- {
- $this->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;
- }
- }
|