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->proxy = $this->createProxy($form); |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * @return bool |
||
134 | */ |
||
135 | public function formWasSubmitted() |
||
136 | { |
||
137 | return $this->hasForm() && $this->getProxy()->formWasSubmitted(); |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * @return bool |
||
142 | */ |
||
143 | public function formWasValidated() |
||
144 | { |
||
145 | return $this->hasForm() && $this->getProxy()->formWasValidated(); |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * @return FormResult |
||
150 | */ |
||
151 | public function getFormResult() |
||
152 | { |
||
153 | return $this->getProxy()->getFormResult(); |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * @return FormObjectRequestData |
||
158 | */ |
||
159 | public function getRequestData() |
||
160 | { |
||
161 | return $this->getProxy()->getRequestData(); |
||
162 | } |
||
163 | /** |
||
164 | * @return FormMetadata |
||
165 | */ |
||
166 | public function getFormMetadata() |
||
167 | { |
||
168 | return $this->getProxy()->getFormMetadata(); |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * @return string |
||
173 | */ |
||
174 | public function getFormHash() |
||
175 | { |
||
176 | return $this->getProxy()->getFormHash(); |
||
177 | } |
||
178 | |||
179 | /** |
||
180 | * @return string |
||
181 | */ |
||
182 | public function getObjectHash() |
||
183 | { |
||
184 | return $this->static->getObjectHash(); |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * @return PersistenceManager |
||
189 | */ |
||
190 | public function getPersistenceManager() |
||
191 | { |
||
192 | return $this->persistenceManager; |
||
193 | } |
||
194 | |||
195 | /** |
||
196 | * @return bool |
||
197 | */ |
||
198 | public function hasSteps() |
||
199 | { |
||
200 | return $this->getDefinition()->hasSteps(); |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * @param Request $request |
||
205 | * @return Step|null |
||
206 | */ |
||
207 | public function getCurrentStep(Request $request) |
||
208 | { |
||
209 | return $this->getProxy()->getCurrentStep($request); |
||
210 | } |
||
211 | |||
212 | /** |
||
213 | * @return Substep|null |
||
214 | */ |
||
215 | public function getCurrentSubstep() |
||
216 | { |
||
217 | return $this->getProxy()->getCurrentSubstep(); |
||
218 | |||
219 | } |
||
220 | |||
221 | /** |
||
222 | * @return FormObjectProxy |
||
223 | * @throws PropertyNotAccessibleException |
||
224 | */ |
||
225 | protected function getProxy() |
||
233 | |||
234 | /** |
||
235 | * Wrapper for unit tests. |
||
236 | * |
||
237 | * @param FormInterface $form |
||
238 | * @return FormObjectProxy |
||
239 | */ |
||
240 | protected function createProxy(FormInterface $form) |
||
244 | } |
||
245 |