$conf
$conf : \Phabstractic\Features\Zend\Config\Config
The objects configuration object
Should be an instance of Zend/Config
Builder Class - Creates and Defines OO-defined Builder Interfaces/Objects
The Builder class which when instantiated can define a builder interface and builder abstract class that can then be 'baked' into the appropriate namespace (or global namespace) and accessed, once baked, as a builder class to inherit from.
A static 'registry' makes sure that the programmer doesn't try to instantiate a fully qualified BuilderInterface twice, and throws an error.
CHANGELOG
1.0: created Builder - August 6th, 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(string $builderName, array $methods = array(), array $options = array())
Builder construction, Set Up builder parameters
This sets up the parameters for the builder to be generated It only generates the class when the option 'bake' is set to true
Options: strict => throw errors bake => define the classes immediately with the given parameters namespace => define the namespace
string | $builderName | The name of the factory class, turned into {BuilderName}BuildableInterface, Abstract{BuilderName}Factory, {BuilderName}Builder |
array | $methods | The methods of the class, turned into makeMethod |
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?
setBuilderName( $builderName)
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
$builderName |
when the qualified name clashes with an already created enumerator class
when 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.
buildBuilder( $builderName, array $methods, 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
$builderName | ||
array | $methods | The methods to be defined in the factory |
array | $options | See (__construct) |
createBuilder() : boolean
Generates the required class code and evaluates it
The function that pieces the generated code together and evaluates it
Evaluations: $this->builderName The name of the generated interface/classes (is turned into BuilderNameBuildableInterface, and AbstractBuilderNameBuildable, and BuilderNameBuilder) $this->methods The methods to put in the interface/classes (are turned into setMethod)
if class couldn't be generated
if interfaces and classes are generated without errors