-
Book Overview & Buying
-
Table Of Contents
PHP 7 Programming Cookbook
By :
The purpose of a form factory is to generate a usable form object from a single configuration array. The form object should have the ability to retrieve the individual elements it contains so that output can be generated.
First, let's create a class called Application\Form\Factory to contain the factory code. It will have only one property, $elements, with a getter:
namespace Application\Form;
class Factory
{
protected $elements;
public function getElements()
{
return $this->elements;
}
// remaining code
}Before we define the primary form generation method, it's important to consider what configuration format we plan to receive, and what exactly the form generation will produce. For this illustration, we will assume that the generation will produce a Factory instance, with an $elements property. This property would be an array of Application\Form\Generic or Application\Form\Element classes.
We are now ready to tackle the generate...