$conf
$conf : \Phabstractic\Features\Zend\Config\Config
The objects configuration object
Should be an instance of Zend/Config
AbstractFactory Class - Creates and Defines OO-defined AbstractFactory Classes/Objects
The AbstractFactory class which when instantiated can define an abstract factory that can then be 'baked' into the appropriate namespace (or global namespace) and accessed, once baked, as an AbstractFactory class of itself.
A static 'registry' makes sure that the programmer doesn't try to instantiate a fully qualified AbstractFactory twice, and throws an error.
CHANGELOG
1.0 created AbstractFactory - May 27th, 2013 2.0: Integrated into Primus2 - August 30th, 2015 3.0: configuration information is now in one place, the constructor refactored createAbstractFactory to access object properties clarified all exceptions as coming from patterns/exception reformatted for inclusion into phabstractic - July 20th, 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( $factoryName, array $methods = array(), array $constants = array(), array $options = array())
AbstractFactory construction, Set Up abstract factory parameters
This sets up the parameters for the abstractfactory to be generated It only generas the class when the option 'bake' is set to true
Options: strict => throw errors namespace => namespace to define this enumerator in bake => define the class immediately with the given parameters
$factoryName | ||
array | $methods | The methods of the class, turned into makeMethod |
array | $constants | The constants if any defined for the class ($key = $value) |
array | $options | See above options |
bake() : boolean
Generates the abstract factory class in the desired namespace
Generates the abstract factory class in the desired namespace using the given parameters, in essence solidifying them in place. Once an abstract factory class is 'baked' it cannot be changed.
This function also pushes the qualified name onto a static set so that future abstract factories defined through this method don't clash in name, allowing the class ro raise a RangeException
Success or failure?
setFactoryName(string $factoryName)
Sets the name of the class to be generated
Checks to make sure the proposed fully qualified name doesn't clash with an already created enumerator object, raising a RangeException error
Remember, factoryName becomes Abstract{FactoryName}Factory
string | $factoryName | The name of the class to be generated |
when the qualified name clashes with an already created enumerator class
when the class has already been baked
setConstants(array $constants)
Sets any desired constants to be defined in the abstract factory
array | $constants | An array containing the constant names => values |
when the class has already been generated (baked)
addConstant(string $name, mixed $value)
Add a single constant to the constant list
This method overrides any constant names already defined with the new proposed values
string | $name | The name of the constant |
mixed | $value | May be anything a constant can be defined as |
if the class has already been baked
addConstants(array $constants)
Add multiple constants to the constant list
This method employs the array structure identifier => value. Overrides any constant names already defined with the new proposed values
array | $constants |
if the class has already been baked
removeConstant( $name)
Remove a constant from the constant list
This method removes a constant from the constant list only if the class has not been generated, otherwise it throws an error
$name |
if the class has already been baked
setMethods(array $methods)
Sets the abstract factory methods
Remember, method names are transformed into makeMethod
array | $methods | An array containing the method names |
when the class has already been generated (baked)
addMethod(string $method)
Add a single method to the method list
This method overrides any method names already defined with the new proposed values
Remember: method becomes makeMethod
string | $method | The name of the method |
if the class has already been baked
addMethods(array $methods)
Add multiple methods to the method list
This method employs the array structure identifier => value. Overrides any method names already defined with the new proposed values
array | $methods | The array of methods to add to the list |
if the class has already been baked
removeMethod(string $method)
Remove a method from the method list
This method removes a method from the method list only if the class has not been generated, otherwise it throws an error
Remember: NOT makeMethod, just method
string | $method | Name of the method |
if the class has already been baked
setNamespace(string $namespace)
Sets up the namespace to be used when generating the abstract factory class
This sets the namespace that will be used when the enumerator class is generated How? Eval statements operate in the global namespace, or basically a clean slate enabling us to put a namespace statement at the beginning of our generated code Any namespace will do, if there is no namespace, you must access your abstract factory using the global namespace. ex: \Months::January, \Colors::Red, ...
string | $namespace | The namespace specified |
when the class/namespace has already been generated via Enum
if the class has already been generated/baked.
buildAbstractFactory(string $factoryName, array $methods, array $constants = array(), array $options = array())
Straight out define the abstract factory class without instantiating
Takes care of the instantiation and defines the abstract factory according to parameters
string | $factoryName | The name of the abstract factory class (remember Abstract{FactoryName}Factory) |
array | $methods | The methods to be defined in the factory |
array | $constants | The constants to be defined in the factory |
array | $options | See (__construct) |
createAbstractFactory() : boolean
Generates the required class code and evaluates it
The function that pieces the generated code together and evaluates it
Evaluations: $this->factoryName The name of the generate class (is turned into AbstractFactoryNameFactory) $this->methods The methods to put in the factory (are turned into makeMethodName) $this->constants The constants to put in the factory (are turned uppercase)
if class couldn't be generated
if abstract factory class is generated without errors