Пример #1
0
 /**
  * Validates whether if the index is set
  * For Iterator interface
  *
  * @return void
  */
 public function valid()
 {
     if (!self::$_session) {
         Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger();
     }
     return isset($_SESSION[$this->key()]);
 }
Пример #2
0
if(!class_exists('Eden_Session')){class Eden_Session extends Eden_Class implements ArrayAccess,Iterator{protected static $_session=false;public static function i(){return self::_getSingleton(__CLASS__);}public function __toString(){if(!self::$_session){return '[]';}return json_encode($_SESSION);}public function clear(){if(!self::$_session){Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger();}$_SESSION=array();return $this;}public function current(){if(!self::$_session){Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger();}return current($_SESSION);}public function get($key=NULL){$error=Eden_Session_Error::i()->argument(1,'string','null');if(!self::$_session){$error->setMessage(Eden_Session_Error::ERROR_ERROR_NOT_STARTED)->trigger();}if(is_null($key)){return $_SESSION;}if(isset($_SESSION[$key])){return $_SESSION[$key];}return NULL;}public function getId(){if(!self::$_session){Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger();}return session_id();}public function key(){if(!self::$_session){Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger();}return key($_SESSION);}public function next(){if(!self::$_session){Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger();}next($_SESSION);}public function offsetExists($offset){if(!self::$_session){Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger();}return isset($_SESSION[$offset]);}public function offsetGet($offset){if(!self::$_session){Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger();}return isset($_SESSION[$offset]) ? $_SESSION[$offset] : NULL;}public function offsetSet($offset,$value){if(!self::$_session){Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger();}if (is_null($offset)){$_SESSION[]=$value;}else{$_SESSION[$offset]=$value;}}public function offsetUnset($offset){if(!self::$_session){Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger();}unset($_SESSION[$offset]);}public function remove($name){Eden_Session_Error::i()->argument(1,'string');if(isset($_SESSION[$name])){unset($_SESSION[$name]);}return $this;}public function rewind(){if(!self::$_session){Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger();}reset($_SESSION);}public function set($data,$value=NULL){$error=Eden_Session_Error::i()->argument(1,'array','string');if(!self::$_session){$error->setMessage(Eden_Session_Error::ERROR_ERROR_NOT_STARTED)->trigger();}if(is_array($data)){$_SESSION=$data;return $this;}$_SESSION[$data]=$value;return $this;}public function setId($sid){$error=Eden_Session_Error::i()->argument(1,'numeric');if(!self::$_session){$error->setMessage(Eden_Session_Error::ERROR_ERROR_NOT_STARTED)->trigger();}return session_id((int) $sid);}public function start(){if(!session_id()){self::$_session=session_start();}return $this;}public function stop(){self::$_session=false;session_write_close();return $this;}public function valid(){if(!self::$_session){Eden_Session_Error::i(Eden_Session_Error::ERROR_NOT_STARTED)->trigger();}return isset($_SESSION[$this->key()]);}}class Eden_Session_Error extends Eden_Error{const ERROR_NOT_STARTED='Session is not started.Try using Eden_Session->start() first.';public static function i($message=NULL,$code=0){$class=__CLASS__;return new $class($message,$code);}}}