Session

Wrapper for $_SESSION. It is recommended to never create an object from this class, use a "Request" instance to access an instance of this class. e.g. "$request->Session->has("key");". The "Request" instance will only start session and create a "IRequestArray" instance if it is demanded and then the instance will be used for further calls.
The session configs can be set inside the App configs array or ini file under section "[session]". The session handler can be set to database or memcache (see the configs).
As instanced of this class are created and accessed via an "IRequest", this class is not included into the autoload.
Source
Session.php
Implements
ISession , IRequestArray
Depends on
Arta , SessionDb , RequiresIDbAdvanced , ISession , Request

Static Methods

clear

void Session::clear()

Clear all session data.

Returns

void

close

void Session::close()

Close session (session_write_close). To prevent session repo lock close sessions after use in slower scripts.

Returns

void

destroy

void Session::destroy()

Unset and destroy the session.

Returns

void

expire

ISession Session::expire(int expire=60)

To check session life-time manually and destroy the session if its older than "expire".

Arguments

    expire=60 (int)
    Time in minutes

Returns

ISession
object For method chaining

get

mixed Session::get(string key, mixed default=null, const type=null)

Get a value from $_SESSION.

Arguments

    key (string)
    The key to get it's value
    default=null (mixed)
    The default-value to be returned if key not exists or value is invalid
    type=null (const)
    Set to an Artaengine type constant such as "INT", "T::INT", "T::EMAIL", etc. to validate or cast the returned value

Returns

mixed
The value set to the key or the default-value/"null" if key not exists

has

bool Session::has(string key)

Check if a key exists in $_SESSION.

Arguments

    key (string)
    Key to be checked

Returns

bool
true=key exists

hasValue

bool Session::hasValue(string key, mixed val)

Check if a key has a given value A[key] === val.

Arguments

    key (string)
    Key to compare it's value
    val (mixed)
    Value to be compared to

Returns

bool
true=key has the given value

like

array Session::like(string key)

Get {key:value,} from "$_SESSION" where the keys in source contain the "key" string inside them.

Since
Artaengine 1.2.2

Arguments

    key (string)
    String to be searched in "source" keys

Returns

array
{key:value,} a subset of "source" where keys contains "key"

regenerate

ISession Session::regenerate()

Regenerate the session id.

Returns

ISession
object For method chaining

remove

void Session::remove([string] key)

Remove key(s).

Arguments

    key ([string])
    The key or keys to be removed

Returns

void

set

void Session::set(string key, mixed val)

Set a value to the $_SESSION array.

Arguments

    key (string)
    Key to set the value to
    val (mixed)
    Value to be set

Returns

void

start

void Session::start(array configs=null)

Start session. If no config is provided then the session configs defined in the app configs (array or ini file) will be used. If no config is available then the session will be started with default configs.

Arguments

    configs=null (array)
    Session configs
    {
        IDbAbstract database      : null
            database access object name. if this key is set then session data
            will be written on the database,
        bool        memcache      : false
            true=put session repo on the memcache,
        string      path          : PHP's default value
            session file directory,
        string      name          : PHP's default value
            session name,
        int         regenerate    : null
            intervals (minutes) to regenerate session id - will be checked
            on each request,
        string      secret        : null
            if set to a string(secret-key), session id will be regenerated
            on occasions and "UnsafeSession" exception will be thrown if
            the user-agent+secret-key changes,
        int         expire        : null
            expire session manually if the session is older than this number
            of minutes,
        int         cookie_expire : 0     session cookie setting,
        string      cookie_path   : \     session cookie setting,
        string      cookie_domain : ""    session cookie setting,
        bool        cookie_secure : false session cookie setting,
    }
    

Returns

void

with

array Session::with(string key, bool remove)

Get {key:value,} from "$_SESSION" where the keys in source start with the "key".

Since
Artaengine 1.2.0

Arguments

    key (string)
    String to be searched in "source" keys
    remove (bool)
    true=remove "key" from the keys in the returned array

Returns

array
{key:value,} a subset of "source" where keys start with "key"

Methods

__construct

Session $obj = new Session(array configs=null)

Constructor. Start session. If no config is provided then the session configs defined in the app configs (array or ini file) will be used. If no config is available then the session will be started with default configs.

Arguments

    configs=null (array)
    Session configs
    {
        IDbAbstract database      : null
            database access object name. if this key is set then session data
            will be written on the database,
        bool        memcache      : false
            true=put session repo on the memcache,
        string      path          : PHP's default value
            session file directory,
        string      name          : PHP's default value
            session name,
        int         regenerate    : null
            intervals (minutes) to regenerate session id - will be checked
            on each request,
        string      secret        : null
            if set to a string(secret-key), session id will be regenerated
            on occasions and "UnsafeSession" exception will be thrown if
            the user-agent+secret-key changes,
        int         expire        : null
            expire session manually if the session is older than this number
            of minutes,
        int         cookie_expire : 0     session cookie setting,
        string      cookie_path   : \     session cookie setting,
        string      cookie_domain : ""    session cookie setting,
        bool        cookie_secure : false session cookie setting,
    }
    

Returns

void

__destruct

__destruct()

Destructor.

Returns

void

__get

mixed __get(string key)

Get a value from $_SESSION.

Arguments

    key (string)
    The key to get it's value

Returns

mixed
The value set to the key or "null" if key not exists

__isset

bool __isset(string key)

Check if a key exists in $_SESSION an is not null.

Arguments

    key (string)
    Key to be checked

Returns

bool
true=key exists and is nut null

__set

void __set(string key, mixed val)

Set a value to the $_SESSION array.

Arguments

    key (string)
    Key to set the value to
    val (mixed)
    Value to be set

Returns

void

__unset

void __unset(string key)

Unset key.

Arguments

    key (string)
    Key to unset

Returns

void

id

variable $obj->id()

Get the session id.

Returns

variable
Session id