1 | <?php |
||
42 | class FormObjectFactory implements SingletonInterface |
||
43 | { |
||
44 | use ExtendedSelfInstantiateTrait; |
||
45 | |||
46 | /** |
||
47 | * @var FormObject[] |
||
48 | */ |
||
49 | protected $instances = []; |
||
50 | |||
51 | /** |
||
52 | * @var FormObjectStatic[] |
||
53 | */ |
||
54 | protected $static = []; |
||
55 | |||
56 | /** |
||
57 | * @var FormObjectProxy[] |
||
58 | */ |
||
59 | protected $proxy = []; |
||
60 | |||
61 | /** |
||
62 | * Returns the form object for the given form instance. The form instance |
||
63 | * must have been defined first in this factory, or an exception is thrown. |
||
64 | * |
||
65 | * @param FormInterface $form |
||
66 | * @return FormObject |
||
67 | * @throws EntryNotFoundException |
||
68 | */ |
||
69 | public function getInstanceWithFormInstance(FormInterface $form) |
||
77 | |||
78 | /** |
||
79 | * Checks that the given form instance was registered in this factory. |
||
80 | * |
||
81 | * @param FormInterface $form |
||
82 | * @return bool |
||
83 | */ |
||
84 | public function formInstanceWasRegistered(FormInterface $form) |
||
88 | |||
89 | /** |
||
90 | * Registers a new form instance. |
||
91 | * |
||
92 | * @param FormInterface $form |
||
93 | * @param string $name |
||
94 | * @throws DuplicateEntryException |
||
95 | * @throws InvalidArgumentValueException |
||
96 | */ |
||
97 | public function registerFormInstance(FormInterface $form, $name) |
||
111 | |||
112 | /** |
||
113 | * A shortcut function to register the given form instance (if it was not |
||
114 | * already registered) and return the form object. |
||
115 | * |
||
116 | * @param FormInterface $form |
||
117 | * @param string $name |
||
118 | * @return FormObject |
||
119 | */ |
||
120 | public function registerAndGetFormInstance(FormInterface $form, $name) |
||
121 | { |
||
122 | if (false === $this->formInstanceWasRegistered($form)) { |
||
123 | $this->registerFormInstance($form, $name); |
||
124 | } |
||
125 | |||
126 | return $this->getInstanceWithFormInstance($form); |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * Will create an instance of `FormObject` based on a class that implements |
||
131 | * the interface `FormInterface`. |
||
132 | * |
||
133 | * @param string $className |
||
134 | * @param string $name |
||
135 | * @return FormObject |
||
136 | */ |
||
137 | public function getInstanceWithClassName($className, $name) |
||
144 | |||
145 | /** |
||
146 | * Returns the proxy object for the given form object and form instance. |
||
147 | * |
||
148 | * Please use with caution, as this is a very low level function! |
||
149 | * |
||
150 | * @param FormInterface $form |
||
151 | * @return FormObjectProxy |
||
152 | */ |
||
153 | public function getProxy(FormInterface $form) |
||
163 | |||
164 | /** |
||
165 | * @param string $className |
||
166 | * @return FormObjectStatic |
||
167 | * @throws ClassNotFoundException |
||
168 | * @throws InvalidArgumentTypeException |
||
169 | */ |
||
170 | protected function getStaticInstance($className) |
||
203 | |||
204 | /** |
||
205 | * @param string $className |
||
206 | * @return string |
||
207 | */ |
||
208 | protected function getCacheIdentifier($className) |
||
214 | |||
215 | /** |
||
216 | * Wrapper for unit tests. |
||
217 | * |
||
218 | * @param string $className |
||
219 | * @return FormObjectStatic |
||
220 | */ |
||
221 | protected function buildStaticInstance($className) |
||
228 | |||
229 | /** |
||
230 | * Wrapper for unit tests. |
||
231 | * |
||
232 | * @param FormInterface $form |
||
233 | * @return FormObjectProxy |
||
234 | */ |
||
235 | protected function getNewProxyInstance(FormInterface $form) |
||
244 | |||
245 | /** |
||
246 | * @return Configuration|ConfigurationObjectInterface |
||
247 | */ |
||
248 | protected function getRootConfiguration() |
||
252 | |||
253 | /** |
||
254 | * @return FrontendInterface |
||
255 | */ |
||
256 | protected function getCacheInstance() |
||
260 | } |
||
261 |