systemConfigBase

systemConfigBase class contains the basic methods for reading, writing and modifying a configuration file. Scorpio config files are very simple XML files with the following structure:


    

Additionally, the config system supports the concept of protected values. By specifying override="" a parameter can be locked from being overwritten. This applies to the section as well. Override takes a boolean value which is one of: true, yes, 1 or false, no, 0.

Sections can contain multiple parameters and are used to group similar config params together. While further levels could be supported, this system only allows for a single section -> param setup to keep the files straight forward.

Example usage:

// load route config.xml file (system config)
$oConfig = new systemConfigBase();
$oConfig->load();

// load a custom config file
$oConfig = new systemConfigBase();
$oConfig->load('/path/to/my/config.xml');

// access a param
$oConfig->getParam('section','param', false);

When fetching params, a systemConfigParam object is returned. It is important to understand that this is a full object, and that to get the actual value it is necessary to either cast as a string, use in a string context or to call the method ->getParamValue().

You can freely extend this class into a specific configuration object with dedicated methods that return the values if you wish. This is done in systemConfig.

When calling getParam(), the third parameter is a default value that should be returned should a value not be found. This defaults to false (the boolean false, not a string containing false). If you wish another value, simply specify it when calling getParam().

Note: When loading files, should a param attempt to overwrite an existing param that is marked as not overridable, an exception will be thrown. You can either catch the exception, or allow it to bubble. The default is to allow it to bubble as this (could be) an attempt to change core system parameters. The raised exception will give the name of the parameter AND the value that was going to be written - it does not give the existing value. Either way: it is up to the developer to decide how to handle this.


Methods

public __construct()

Returns new systemConfigBase

public reset()

Resets the object

public load([$inFilename = false])

Reads an XML config file into the systemConfigBase class, if no path attempts to load from the current location

The XML should be structured as:

public save()

Attempts to save the current config to the last read file location

public addSection($oSection)

Adds the section to the set but only if it can be overridden

public getSection($inSectionName)

Returns the section with name $sectionName; if it does not exist, it is created

public getParam($inSectionName, $inParamName, [$inDefault = false])

Returns systemConfigParam, if $inDefault set, param will inherit this value

private setBasePath()

Sets the base path relative to the config file

public getBasePath()

Returns the current base path

public getConfigParams()

Returns ConfigParams

public setConfigParams($inConfigParams)

Set ConfigParams property

public getLastConfigFile()

Returns LastConfigFile

public setLastConfigFile($inString)

Set LastConfigFile property

public getModified()

Returns true if set has been modified

private _convertToBoolean($inValue)

Converts $inValue to boolean true or false if the string can be interrpreted as a boolean value


Inherited Methods

<  1  >