Go to the documentation of this file.00001 <?php
00010 class http_cookie extends object {
00011
00017 protected $saved = false;
00018
00024 protected $doNotSave = false;
00025
00026 protected function afterInit() {
00027 if (empty($this->cfg->value)) {
00028 $this->cfg->value = $this->get(true);
00029 $this->saved = true;
00030 }
00031
00032 if ($this->cfg->autoSave)
00033 response::getInstance()->addBeforeOut(array($this, 'save'));
00034 }
00035
00041 public function changeCfg(array $prm) {
00042 $this->cfg->setA($prm);
00043 $this->saved = false;
00044 }
00045
00052 public function doNotSave($doNotSave=null) {
00053 if (is_null($doNotSave))
00054 return $this->doNotSave;
00055 else
00056 $this->doNotSave = (boolean) $doNotSave;
00057 }
00058
00064 public function check() {
00065 return array_key_exists($this->getRawName(), $_COOKIE);
00066 }
00067
00074 public function get($fromBrowser=false) {
00075 if (!$this->saved && !$fromBrowser)
00076 return $this->cfg->value;
00077 else if ($this->check())
00078 return $_COOKIE[$this->getRawName()];
00079
00080 return null;
00081 }
00082
00088 public function set($value) {
00089 if ($value != $this->cfg->value)
00090 $this->saved = false;
00091
00092 $this->cfg->value = $value;
00093 }
00094
00098 public function del() {
00099 $this->set(null);
00100 $this->cfg->expire = -1;
00101 }
00102
00108 public function save() {
00109 if ($this->saved)
00110 return true;
00111
00112 if ($this->doNotSave)
00113 return false;
00114
00115 $this->saved = setcookie(
00116 $this->getRawName(),
00117 $this->cfg->value,
00118 $this->cfg->expire+time(),
00119 $this->cfg->path,
00120 $this->cfg->domain,
00121 $this->cfg->secure);
00122
00123 return $this->saved;
00124 }
00125
00131 public function getRawName() {
00132 return $this->cfg->prefix.$this->cfg->name;
00133 }
00134
00135 }