1 | <?php |
||
22 | abstract class AbstractFormObjectBuilder implements FormObjectBuilderInterface |
||
23 | { |
||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $className; |
||
28 | |||
29 | /** |
||
30 | * @var FormObjectStatic |
||
31 | */ |
||
32 | protected $static; |
||
33 | |||
34 | /** |
||
35 | * @param string $className |
||
36 | * @return FormObjectStatic |
||
37 | */ |
||
38 | public function getStaticInstance($className) |
||
39 | { |
||
40 | $this->className = $className; |
||
41 | |||
42 | $formDefinitionObject = $this->getFormDefinitionObject(); |
||
43 | |||
44 | $this->static = Core::instantiate( |
||
45 | FormObjectStatic::class, |
||
46 | $this->className, |
||
47 | $formDefinitionObject |
||
48 | ); |
||
49 | |||
50 | $this->process(); |
||
51 | |||
52 | // $middleware = $this->static->getDefinition()->addMiddleware( |
||
53 | // 'test', |
||
54 | // \Romm\FormzExample\Middlewares\TestMiddleware::class, |
||
55 | // function (\Romm\FormzExample\Middlewares\Options\TestOptions $options) { |
||
56 | // $options->setFoo('pouet'); |
||
57 | // } |
||
58 | // ); |
||
59 | // debug($middleware); |
||
60 | // die('!!'); |
||
61 | |||
62 | $formDefinitionObject->refreshValidationResult(); |
||
63 | |||
64 | return $this->static; |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @return FormDefinitionObject |
||
69 | */ |
||
70 | protected function getFormDefinitionObject() |
||
77 | |||
78 | /** |
||
79 | * Override this function in child classes to implement custom processes. |
||
80 | */ |
||
81 | protected function process() |
||
84 | |||
85 | /** |
||
86 | * Must return the form definition of the form class. |
||
87 | * |
||
88 | * @return FormDefinition |
||
89 | */ |
||
90 | abstract public function getFormDefinition(); |
||
91 | } |
||
92 |