\midcom_services_session

Provides sessioning for components.

Use get, set and exists to access the sessioning data within your component.

Example:

<?php $session = new midcom_services_session(); if ($session->exists("mykey")) { echo "found session value: " . $session->get ("mykey") . ", removing it."; $value = $session->remove("mykey"); } else { echo "setting session value..."; $session->set("mykey", "hello world"); }

You should keep in mind, that the isolation level by default is per-component, not per-request. If you, for example, have the same component active twice (through dynamic_load) you have to manually ensure, that each request is treated separately. Unfortunately MidCOM cannot help you here.

Implementation Notes:

This is a simple wrapper that provides access to the sessioning singleton. It has the same public member functions as midcom_services__sessioning, refer to this class for a detailed documentation.

Basically this wrapper ensures the singleton pattern is maintained and provides you with an easy way of lock the domain you're working in.

Summary

Methods
Properties
Constants
__construct()
get()
set()
exists()
remove()
get_session_data()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
$_sessioning
$_domain
N/A

Properties

$_domain

$_domain : string

The domain we're working in.

Type

string

Methods

__construct()

__construct(mixed  $context = null) 

Constructs a session object.

The constructor has three semantics:

The default constructor will create a sessioning object within the domain of the current context's component. This will be sufficient for almost all actual uses of the sessions.

If passed an integer argument, it will use the context indicated by this parameter as a default domain.

Finally, if passed a string argument, this value is used as a domain. This is useful for components that need sessioning while under dynamic_load conditions or while used as a library.

Parameters

mixed $context

Either null or a context ID (uses the context's component) or an explicit domain.

get()

get(mixed  $key) : mixed

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.

Parameters

mixed $key

The key to query.

Returns

mixed —

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

set()

set(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

mixed $key

Session value identifier.

mixed $value

Session value.

exists()

exists(mixed  $key) : boolean

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

mixed $key

The key to query.

Returns

boolean —

Indicating availability.

remove()

remove(mixed  $key) : mixed

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.

Parameters

mixed $key

The key to remove.

Returns

mixed —

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

get_session_data()

get_session_data() : Array

Get all the session data

Returns

Array —

containing session data