1: <?php
2:
3: namespace Charcoal\Ui\Form;
4:
5: use \Pimple\Container;
6:
7: // From 'charcoal-factory'
8: use \Charcoal\Factory\FactoryInterface;
9:
10: /**
11: * Form Builder
12: */
13: class FormBuilder
14: {
15: /**
16: * The default, concrete, form model.
17: *
18: * @const string
19: */
20: const DEFAULT_TYPE = 'charcoal/ui/form/generic';
21:
22: /**
23: * Store the form factory instance.
24: *
25: * @var FactoryInterface
26: */
27: protected $factory;
28:
29: /**
30: * Store the dependency-injection container to fulfill the required services.
31: *
32: * @var Container $container
33: */
34: protected $container;
35:
36: /**
37: * Return a new form builder.
38: *
39: * @param FactoryInterface $factory An form factory.
40: */
41: public function __construct(FactoryInterface $factory)
42: {
43: $this->factory = $factory;
44: }
45:
46: /**
47: * Build and return a new form.
48: *
49: * @param array|\ArrayAccess $options The form build options.
50: * @return DashboardInterface
51: */
52: public function build($options)
53: {
54: $objType = isset($options['type']) ? $options['type'] : self::DEFAULT_TYPE;
55:
56: $obj = $this->factory->create($objType);
57: $obj->setData($options);
58:
59: return $obj;
60: }
61: }
62: