$conf
$conf : \Phabstractic\Features\Zend\Config\Config
The objects configuration object
Should be an instance of Zend/Config
Restricted Set Class - Defines A Restricted Set Data Structure
An instantiated Set is like an array, but only holds unique values without really any keys to the set itself. It's just a collection of unique values, like a pool of variables. This makes the Set only hold certain values, usually one type.
NOTE: You can only set the restrictions of this object in the constructor Which makes sense, what would you do half-way through if all of a sudden half your set doesn't qualify anymore? Seems like a mess.
CHANGELOG
1.0: Documented RestrictedSet - March 5th, 2013 1.1: Fixed Options initialization - May 16th, 2013 2.0: Refactored and re-formatted for inclusion in Primus - April 11th, 2015 3.0: added option filter_class to specify alternate static function call reformatted for inclusion in phabstractic - July 201th, 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 $values = array(), \Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\AbstractFilter $restrictions = null, array $options = array())
RestrictedSet Class Constructor
This sets up the restrictions for the values, then provides the options to the parent set. This is the only place to set the restrictions for the set.
options - 'filter_class' => the class that the checkElements static function is called on
array | $values | The values for the RestrictedSet |
\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\AbstractFilter | $restrictions | The restrictions for the data type |
array | $options | The options for the parent set. |
retrieveReference(mixed $identifier) : mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None;
If the value is in the set, this retrieves a reference to it
This only works if the set is considered unique
mixed | $identifier | The identifier returned by the add function |
if strict
add(mixed $value) : string|false
Add a value to the set
Runs the value by the restrictions, only triggering if set is strict otherwise doing nothing and exiting the function
mixed | $value | Value to add to the set, must be of allowed type |
if 'strict' option is set and type is not in Restrictions
The identifier for the entry, false otherwise
addReference(mixed $value) : string|false
Add a value to the set as a reference
Runs the value by the restrictions, only triggering if set is strict otherwise doing nothing and exiting the function
mixed | $value | Value to add to the set, must be of allowed type |
if 'strict' option is set and type is not in Restrictions
The datum identifier, false otherwise
equal(\Phabstractic\Data\Types\Resource\SetInterface $S1, \Phabstractic\Data\Types\Resource\SetInterface $S2) : boolean
Is S1 Equal to S2?
This static function converts the sets to plain arrays, but compares them using the arrayUtilities function.
\Phabstractic\Data\Types\Resource\SetInterface | $S1 | |
\Phabstractic\Data\Types\Resource\SetInterface | $S2 |
fold(callable $F, \Phabstractic\Data\Types\Set $S) : mixed
Apply a function to each element of the set, reducing to a single function
"returns the value A|S| after applying Ai+1 := F(Ai, e) for each element e of S."
callable | $F | The applicable function. |
\Phabstractic\Data\Types\Set | $S | The Set to fold |
The value resulting from the 'fold' (array_reduce)
filter(callable $F, \Phabstractic\Data\Types\Set $S) : array
Returns only elements that satisfy a 'predicate'
The predicate here is a function that returns true or false on any given item "returns the subset containing all elements of S that satisfy a given predicate P."
callable | $F | The applicable predicate function. |
\Phabstractic\Data\Types\Set | $S | The Set to filter |
The filtered aray
map(callable $F, \Phabstractic\Data\Types\Set $S) : array
Apply a function to each element of the set
"returns the set of distinct values resulting from applying function F to each element of S."
callable | $F | The applicable function. |
\Phabstractic\Data\Types\Set | $S | The Set to map |
The resulting distinct set
walk(\Phabstractic\Data\Types\Resource\SetInterface $S, callable $F, mixed $D) : boolean
Walk (non-recursively) the array
Applies the given function, plus any additional arguments ($args) past the given function argument to each element of the set.
Note: Unlike Map, this operates on a reference of the set
\Phabstractic\Data\Types\Resource\SetInterface | $S | |
callable | $F | the applicablt function |
mixed | $D | the user data |
True on Success, False otherwise
build(array $values = array(), \Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\AbstractFilter $restrictions = null, array $options = array()) : \Phabstractic\Data\Types\Phabstractic\Data\Types\RestrictedSet
Generates a RestrictedSet from an array
Default restrictions are all but TYPED_OBJECT
NOTE: This method signature expands on the Set::build static function PHP allows you to do this with default arguments
array | $values | The values to put in the Restricted Set |
\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\AbstractFilter | $restrictions | The Restrictions to place on the generated set |
array | $options | The restricted set options (See constructor) |
Generated RestrictedSet
subset(\Phabstractic\Data\Types\Set $S, \Phabstractic\Data\Types\Set $T) : boolean
Subset
"a predicate that tests whether the set S is a subset of set T."
This function tests whether all elements of S are in T
\Phabstractic\Data\Types\Set | $S | The first set |
\Phabstractic\Data\Types\Set | $T | The comparison/parent set |
mapInternal(string $method, array $args, \Phabstractic\Data\Types\Phabstractic\Data\Types\Set $S)
Calls an internal member function of a set member with arguments
Like map, only it calls a particular method on the given object, this is possible because the set can be guaranteed to hold only certain objects. !! Do not attempt on a mixed set. !!
string | $method | The method name to call |
array | $args | The arguments to pass to the method |
\Phabstractic\Data\Types\Phabstractic\Data\Types\Set | $S | The set to act on |
checkUniqueValues(array $values = array()) : boolean
Check an array for unique values
Useful for 'strict' option to warn of incoming duplicate entries
array | $values | The array to check |
When a value is not unique in the array if configured strict
Successful?