1 | <?php |
||
33 | class FormObject |
||
34 | { |
||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $name; |
||
39 | |||
40 | /** |
||
41 | * @var FormObjectStatic |
||
42 | */ |
||
43 | protected $static; |
||
44 | |||
45 | /** |
||
46 | * @var FormObjectProxy |
||
47 | */ |
||
48 | protected $proxy; |
||
49 | |||
50 | /** |
||
51 | * @var FormObjectFactory |
||
52 | */ |
||
53 | protected $formObjectFactory; |
||
54 | |||
55 | /** |
||
56 | * @var PersistenceManager |
||
57 | */ |
||
58 | protected $persistenceManager; |
||
59 | |||
60 | /** |
||
61 | * You should never create a new instance of this class directly, use the |
||
62 | * `FormObjectFactory->getInstanceFromClassName()` function instead. |
||
63 | * |
||
64 | * @param string $name |
||
65 | * @param FormObjectStatic $static |
||
66 | */ |
||
67 | public function __construct($name, FormObjectStatic $static) |
||
68 | { |
||
69 | $this->name = $name; |
||
70 | $this->static = $static; |
||
71 | |||
72 | $this->persistenceManager = Core::instantiate(PersistenceManager::class, $this); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @return string |
||
77 | */ |
||
78 | public function getName() |
||
79 | { |
||
80 | return $this->name; |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @return string |
||
85 | */ |
||
86 | public function getClassName() |
||
87 | { |
||
88 | return $this->static->getClassName(); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @param string $name |
||
93 | * @return bool |
||
94 | */ |
||
95 | public function hasProperty($name) |
||
96 | { |
||
97 | return $this->static->hasProperty($name); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * @return Form |
||
102 | */ |
||
103 | public function getConfiguration() |
||
104 | { |
||
105 | return $this->static->getConfiguration(); |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @return Result |
||
110 | */ |
||
111 | public function getConfigurationValidationResult() |
||
112 | { |
||
113 | return $this->static->getConfigurationValidationResult(); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * @return FormInterface |
||
118 | */ |
||
119 | public function getForm() |
||
120 | { |
||
121 | return $this->getProxy()->getForm(); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * @return bool |
||
126 | */ |
||
127 | public function hasForm() |
||
128 | { |
||
129 | return $this->proxy !== null; |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * @param FormInterface $form |
||
134 | * @throws DuplicateEntryException |
||
135 | */ |
||
136 | public function setForm(FormInterface $form) |
||
137 | { |
||
138 | if ($this->proxy) { |
||
139 | throw DuplicateEntryException::formInstanceAlreadyAdded($this); |
||
140 | } |
||
141 | |||
142 | $this->proxy = $this->createProxy($form); |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * Returns `true` if the form was submitted by the user. |
||
147 | * |
||
148 | * @return bool |
||
149 | */ |
||
150 | public function formWasSubmitted() |
||
151 | { |
||
152 | return $this->hasForm() && $this->getProxy()->formWasSubmitted(); |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * @return FormResult |
||
157 | */ |
||
158 | public function getFormResult() |
||
159 | { |
||
160 | return $this->getProxy()->getFormResult(); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * @return bool |
||
165 | */ |
||
166 | public function hasFormResult() |
||
167 | { |
||
168 | return $this->getProxy()->hasFormResult(); |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * @return FormObjectRequestData |
||
173 | */ |
||
174 | public function getRequestData() |
||
178 | |||
179 | /** |
||
180 | * @return FormMetadata |
||
181 | */ |
||
182 | public function getFormMetadata() |
||
186 | |||
187 | /** |
||
188 | * @return string |
||
189 | */ |
||
190 | public function getFormHash() |
||
194 | |||
195 | /** |
||
196 | * @return string |
||
197 | */ |
||
198 | public function getObjectHash() |
||
199 | { |
||
200 | return $this->static->getObjectHash(); |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * @return PersistenceManager |
||
205 | */ |
||
206 | public function getPersistenceManager() |
||
207 | { |
||
210 | |||
211 | /** |
||
212 | * This function will search among the registered steps to find the one that |
||
213 | * has the same controller parameters. |
||
214 | * |
||
215 | * It is also possible not to find any step, in this case `null` is |
||
216 | * returned. |
||
217 | * |
||
218 | * @param Request $request |
||
219 | * @return StepItem|null |
||
220 | */ |
||
221 | public function getCurrentStep(Request $request) |
||
257 | |||
258 | /** |
||
259 | * @return FormObjectProxy |
||
260 | * @throws PropertyNotAccessibleException |
||
261 | */ |
||
262 | protected function getProxy() |
||
270 | |||
271 | /** |
||
272 | * Wrapper for unit tests. |
||
273 | * |
||
274 | * @param FormInterface $form |
||
275 | * @return FormObjectProxy |
||
276 | */ |
||
277 | protected function createProxy(FormInterface $form) |
||
281 | |||
282 | /** |
||
283 | * @param FormObjectFactory $formObjectFactory |
||
284 | */ |
||
285 | public function injectFormObjectFactory(FormObjectFactory $formObjectFactory) |
||
289 | } |
||
290 |