$conf
$conf : \Phabstractic\Features\Zend\Config\Config
The objects configuration object
Should be an instance of Zend/Config
Structure class - Defines a structure with specific fields
Some objects need modifiable and runtime specific member variables that can also be accessed with generic functions
Some fields may need to be restricted to specific types Coding for such fields can be simplified by using tagged unions
CHANGELOG
1.0: Created Structure - July 18th, 2013 1.1: Updated Documentation - October 7th, 2013 2.0: Updated file for Primus integration - August 25th, 2015 3.0: pass fields as keys and initial values as values of the array reformatted for inclusion in phabstractic - July 20th, 2016 3.0.1: implements configurationinterface - July 31st, 2016
configure(array|string|\Phabstractic\Features\Zend\Config\Config $configuration, string $format = null, mixed $context = null) : boolean
Configure An Object
Expects an array for configuration however, you can also pass it a filepath where it will read the information from a file automatically detecting the format using the file extension. You can also pass a Zend/Config object already made.
You can also pass a format specifier (forced format) for use in a if $configuration is a string formatted with such information. E.G. to load from a string in the format ini:
$this->configure($configString, 'ini');
The $context argument is used for any additional reader constructor information, such as the constructor for the 'yaml' format.
NOTE: You can override/extend the classes used for reading formats by identifying an additional array in the property $this->configReaders. This will merge with the standard formats array.
array|string|\Phabstractic\Features\Zend\Config\Config | $configuration | The objects configuration information. |
string | $format | The forced format, or format for configuration string |
mixed | $context | Any additional information for a reader constructor, such as needed for the YAML format. |
True if instantiated
saveSettings(string $file, \Phabstractic\Features\Zend\Config\Writer\WriterInterface $writer = null, boolean $exclusive = true, mixed $context = null)
Save an Object's Configuration to a File
Takes an objects $conf property and writes the information contained therein to a file with a format automatically specified by the filename.
It is possible to retrieve a string of a particular format from this method by specifying the filename '#string' with an extension indicating the desired format, such as '#string.json'.
The $context argument is used for any additional reader constructor information, such as the constructor for the 'yaml' format.
NOTE: You can override/extend the classes used for writing formats by identifying an additional array in the property $this->configWriters. This will merge with the standard formats array.
string | $file | The file path to write to, or '#string.ext' |
\Phabstractic\Features\Zend\Config\Writer\WriterInterface | $writer | The optional writer object supplied to use (such as a MySQL writer) |
boolean | $exclusive | Argument provided to toFile(), file exclusive lock when writing |
mixed | $context | Any additionla writer constructor information (YAML) |
getSettings(string $format, $context = null) : string|boolean
Retrieve an Object's Configuration Information As String
This is a shortcut to ::saveSettings() which specifies a format and forces the return of a string, using the #string.ext filename -see documentation for ::saveSettings()-
string | $format | The format to return, must be supported by ::saveSettings(), use $this->configWriters to support additional formats. |
$context |
The formatted string, or false otherwise
processSettings(\Phabstractic\Features\Zend\Config\Processor\ProcessorInterface $processor)
Process an Object's Configuration
This uses a Zend\Config\Processor implementation to process the configuration information, such as constants. The processor must be supplied and implement ProcessorInterface
NOTE: Edits the $conf object in place.
\Phabstractic\Features\Zend\Config\Processor\ProcessorInterface | $processor | The given processor object |
__construct(array $allowed = array(), array $options = array())
Defines a Structure
This is where you specify the keys of the given fields as well as if any fields are restricted (tagged unions). Passing in a Restricitons object with tag (array) as an element of the array is all that is needed to initialize a tagged union item.
Ex: array('field1', 'field2', array($restrictions, 'field3'));
Options: strict - throw errors where applicable insensitive - make the keys (fields) insensitive (only for construction) Only one key of a particular value can then exist version2 - construct the fields using the algorithm in v2 false by default
array | $allowed | The field names as values, arrays for tagged unions and restrictions |
array | $options | The options for the object |
offsetSet(integer $key, mixed $value) : \Phabstractic\Data\Types\intNew
Set the offset in the list to the provided value
integer | $key | The index to the list item |
mixed | $value | The value to set to |
if the value is not a stack index
number of list elements
offsetGet(integer $key) : mixed
Retrieve the value in the list at the provided index
integer | $key | The index to the list item |
if the value is not a stack index
The value at the list index
offsetUnset(integer $key) : boolean
Unset the index and value on the list
This isn't applicable in a structure so it is disabled
Note: Like the unset method, this throws no error if the index doesn't exist.
integer | $key | The index to the list item |
False if the index is improper, or not numeric, true otherwise
getElementRestrictions(string $element) : null|\Phabstractic\Data\Types\Falcraft\Data\Types\Null|\Phabstractic\Data\Types\Falcraft\Data\Types\Restrictions
Returns the restrictions held by a given tagged union in the structure
Returns None() if there are no restrictions for that particular field but returns plain null if the key is not in the fields and strict is not enabled
string | $element | the key for the particular field |
The restrictions
getElement(string $element) : mixed|\Phabstractic\Data\Types\Falcraft\Data\Types\Null
Retrieve the value of a given element
Wraps tagged union functionality if need be
string | $element | The key/field name of the value |
Null() if key not present
setElement(string $element, mixed $value) : boolean
Set a given field to a given value
Wraps tagged union functionality
string | $element | The field name |
mixed | $value | The value to set the field to |
If key doesn't exist in fields
True on success