@@ -13,128 +13,128 @@ discard block |
||
| 13 | 13 | class Session { |
| 14 | 14 | use Module; |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Start session handler |
|
| 18 | - * |
|
| 19 | - * @access public |
|
| 20 | - * @static |
|
| 21 | - * @return void |
|
| 22 | - */ |
|
| 23 | - static public function start($name=null){ |
|
| 24 | - if (isset($_SESSION)) return; |
|
| 25 | - static::name($name); |
|
| 16 | + /** |
|
| 17 | + * Start session handler |
|
| 18 | + * |
|
| 19 | + * @access public |
|
| 20 | + * @static |
|
| 21 | + * @return void |
|
| 22 | + */ |
|
| 23 | + static public function start($name=null){ |
|
| 24 | + if (isset($_SESSION)) return; |
|
| 25 | + static::name($name); |
|
| 26 | 26 | // Obfuscate IDs |
| 27 | 27 | ini_set('session.hash_function', 'whirlpool'); |
| 28 | - session_cache_limiter('must-revalidate'); |
|
| 29 | - @session_start(); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Get/Set Session name |
|
| 34 | - * |
|
| 35 | - * @access public |
|
| 36 | - * @static |
|
| 37 | - * @param string $key The session name |
|
| 38 | - * @return string The session value |
|
| 39 | - */ |
|
| 40 | - static public function name($name=null){ |
|
| 41 | - return $name ? session_name($name) : session_name(); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Get a session variable reference |
|
| 46 | - * |
|
| 47 | - * @access public |
|
| 48 | - * @static |
|
| 49 | - * @param mixed $key The variable name |
|
| 50 | - * @return mixed The variable value |
|
| 51 | - */ |
|
| 52 | - static public function get($key,$default=null){ |
|
| 28 | + session_cache_limiter('must-revalidate'); |
|
| 29 | + @session_start(); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Get/Set Session name |
|
| 34 | + * |
|
| 35 | + * @access public |
|
| 36 | + * @static |
|
| 37 | + * @param string $key The session name |
|
| 38 | + * @return string The session value |
|
| 39 | + */ |
|
| 40 | + static public function name($name=null){ |
|
| 41 | + return $name ? session_name($name) : session_name(); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Get a session variable reference |
|
| 46 | + * |
|
| 47 | + * @access public |
|
| 48 | + * @static |
|
| 49 | + * @param mixed $key The variable name |
|
| 50 | + * @return mixed The variable value |
|
| 51 | + */ |
|
| 52 | + static public function get($key,$default=null){ |
|
| 53 | 53 | if (($active = static::active()) && isset($_SESSION[$key])) { |
| 54 | - return $_SESSION[$key]; |
|
| 54 | + return $_SESSION[$key]; |
|
| 55 | 55 | } else if ($active) { |
| 56 | - return $_SESSION[$key] = (is_callable($default)?call_user_func($default):$default); |
|
| 56 | + return $_SESSION[$key] = (is_callable($default)?call_user_func($default):$default); |
|
| 57 | 57 | } else { |
| 58 | - return (is_callable($default)?call_user_func($default):$default); |
|
| 58 | + return (is_callable($default)?call_user_func($default):$default); |
|
| 59 | 59 | } |
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Set a session variable |
|
| 64 | - * |
|
| 65 | - * @access public |
|
| 66 | - * @static |
|
| 67 | - * @param mixed $key The variable name |
|
| 68 | - * @param mixed $value The variable value |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - static public function set($key,$value=null){ |
|
| 72 | - static::start(); |
|
| 73 | - if($value==null && is_array($key)){ |
|
| 74 | - foreach($key as $k=>$v) $_SESSION[$k]=$v; |
|
| 75 | - } else { |
|
| 76 | - $_SESSION[$key] = $value; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Delete a session variable |
|
| 82 | - * |
|
| 83 | - * @access public |
|
| 84 | - * @static |
|
| 85 | - * @param mixed $key The variable name |
|
| 86 | - * @return void |
|
| 87 | - */ |
|
| 88 | - static public function delete($key){ |
|
| 89 | - static::start(); |
|
| 90 | - unset($_SESSION[$key]); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Delete all session variables |
|
| 96 | - * |
|
| 97 | - * @access public |
|
| 98 | - * @static |
|
| 99 | - * @return void |
|
| 100 | - */ |
|
| 101 | - static public function clear(){ |
|
| 102 | - static::start(); |
|
| 103 | - session_unset(); |
|
| 104 | - session_destroy(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Check if session is active |
|
| 109 | - * |
|
| 110 | - * @access public |
|
| 111 | - * @static |
|
| 112 | - * @return void |
|
| 113 | - */ |
|
| 114 | - static public function active(){ |
|
| 115 | - return session_status() == PHP_SESSION_ACTIVE; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Check if a session variable exists |
|
| 120 | - * |
|
| 121 | - * @access public |
|
| 122 | - * @static |
|
| 123 | - * @param mixed $key The variable name |
|
| 124 | - * @return bool |
|
| 125 | - */ |
|
| 126 | - static public function exists($key){ |
|
| 127 | - static::start(); |
|
| 128 | - return isset($_SESSION[$key]); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Return a read-only accessor to session variables for in-view use. |
|
| 133 | - * @return SessionReadOnly |
|
| 134 | - */ |
|
| 135 | - static public function readOnly(){ |
|
| 136 | - return new SessionReadOnly; |
|
| 137 | - } |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Set a session variable |
|
| 64 | + * |
|
| 65 | + * @access public |
|
| 66 | + * @static |
|
| 67 | + * @param mixed $key The variable name |
|
| 68 | + * @param mixed $value The variable value |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + static public function set($key,$value=null){ |
|
| 72 | + static::start(); |
|
| 73 | + if($value==null && is_array($key)){ |
|
| 74 | + foreach($key as $k=>$v) $_SESSION[$k]=$v; |
|
| 75 | + } else { |
|
| 76 | + $_SESSION[$key] = $value; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Delete a session variable |
|
| 82 | + * |
|
| 83 | + * @access public |
|
| 84 | + * @static |
|
| 85 | + * @param mixed $key The variable name |
|
| 86 | + * @return void |
|
| 87 | + */ |
|
| 88 | + static public function delete($key){ |
|
| 89 | + static::start(); |
|
| 90 | + unset($_SESSION[$key]); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Delete all session variables |
|
| 96 | + * |
|
| 97 | + * @access public |
|
| 98 | + * @static |
|
| 99 | + * @return void |
|
| 100 | + */ |
|
| 101 | + static public function clear(){ |
|
| 102 | + static::start(); |
|
| 103 | + session_unset(); |
|
| 104 | + session_destroy(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Check if session is active |
|
| 109 | + * |
|
| 110 | + * @access public |
|
| 111 | + * @static |
|
| 112 | + * @return void |
|
| 113 | + */ |
|
| 114 | + static public function active(){ |
|
| 115 | + return session_status() == PHP_SESSION_ACTIVE; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Check if a session variable exists |
|
| 120 | + * |
|
| 121 | + * @access public |
|
| 122 | + * @static |
|
| 123 | + * @param mixed $key The variable name |
|
| 124 | + * @return bool |
|
| 125 | + */ |
|
| 126 | + static public function exists($key){ |
|
| 127 | + static::start(); |
|
| 128 | + return isset($_SESSION[$key]); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Return a read-only accessor to session variables for in-view use. |
|
| 133 | + * @return SessionReadOnly |
|
| 134 | + */ |
|
| 135 | + static public function readOnly(){ |
|
| 136 | + return new SessionReadOnly; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | 139 | } /* End of class */ |
| 140 | 140 | |
@@ -146,36 +146,36 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | class SessionReadOnly { |
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * Get a session variable reference |
|
| 151 | - * |
|
| 152 | - * @access public |
|
| 153 | - * @param mixed $key The variable name |
|
| 154 | - * @return mixed The variable value |
|
| 155 | - */ |
|
| 156 | - public function get($key){ |
|
| 157 | - return Session::get($key); |
|
| 158 | - } |
|
| 159 | - public function __get($key){ |
|
| 160 | - return Session::get($key); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - public function name(){ |
|
| 164 | - return Session::name(); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Check if a session variable exists |
|
| 169 | - * |
|
| 170 | - * @access public |
|
| 171 | - * @param mixed $key The variable name |
|
| 172 | - * @return bool |
|
| 173 | - */ |
|
| 174 | - public function exists($key){ |
|
| 175 | - return Session::exists($key); |
|
| 176 | - } |
|
| 177 | - public function __isset($key){ |
|
| 178 | - return Session::exists($key); |
|
| 179 | - } |
|
| 149 | + /** |
|
| 150 | + * Get a session variable reference |
|
| 151 | + * |
|
| 152 | + * @access public |
|
| 153 | + * @param mixed $key The variable name |
|
| 154 | + * @return mixed The variable value |
|
| 155 | + */ |
|
| 156 | + public function get($key){ |
|
| 157 | + return Session::get($key); |
|
| 158 | + } |
|
| 159 | + public function __get($key){ |
|
| 160 | + return Session::get($key); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + public function name(){ |
|
| 164 | + return Session::name(); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Check if a session variable exists |
|
| 169 | + * |
|
| 170 | + * @access public |
|
| 171 | + * @param mixed $key The variable name |
|
| 172 | + * @return bool |
|
| 173 | + */ |
|
| 174 | + public function exists($key){ |
|
| 175 | + return Session::exists($key); |
|
| 176 | + } |
|
| 177 | + public function __isset($key){ |
|
| 178 | + return Session::exists($key); |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | 181 | } /* End of class */ |