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.

package midcom.helper

 Methods

__construct (mixed $param1, mixed $param2)

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

$param1

mixedEither an associative array or a reference to a Midgard object.

$param2

mixedEither null or the name of a Parameter domain.

exists (string $key)

Checks for the existence of a configuration key.

Parameters

$key

stringThe configuration key to check for.

Returns

booleanTrue, if the key is available, false otherwise.

get (string $key)

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).

see \midcom_helper_configuration::exists()

Parameters

$key

stringThe configuration key to query.

Returns

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

get_all ()

Retrieve a copy the complete configuration array.

Returns

ArrayThe complete current configuration.

reset_local ()

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

store (array $params, boolean $reset)

The method store will 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.

see \midcom_helper_configuration::reset_local()

Parameters

$params

arrayThe new local parameters

$reset

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

Returns

booleanIndicating success.

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

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

$object

\MidgardObjectThe object from which to import data.

$path

stringThe parameter domain to query.

$merge

booleanShould the existing local config be overridden or merged

Returns

booleanIndicating success

_check_local_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

_store_from_object (boolean $global, $merge)

This function will fetch the configuration data stored in the parameter domain $path of the Midgard Object $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

$global

booleanSet to true to replace the global configuration.

$merge

_update_cache ()

This method will merge the local and the global configuration arrays into the cache array.

 Properties

 

Array $_global

Globally assigned configuration data.
 

Array $_local

Locally overridden configuration data.
 

Array $_merged

Merged, current configuration state.
 

mixed $_object

 

mixed $_object_stored

Internal cache-related items
ignore
 

mixed $_path