Base singleton class of the MidCOM sessioning service.

This is a singleton class, that is accessible through the MidCOM Service infrastructure. It manages session data of MidCOM driven applications.

This sessioning interface will always work with copies, never with references to work around a couple of bugs mentioned in the details below.

This class provides a generic interface to store keyed session values in the domain of the corresponding component.

All requests involving this service will always be flagged as no_cache.

If you store class instances within a session, which is perfectly safe in general, there are known problems due to the fact, that a class declaration has to be available before it can be deserialized. As PHP sessioning does this deserialization automatically, this might fail with MidCOM, where the sequence in which the code gets loaded and the sessioning gets started up is actually undefined. To get around this problems, the sessioning system stores not the actual data in the sessioning array, but a serialized string of the data, which can always be deserialized on PHP sessioning startup (its a string after all). This has an important implication though: The sessioning system always stores copies of the data, not references. So if you put something in to the session store and modify it afterwards, this change will not be reflected in the sessioning store.

Important:

Do never create an instance of this class directly. This is handled by the framework. Instead use midcom_service_session which ensures the singleton pattern.

Do never work directly with the $_SESSION["midcom_session_data"] variable, this is a 100% must-not, as this will break functionality.

package midcom.services
see \global\midcom_services_session

 Methods

__construct ()

The constructor will initialize the sessioning, set the output nocacheable and initialize the session data.

This might involve creating an empty session array.

_get_helper (string $domain, mixed $key)

This is a small, internal helper function, which will load, unserialize and return a given key's value.

It is shared by get and remove.

Parameters

$domain

stringThe domain in which to search for the key.

$key

mixedThe key to query.

Returns

mixedThe session key's data value, or null on failure.

exists (string $domain, mixed $key)

Checks, if the specified key has been added to the session store.

This is often used in conjunction with get to verify a keys existence.

Parameters

$domain

stringThe domain in which to search for the key.

$key

mixedThe key to query.

Returns

booleanIndicating availability.

get (string $domain, mixed $key)

Returns a value from the session.

Returns null if the key is non-existent. Note, that this is not necessarily a valid non-existence check, as the sessioning system does allow null values. Use the exists function if unsure.

see \midcom_services__sessioning::exists()

Parameters

$domain

stringThe domain in which to search for the key.

$key

mixedThe key to query.

Returns

mixedThe session key's data value, or null on failure.

get_session_data (string $domain)

Get the session data

Parameters

$domain

stringSession domain

Returns

Arraycontaining session values

remove (string $domain, mixed $key)

Removes the value associated with the specified key.

Returns null if the key is non-existent or the value of the key just removed otherwise. Note, that this is not necessarily a valid non-existence check, as the sessioning system does allow null values. Use the exists function if unsure.

see \midcom_services__sessioning::exists()

Parameters

$domain

stringThe domain in which to search for the key.

$key

mixedThe key to remove.

Returns

mixedThe session key's data value, or null on failure.

set (string $domain, mixed $key, mixed $value)

This will store the value to the specified key.

Note, that a copy is stored, the actual object is not referenced in the session data. You will have to update it manually in case of changes.

Parameters

$domain

stringThe domain in which to search for the key.

$key

mixedSession value identifier.

$value

mixedSession value.

_initialize ($unconditional_start)

Parameters

$unconditional_start