$_global
$_global : Array
Globally assigned configuration data.
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.
__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.
mixed | $param1 | Either an associative array or a Midgard object. |
mixed | $param2 | Either null or the name of a Parameter domain. |
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.
array | $params | The new local parameters |
boolean | $reset | If set to true, the current local configuration will be discarded first. |
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.
\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 |
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).
string | $key | The configuration key to query. |
Its value or false, if the key doesn't exist.
_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.
boolean | $global | Set to true to replace the global configuration. |
$merge |
_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.
array | $array |