\midcom_helper_configuration

This class is designed to ease MidCOM Configuration management.

Basically it supports key/value pairs of data, which can be retrieved out of Midgard Parameters. In this case it would make the key/values a string/string pair with a length limit of 255 characters. Since the current implementation only supports read-access to the configuration data, this is a negligible fact, in reality it supports all valid PHP data types as key or data values, as long it is allowed to use the keys as array index elements.

This class is designed to manage parameter like key/value configuration data. The class makes no assumption about the value type of keys or values, any valid PHP data type is allowed. Two different sets of configuration options are stored within the class, the "global" and the "local" configuration.

The global configuration must include all possible configuration parameters with their default values. These data is fixed and cannot be changed after object instantiation. Aimed specifically at MidCOM is the second set of configuration data, the "local" parameters. It gives you a way of explicitly overwrite a part of the configuration data with localized values. This customization data can be overwritten at wish by deliberately resetting it to the defaults or by importing a new one over the existing local configuration.

Configuration data can be delivered in two ways: The easiest way is using a associative array that will be used as configuration. Alternatively you can specify both a MidgardObject and a MidCOM Path which is used to fetch configuration data.

Any configuration key in the local configuration, which is not present in the global "template", will be logged as a warning. This should normally not happen. Originally, this case threw a critical error, but that made upgrading configurations quite difficult.

Summary

Methods
Properties
Constants
__construct()
store()
store_from_object()
reset_local()
get()
set()
get_all()
exists()
$_global
$_local
No constants found
No protected methods found
No protected properties found
N/A
_store_from_object()
_update_cache()
_check_local_array()
$_merged
$_object
$_path
N/A

Properties

$_global

$_global : Array

Globally assigned configuration data.

Type

Array

$_local

$_local : Array

Locally overridden configuration data.

Type

Array

$_merged

$_merged : Array

Merged, current configuration state.

Type

Array

$_object

$_object : 

Type

$_path

$_path : 

Type

Methods

__construct()

__construct(mixed  $param1, mixed  $param2 = null) 

The constructor initializes the global configuration.

Two sources can be specified:

First, if passed a single associative array to the constructor, it will use its contents as global configuration.

Alternatively you can specify any Midgard object and a parameter domain. It will then use the contents of this domain as global configuration.

Parameters

mixed $param1

Either an associative array or a Midgard object.

mixed $param2

Either null or the name of a Parameter domain.

store()

store(array  $params, boolean  $reset = true) 

Write the parameters in $params into the local configuration.

If $reset is set, the local configuration will be cleared before the new set is imported, if not, the new data is merged with the old local configuration, overwriting duplicates. During import each configuration key will be checked against the global configuration values. If an unknown value is found, import will be aborted and no changes to the configuration is done.

After import the cache array will be updated, reset is done by reset_local.

Parameters

array $params

The new local parameters

boolean $reset

If set to true, the current local configuration will be discarded first.

store_from_object()

store_from_object(\MidgardObject  $object, string  $path, boolean  $merge = false) 

Import data from a Midgard object.

To import configuration data from a Midgard Object, use this method. As in the respective constructor it will retrieve the configuration data in the parameter domain $path of $object. Unlike the constructor this function will store the data in the local configuration.

Parameters

\MidgardObject $object

The object from which to import data.

string $path

The parameter domain to query.

boolean $merge

Should the existing local config be overridden or merged

reset_local()

reset_local() 

Clear the local configuration data, effectively reverting to the global default.

get()

get(string  $key) : mixed

Retrieve a configuration key

If $key exists in the configuration data, its value is returned to the caller. If the value does not exist, the boolean value false will be returned. Be aware that this is not always good for error checking, since "false" is a perfectly good value in the configuration data. Do error checking with the function exists (see below).

Parameters

string $key

The configuration key to query.

Returns

mixed —

Its value or false, if the key doesn't exist.

set()

set(string  $key, mixed  $value) 

Set a value on the current instance, if the given key exists

Parameters

string $key

The configuration key to set.

mixed $value

The value to set.

get_all()

get_all() : Array

Retrieve a copy the complete configuration array.

Returns

Array —

The complete current configuration.

exists()

exists(string  $key) : boolean

Checks for the existence of a configuration key.

Parameters

string $key

The configuration key to check for.

Returns

boolean —

True, if the key is available, false otherwise.

_store_from_object()

_store_from_object(boolean  $global = false,   $merge = false) 

Fetch the configuration data stored in the parameter domain _path of _object.

The flag $global controls whether the global or the local configuration should be updated. No control whether an update of the global data is allowed is done here, the caller has to do this. This function will update the config data cache array. If it stores global configuration data it will automatically erase the local configuration data.

Any error such as invalid configuration data will trigger a MidCOM error.

Parameters

boolean $global

Set to true to replace the global configuration.

$merge

_update_cache()

_update_cache() 

Merge the local and the global configuration arrays into the cache array.

_check_local_array()

_check_local_array(array  $array) 

Check local data array for validity

Since the local array must only include configuration parameters that are included in the global configuration, this function is used to check a local array against the current global configuration. true/false is returned accordingly.

Parameters

array $array