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 FormObjectFactory |
||
53 | */ |
||
54 | protected $formObjectFactory; |
||
55 | |||
56 | /** |
||
57 | * @var PersistenceManager |
||
58 | */ |
||
59 | protected $persistenceManager; |
||
60 | |||
61 | /** |
||
62 | * @var FormObjectSteps |
||
63 | */ |
||
64 | protected $stepService; |
||
65 | |||
66 | /** |
||
67 | * You should never create a new instance of this class directly, use the |
||
68 | * `FormObjectFactory->getInstanceFromClassName()` function instead. |
||
69 | * |
||
70 | * @param string $name |
||
71 | * @param FormObjectStatic $static |
||
72 | */ |
||
73 | public function __construct($name, FormObjectStatic $static) |
||
74 | { |
||
75 | $this->name = $name; |
||
76 | $this->static = $static; |
||
77 | |||
78 | $this->persistenceManager = Core::instantiate(PersistenceManager::class, $this); |
||
79 | $this->stepService = Core::instantiate(FormObjectSteps::class, $this); |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * @return string |
||
84 | */ |
||
85 | public function getName() |
||
86 | { |
||
87 | return $this->name; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @return string |
||
92 | */ |
||
93 | public function getClassName() |
||
94 | { |
||
95 | return $this->static->getClassName(); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @param string $name |
||
100 | * @return bool |
||
101 | */ |
||
102 | public function hasProperty($name) |
||
103 | { |
||
104 | return $this->static->hasProperty($name); |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * @return Form |
||
109 | */ |
||
110 | public function getConfiguration() |
||
111 | { |
||
112 | return $this->static->getConfiguration(); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * @return Result |
||
117 | */ |
||
118 | public function getConfigurationValidationResult() |
||
119 | { |
||
120 | return $this->static->getConfigurationValidationResult(); |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * @return FormInterface |
||
125 | */ |
||
126 | public function getForm() |
||
127 | { |
||
128 | return $this->getProxy()->getForm(); |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * @return bool |
||
133 | */ |
||
134 | public function hasForm() |
||
135 | { |
||
136 | return $this->proxy !== null; |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * @param FormInterface $form |
||
141 | * @throws DuplicateEntryException |
||
142 | */ |
||
143 | public function setForm(FormInterface $form) |
||
144 | { |
||
145 | if ($this->proxy) { |
||
146 | throw DuplicateEntryException::formInstanceAlreadyAdded($this); |
||
147 | } |
||
148 | |||
149 | $this->proxy = $this->createProxy($form); |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * @return bool |
||
154 | */ |
||
155 | public function formWasSubmitted() |
||
156 | { |
||
157 | return $this->hasForm() && $this->getProxy()->formWasSubmitted(); |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * @return bool |
||
162 | */ |
||
163 | public function formWasValidated() |
||
164 | { |
||
165 | return $this->hasForm() && $this->getProxy()->formWasValidated(); |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * @return FormResult |
||
170 | */ |
||
171 | public function getFormResult() |
||
172 | { |
||
173 | return $this->getProxy()->getFormResult(); |
||
174 | } |
||
175 | |||
176 | /** |
||
177 | * @return FormObjectRequestData |
||
178 | */ |
||
179 | public function getRequestData() |
||
180 | { |
||
181 | return $this->getProxy()->getRequestData(); |
||
182 | } |
||
183 | |||
184 | /** |
||
185 | * @return FormMetadata |
||
186 | */ |
||
187 | public function getFormMetadata() |
||
188 | { |
||
189 | return $this->getProxy()->getFormMetadata(); |
||
190 | } |
||
191 | |||
192 | /** |
||
193 | * @return string |
||
194 | */ |
||
195 | public function getFormHash() |
||
196 | { |
||
197 | return $this->getProxy()->getFormHash(); |
||
198 | } |
||
199 | |||
200 | /** |
||
201 | * @return string |
||
202 | */ |
||
203 | public function getObjectHash() |
||
207 | |||
208 | /** |
||
209 | * @return PersistenceManager |
||
210 | */ |
||
211 | public function getPersistenceManager() |
||
215 | |||
216 | /** |
||
217 | * This function will search among the registered steps to find the one that |
||
218 | * has the same controller parameters. |
||
219 | * |
||
220 | * It is also possible not to find any step, in this case `null` is |
||
221 | * returned. |
||
222 | * |
||
223 | * @param Request $request |
||
224 | * @return Step|null |
||
225 | */ |
||
226 | public function getCurrentStep(Request $request) |
||
227 | { |
||
228 | return $this->stepService->getCurrentStep($request); |
||
229 | } |
||
230 | |||
231 | /** |
||
232 | * @return FormObjectProxy |
||
233 | * @throws PropertyNotAccessibleException |
||
234 | */ |
||
235 | protected function getProxy() |
||
243 | |||
244 | /** |
||
245 | * Wrapper for unit tests. |
||
246 | * |
||
247 | * @param FormInterface $form |
||
248 | * @return FormObjectProxy |
||
249 | */ |
||
250 | protected function createProxy(FormInterface $form) |
||
254 | |||
255 | /** |
||
256 | * @param FormObjectFactory $formObjectFactory |
||
257 | */ |
||
258 | public function injectFormObjectFactory(FormObjectFactory $formObjectFactory) |
||
262 | } |
||
263 |