nyroFwk  0.2
php.class.php
Go to the documentation of this file.
1 <?php
12 
16  protected function afterInit() {
17  if (!session_id()) {
18  $sessIdForce = $this->cfg->sessIdForce;
19  if (isset($_GET[$sessIdForce]))
20  session_id($_GET[$sessIdForce]);
21  elseif (isset($_POST[$sessIdForce]))
22  session_id($_POST[$sessIdForce]);
23  session_start();
24  if ($this->cfg->regenerateId)
25  session_regenerate_id(true);
26  }
27  }
28 
29  public function get($prm) {
30  if ($this->check($prm)) {
31  if (is_array($prm)) {
32  $this->setNameSpaceInArray($prm);
33  config::initTab($prm, array(
34  'name'=>null,
35  'serialize'=>false
36  ));
37  $name = $this->prefixNameSpace($prm['name']);
38  $serialize = $prm['serialize'];
39  } else {
40  $name = $this->prefixNameSpace($prm);
41  $serialize = false;
42  }
43  return $serialize? unserialize($_SESSION[$name]) : $_SESSION[$name];
44  }
45  return null;
46  }
47 
48  public function getAll() {
49  $ret = array();
50  $prefix = $this->prefixNameSpace('');
51  $prefixLn = strlen($prefix);
52  foreach($_SESSION as $k=>$v) {
53  if (strpos($k, $prefix) === 0)
54  $ret[substr($k, $prefixLn)] = $v;
55  }
56  return $ret;
57  }
58 
59  public function set(array $prm) {
60  $this->setNameSpaceInArray($prm);
61  config::initTab($prm, array(
62  'name'=>null,
63  'val'=>null,
64  'serialize'=>false
65  ));
66  $_SESSION[$this->prefixNameSpace($prm['name'])] = $prm['serialize']? serialize($prm['val']) : $prm['val'];
67  }
68 
69  public function check($prm) {
70  if (is_array($prm)) {
71  $this->setNameSpaceInArray($prm);
72  config::initTab($prm, array(
73  'name'=>null,
74  ));
75  $name = $prm['name'];
76  } else {
77  $name = $prm;
78  }
79  return isset($_SESSION[$this->prefixNameSpace($name)]);
80  }
81 
90  public function del($prm, $autoPrefix=true) {
91  if (is_array($prm)) {
92  $this->setNameSpaceInArray($prm);
93  $name = $prm['name'];
94  } else {
95  $name = $prm;
96  }
97  if ($autoPrefix)
98  $name = $this->prefixNameSpace($name);
99  unset($_SESSION[$name]);
100  }
101 
102  public function clear($nameSpace=true) {
103  $tmp = array_keys($_SESSION);
104 
105  if ($nameSpace === true)
106  $nameSpace = $this->getNameSpace();
107 
108  if (is_string($nameSpace)) {
109  $this->setNameSpace($nameSpace);
110  $tmp = array_filter($tmp, create_function('$v', 'return (strpos($v, "'.$this->prefixNameSpace('').'") === 0);'));
111  }
112 
113  foreach($tmp as $v)
114  $this->del($v, false);
115  }
116 
122  public function getSessIdForce() {
123  return $this->cfg->sessIdForce;
124  }
125 
129  private function prefixNameSpace($name) {
130  $nameSpace = $this->cfg->nameSpace? $this->cfg->nameSpace.'_' : null;
131  return $this->cfg->prefix.$nameSpace.$name;
132  }
133 
134 }
check($prm)
Definition: php.class.php:69
del($prm, $autoPrefix=true)
Definition: php.class.php:90
static initTab(array &$vars, array $init)
clear($nameSpace=true)
Definition: php.class.php:102
prefixNameSpace($name)
Definition: php.class.php:129
Generated on Sun Oct 15 2017 22:25:20 for nyroFwk by doxygen 1.8.13