nyroFwk  0.2
cookie.class.php
Go to the documentation of this file.
1 <?php
10 class http_cookie extends object {
11 
17  protected $saved = false;
18 
24  protected $doNotSave = false;
25 
26  protected function afterInit() {
27  if (empty($this->cfg->value)) {
28  $this->cfg->value = $this->get(true);
29  $this->saved = true;
30  }
31 
32  if ($this->cfg->autoSave)
33  response::getInstance()->addBeforeOut(array($this, 'save'));
34  }
35 
41  public function changeCfg(array $prm) {
42  $this->cfg->setA($prm);
43  $this->saved = false;
44  }
45 
52  public function doNotSave($doNotSave=null) {
53  if (is_null($doNotSave))
54  return $this->doNotSave;
55  else
56  $this->doNotSave = (boolean) $doNotSave;
57  }
58 
64  public function check() {
65  return array_key_exists($this->getRawName(), $_COOKIE);
66  }
67 
74  public function get($fromBrowser=false) {
75  if (!$this->saved && !$fromBrowser)
76  return $this->cfg->value;
77  else if ($this->check())
78  return $_COOKIE[$this->getRawName()];
79 
80  return null;
81  }
82 
88  public function set($value) {
89  if ($value != $this->cfg->value)
90  $this->saved = false;
91 
92  $this->cfg->value = $value;
93  }
94 
98  public function del() {
99  $this->set(null);
100  $this->cfg->expire = -1;
101  }
102 
108  public function save() {
109  if ($this->saved)
110  return true;
111 
112  if ($this->doNotSave)
113  return false;
114 
115  $this->saved = setcookie(
116  $this->getRawName(),
117  $this->cfg->value,
118  $this->cfg->expire+time(),
119  $this->cfg->path,
120  $this->cfg->domain,
121  $this->cfg->secure);
122 
123  return $this->saved;
124  }
125 
131  public function getRawName() {
132  return $this->cfg->prefix.$this->cfg->name;
133  }
134 
135 }
static getInstance()
Generated on Sun Oct 15 2017 22:25:20 for nyroFwk by doxygen 1.8.13