1 | <?php |
||
34 | class FormObject |
||
35 | { |
||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $name; |
||
40 | |||
41 | /** |
||
42 | * @var FormObjectStatic |
||
43 | */ |
||
44 | protected $static; |
||
45 | |||
46 | /** |
||
47 | * @var FormObjectProxy |
||
48 | */ |
||
49 | protected $proxy; |
||
50 | |||
51 | /** |
||
52 | * @var PersistenceManager |
||
53 | */ |
||
54 | protected $persistenceManager; |
||
55 | |||
56 | /** |
||
57 | * You should never create a new instance of this class directly, use the |
||
58 | * `FormObjectFactory->getInstanceFromClassName()` function instead. |
||
59 | * |
||
60 | * @param string $name |
||
61 | * @param FormObjectStatic $static |
||
62 | */ |
||
63 | public function __construct($name, FormObjectStatic $static) |
||
64 | { |
||
65 | $this->name = $name; |
||
66 | $this->static = $static; |
||
67 | |||
68 | $this->persistenceManager = Core::instantiate(PersistenceManager::class, $this); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @return string |
||
73 | */ |
||
74 | public function getName() |
||
75 | { |
||
76 | return $this->name; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @return string |
||
81 | */ |
||
82 | public function getClassName() |
||
83 | { |
||
84 | return $this->static->getClassName(); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @return FormDefinition |
||
89 | */ |
||
90 | public function getDefinition() |
||
91 | { |
||
92 | return $this->static->getDefinition(); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @return Result |
||
97 | */ |
||
98 | public function getDefinitionValidationResult() |
||
99 | { |
||
100 | return $this->static->getDefinitionValidationResult(); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * @return FormInterface |
||
105 | */ |
||
106 | public function getForm() |
||
107 | { |
||
108 | return $this->getProxy()->getForm(); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * @return bool |
||
113 | */ |
||
114 | public function hasForm() |
||
115 | { |
||
116 | return $this->proxy !== null; |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * @param FormInterface $form |
||
121 | * @throws DuplicateEntryException |
||
122 | */ |
||
123 | public function setForm(FormInterface $form) |
||
124 | { |
||
125 | if ($this->proxy) { |
||
126 | throw DuplicateEntryException::formInstanceAlreadyAdded($this); |
||
127 | } |
||
128 | |||
129 | $this->registerFormInstance($form); |
||
130 | |||
131 | $this->proxy = $this->createProxy($form); |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * @return bool |
||
136 | */ |
||
137 | public function formWasSubmitted() |
||
138 | { |
||
139 | return $this->hasForm() && $this->getProxy()->formWasSubmitted(); |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * @return bool |
||
144 | */ |
||
145 | public function formWasValidated() |
||
146 | { |
||
147 | return $this->hasForm() && $this->getProxy()->formWasValidated(); |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * @return FormResult |
||
152 | */ |
||
153 | public function getFormResult() |
||
157 | |||
158 | /** |
||
159 | * @return FormObjectRequestData |
||
160 | */ |
||
161 | public function getRequestData() |
||
162 | { |
||
163 | return $this->getProxy()->getRequestData(); |
||
164 | } |
||
165 | /** |
||
166 | * @return FormMetadata |
||
167 | */ |
||
168 | public function getFormMetadata() |
||
172 | |||
173 | /** |
||
174 | * @return string |
||
175 | */ |
||
176 | public function getFormHash() |
||
180 | |||
181 | /** |
||
182 | * @return string |
||
183 | */ |
||
184 | public function getObjectHash() |
||
188 | |||
189 | /** |
||
190 | * @return PersistenceManager |
||
191 | */ |
||
192 | public function getPersistenceManager() |
||
196 | |||
197 | /** |
||
198 | * @return bool |
||
199 | */ |
||
200 | public function isPersistent() |
||
204 | |||
205 | /** |
||
206 | * @return bool |
||
207 | */ |
||
208 | public function hasSteps() |
||
212 | |||
213 | /** |
||
214 | * @return Step|null |
||
215 | */ |
||
216 | public function getCurrentStep() |
||
220 | |||
221 | /** |
||
222 | * @param Request $request |
||
223 | * @return $this |
||
224 | */ |
||
225 | public function fetchCurrentStep(Request $request) |
||
231 | |||
232 | /** |
||
233 | * @return SubstepDefinition |
||
234 | */ |
||
235 | public function getCurrentSubstepDefinition() |
||
240 | |||
241 | /** |
||
242 | * @param FormInterface $form |
||
243 | */ |
||
244 | protected function registerFormInstance(FormInterface $form) |
||
250 | |||
251 | /** |
||
252 | * @return FormObjectProxy |
||
253 | * @throws PropertyNotAccessibleException |
||
254 | */ |
||
255 | protected function getProxy() |
||
263 | |||
264 | /** |
||
265 | * Wrapper for unit tests. |
||
266 | * |
||
267 | * @param FormInterface $form |
||
268 | * @return FormObjectProxy |
||
269 | */ |
||
270 | protected function createProxy(FormInterface $form) |
||
274 | } |
||
275 |