示例#1
0
文件: cookie.php 项目: annaqin/eden
 /**
  * Sets a cookie.
  *
  * @param *string cookie name
  * @param variable the data
  * @param int expiration
  * @param string path to make the cookie available
  * @param string|null the domain
  * @return this
  */
 public function set($key, $data = NULL, $expires = 0, $path = NULL, $domain = NULL, $secure = false, $httponly = false)
 {
     //argment test
     Eden_Cookie_Error::i()->argument(1, 'string')->argument(2, 'string', 'numeric', 'null')->argument(3, 'int')->argument(4, 'string', 'null')->argument(5, 'string', 'null')->argument(6, 'bool')->argument(7, 'bool');
     //argument 7 must be a boolean
     $_COOKIE[$key] = $data;
     setcookie($key, $data, $expires, $path, $domain, $secure, $httponly);
     return $this;
 }
示例#2
0
if(!class_exists('Eden_Cookie')){class Eden_Cookie extends Eden_Class implements ArrayAccess,Iterator{public static function i(){return self::_getSingleton(__CLASS__);}public function clear(){foreach($_COOKIE as $key=>$value){$this->remove($key);}return $this;}public function current(){return current($_COOKIE);}public function get($key=NULL){Eden_Cookie_Error::i()->argument(1,'string','null');if(is_null($key)){return $_COOKIE;}if(isset($_COOKIE[$key])){return $_COOKIE[$key];}return NULL;}public function key(){return key($_COOKIE);}public function next(){next($_COOKIE);}public function offsetExists($offset){return isset($_COOKIE[$offset]);}public function offsetGet($offset){return isset($_COOKIE[$offset]) ? $_COOKIE[$offset] : NULL;}public function offsetSet($offset,$value){$this->set($offset,$value,strtotime('+10 years'));}public function offsetUnset($offset){$this->remove($offset);}public function remove($name){Eden_Cookie_Error::i()->argument(1,'string');$this->set($name,NULL,time() - 3600);if(isset($_COOKIE[$name])){unset($_COOKIE[$name]);}return $this;}public function rewind(){reset($_COOKIE);}public function set($key,$data=NULL,$expires=0,$path=NULL,$domain=NULL,$secure=false,$httponly=false){Eden_Cookie_Error::i()->argument(1,'string')->argument(2,'string','numeric','null')->argument(3,'int')->argument(4,'string','null')->argument(5,'string','null')->argument(6,'bool')->argument(7,'bool');$_COOKIE[$key]=$data;setcookie($key,$data,$expires,$path,$domain,$secure,$httponly);return $this;}public function setData(array $data,$expires=0,$path=NULL,$domain=NULL,$secure=false,$httponly=false){foreach($data as $key=>$value){$this->set($key,$value,$expires,$path,$domain,$secure,$httponly);}return $this;}public function setSecure($key,$data=NULL,$expires=0,$path=NULL,$domain=NULL){return $this->set($key,$data,$expires,$path,$domain,true,false);}public function setSecureData(array $data,$expires=0,$path=NULL,$domain=NULL){$this->set($data,$expires,$path,$domain,true,false);return $this;}public function valid(){return isset($_COOKIE[$this->key()]);}}class Eden_Cookie_Error extends Eden_Error{public static function i($message=NULL,$code=0){$class=__CLASS__;return new $class($message,$code);}}}