Matthimatiker / MolComponents

Library with use-at-will architecture that extends the functionality of Zend Framework 1. Main features: Improved bootstrapping with lazy loading of resources, declaration of request parameters as argument in controller actions, advanced form creation and validation, mail templates, lightweight controller testing.
Other
2 stars 0 forks source link

Implement object builder #22

Closed Matthimatiker closed 12 years ago

Matthimatiker commented 12 years ago

Create a factory that is able to create instances of a specified type.

It should be possible to provide a type constraint. When a class instance is requested then the factory should check if it meets the type requirement (before creating the object).

That factory could be useful if it is possible to configure classes, but type constraints must be enforced (for example implementation of an interface).

Matthimatiker commented 12 years ago

Created helper class Mol_Util_ObjectBuilder. The builder accepts an optional type constraint as constructor argument. The method create() is used to instantiate classes that meet the type requirements.

Example:

$builder = new Mol_Util_ObjectBuilder('Countable');
$initialValues = array(1, 2, 3);
$object = $builder->create('ArrayObject', array($initialValues));