$_sessioning
$_sessioning : \midcom_services__sessioning
Sessioning singleton.
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.
$_sessioning : \midcom_services__sessioning
Sessioning singleton.
__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.
mixed | $context | Either null or a context ID (uses the context's component) or an explicit domain. |
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.
mixed | $key | The key to query. |
The session key's data value, or null on failure.
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.
mixed | $key | Session value identifier. |
mixed | $value | Session value. |
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.
mixed | $key | The key to remove. |
The session key's data value, or null on failure.