26 if (isset ( $_SESSION [$arrayKey] )) {
27 $array = $_SESSION [$arrayKey];
28 if (! is_array ( $array ))
47 $array = self::getArray ( $arrayKey );
48 $_SESSION [$arrayKey] = $array;
49 $search = array_search ( $value, $array );
50 if ($search === FALSE && $add) {
51 $_SESSION [$arrayKey] [] = $value;
54 unset ( $_SESSION [$arrayKey] [$search] );
55 $_SESSION [$arrayKey] = array_values ( $_SESSION [$arrayKey] );
70 return self::addOrRemoveValueFromArray ( $arrayKey, $value,
false );
83 return self::addOrRemoveValueFromArray ( $arrayKey, $value,
true );
97 return $_SESSION [$key];
110 if (isset ( $_SESSION [$key] )) {
125 public static function session($key, $default = NULL) {
127 return isset ( $_SESSION [$key] ) ? $_SESSION [$key] : $default;
139 public static function get($key, $default = NULL) {
141 return isset ( $_SESSION [$key] ) ? $_SESSION [$key] : $default;
151 public static function set($key, $value) {
152 $_SESSION [$key] = $value;
156 public static function setTmp($key,$value,$duration){
157 if(isset($_SESSION[$key])){
158 $object=$_SESSION[$key];
160 return $object->setValue($value);
164 return $_SESSION[$key]=$object;
167 public static function getTmp($key,$default=null){
168 if(isset($_SESSION[$key])){
169 $object=$_SESSION[$key];
171 $value=$object->getValue();
173 return $object->getValue();
183 if(isset($_SESSION[$key])){
184 $object=$_SESSION[$key];
186 $value=$object->getTimeout();
203 public static function delete($key) {
205 unset ( $_SESSION [$key] );
215 public static function inc($key, $inc = 1) {
216 return self::set ( $key, self::get ( $key, 0 ) + $inc );
226 public static function dec($key, $dec = 1) {
227 return self::set ( $key, self::get ( $key, 0 ) - $dec );
237 public static function concat($key, $str, $default = NULL) {
238 return self::set ( $key, self::get ( $key, $default ) . $str );
248 public static function apply($key, $callback, $default = NULL) {
249 $value = self::get ( $key, $default );
250 if (is_string ( $callback ) && function_exists ( $callback )) {
251 $value = call_user_func ( $callback, $value );
252 } elseif (is_callable ( $callback )) {
253 $value = $callback ( $value );
257 return self::set ( $key, $value );
267 public static function Walk($callback, $userData = null) {
269 array_walk ( $_SESSION, $callback, $userData );
279 public static function replace($keyAndValues) {
281 $_SESSION = array_replace ( $_SESSION, $keyAndValues );
302 if (! isset ( $_SESSION )) {
306 if (isset ( self::$name )) {
307 \session_name ( self::$name );
319 return isset ( $_SESSION );
331 return isset ( $_SESSION [$key] );
340 public static function init($key,$value){
341 if(!isset($_SESSION[$key])){
342 $_SESSION[$key]=$value;
344 return $_SESSION[$key];
351 if (! self::isStarted ())
354 $_SESSION = array ();
356 if (\ini_get (
"session.use_cookies" )) {
357 $params = \session_get_cookie_params ();
358 \setcookie ( \session_name (),
'', \time () - 42000, $params [
"path"], $params [
"domain"], $params [
"secure"], $params [
"httponly"] );
static dec($key, $dec=1)
Decrement the value at the key index in session.
static init($key, $value)
Initialize the key in Session if key does not exists.
static exists($key)
Returns true if the key exists in Session.
static session($key, $default=NULL)
Returns the value stored at the key position in session.
static setTmp($key, $value, $duration)
static isStarted()
Returns true if the session is started.
static apply($key, $callback, $default=NULL)
Applies a callback function to the value at the key index in session.
static Walk($callback, $userData=null)
Apply a user supplied function to every member of Session array.
static concat($key, $str, $default=NULL)
Adds a string at the end of the value at the key index in session.
static getBoolean($key)
Returns a boolean stored at the key position in session.
static replace($keyAndValues)
Replaces elements from Session array with $keyAndValues.
static terminate()
Terminates the active session.
static setBoolean($key, $value)
Sets a boolean value at key position in session.
static getAll()
Returns the associative array of session vars.
static start($name=null)
Start new or resume existing session.
static inc($key, $inc=1)
Increment the value at the key index in session.
static removeValueFromArray($arrayKey, $value)
Removes a value from an array in session.
static getArray($arrayKey)
Returns an array stored in session variable as $arrayKey.
static addValueToArray($arrayKey, $value)
Adds a value from an array in session.
static addOrRemoveValueFromArray($arrayKey, $value, $add=true)
Adds or removes a value from an array in session.
static getTmp($key, $default=null)