\midcom_core_context

MidCOM context handling

Provides a basic context mechanism that allows each independent component invocation to access its own context information.

Summary

Methods
Properties
Constants
__construct()
set_current()
get()
get_all()
get_key()
set_key()
get_custom_key()
has_custom_key()
set_custom_key()
run()
handle()
show()
$id
$parser
No constants found
No protected methods found
No protected properties found
N/A
_initialize_root_topic()
_loadconfig()
$_contexts
$_currentcontext
$_data
N/A

Properties

$id

$id : integer

The context's ID

Type

integer

$_contexts

$_contexts : array<mixed,\midcom_core_context>

Holds the component context information.

This is an array of arrays, the outer one indexed by context IDs, the inner one indexed by context keys. Only valid of the system has left the code-init phase.

Type

array<mixed,\midcom_core_context>

$_currentcontext

$_currentcontext : integer

Contains the ID of the currently active context

Type

integer

$_data

$_data : array

The context's data

Type

array

Methods

__construct()

__construct(integer  $id = null, \midcom_db_topic  $node = null) 

Create and prepare a new component context.

Parameters

integer $id

Explicitly specify the ID for context creation (used during construction), this parameter is usually omitted.

\midcom_db_topic $node

Root node of the context

set_current()

set_current() 

Marks context as current

get()

get(integer  $id = null) : \midcom_core_context

Get context, either the current one or one designated by ID

If the current context is requested and doesn't exist for some reason, it is automatically created

Parameters

integer $id

The context ID, if any

Returns

\midcom_core_context

The requested context, or false if not found

get_all()

get_all() : array<mixed,\midcom_core_context>

Returns the complete context data array

Returns

array<mixed,\midcom_core_context> —

All contexts

get_key()

get_key(integer  $key) : mixed

Access the MidCOM component context

Returns Component Context Information associated to the component with the context identified by $key.

Parameters

integer $key

The key requested

Returns

mixed —

The content of the key being requested.

set_key()

set_key(integer  $key, mixed  $value) 

Update the component context

This function sets a variable of the current or the given component context.

Parameters

integer $key

The key to use

mixed $value

The value to be stored

get_custom_key()

get_custom_key(integer  $key, string  $component = null) : mixed

Retrieve arbitrary, component-specific information in the component context

The set call defaults to the current context, the get call's semantics are as with get_key().

Note, that if you are working from a library like the datamanager is, you cannot override the component association done by the system. Instead you should add your libraries name (like midcom.helper.datamanager) as a prefix, separated by a dot. I know, that this is not really an elegant solution and that it actually breaks with the encapsulation I want, but I don't have a better solution yet.

A complete example can be found with set_custom_key.

Parameters

integer $key

The requested key

string $component

The component name

Returns

mixed —

The requested value, which is returned by Reference!

has_custom_key()

has_custom_key(  $key,   $component = null) 

Parameters

$key
$component

set_custom_key()

set_custom_key(mixed  $key,   $value, string  $component = null) 

Store arbitrary, component-specific information in the component context

This method allows you to get custom data to a given context. The system will automatically associate this data with the component from the currently active context. You cannot access the custom data of any other component this way, it is private to the context. You may attach information to other contexts, which will be associated with the current component, so you have a clean namespace independently from which component or context you are operating of. All calls honor references of passed data, so you can use this for central controlling objects.

Note, that if you are working from a library like the datamanager is, you cannot override the component association done by the system. Instead you should add your libraries name (like midcom.helper.datamanager) as a prefix, separated by a dot. I know, that this is not really an elegant solution and that it actually breaks with the encapsulation I want, but I don't have a better solution yet.

Be aware, that this function works by-reference instead of by-value.

A complete example could look like this:

class my_component_class_one { public function init () { midcom_core_context::get()->set_custom_key('classone', $this); } }

class my_component_class_two { public $one; public function __construct() { $this->one =& midcom_core_context::get()->get_custom_key('classone'); } }

Parameters

mixed $key

The key associated to the value.

$value
string $component

The component associated to the key.

run()

run(\Symfony\Component\HttpFoundation\Request  $request) : \midcom_response

Handle a request.

The URL of the component that is used to handle the request is obtained automatically. If the handler hook returns false (i.e. handling failed), it will produce an error page.

Parameters

\Symfony\Component\HttpFoundation\Request $request

Returns

\midcom_response

handle()

handle(\midcom_db_topic  $topic, \Symfony\Component\HttpFoundation\Request  $request = null) : \midcom_response

Check whether a given component is able to handle the current request.

After the local configuration is retrieved from the object in question the component will be asked if it can handle the request. If so, the interface class will be returned to the caller

Parameters

\midcom_db_topic $topic

The node that is currently being tested.

\Symfony\Component\HttpFoundation\Request $request

Returns

\midcom_response

show()

show() 

_initialize_root_topic()

_initialize_root_topic() 

_loadconfig()

_loadconfig(integer  $context_id, \midcom_db_topic  $topic) : \midcom_helper_configuration

Load the configuration for a given object.

This is a small wrapper function that retrieves all local configuration data attached to $topic. The assigned component is used to determine which parameter domain has to be used.

Parameters

integer $context_id

The context ID

\midcom_db_topic $topic

The node from which to load the configuration.

Returns

\midcom_helper_configuration

The newly constructed configuration object.