]> git.immae.eu Git - github/wallabag/wallabag.git/blame - vendor/symfony/form/Symfony/Component/Form/Button.php
gitignore vendor
[github/wallabag/wallabag.git] / vendor / symfony / form / Symfony / Component / Form / Button.php
CommitLineData
4f5b44bd
NL
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Form;
13
14use Symfony\Component\Form\Exception\AlreadySubmittedException;
15use Symfony\Component\Form\Exception\BadMethodCallException;
16
17/**
18 * A form button.
19 *
20 * @author Bernhard Schussek <bschussek@gmail.com>
21 */
22class Button implements \IteratorAggregate, FormInterface
23{
24 /**
25 * @var FormInterface
26 */
27 private $parent;
28
29 /**
30 * @var FormConfigInterface
31 */
32 private $config;
33
34 /**
35 * @var Boolean
36 */
37 private $submitted = false;
38
39 /**
40 * Creates a new button from a form configuration.
41 *
42 * @param FormConfigInterface $config The button's configuration.
43 */
44 public function __construct(FormConfigInterface $config)
45 {
46 $this->config = $config;
47 }
48
49 /**
50 * Unsupported method.
51 *
52 * @param mixed $offset
53 *
54 * @return Boolean Always returns false.
55 */
56 public function offsetExists($offset)
57 {
58 return false;
59 }
60
61 /**
62 * Unsupported method.
63 *
64 * This method should not be invoked.
65 *
66 * @param mixed $offset
67 *
68 * @throws BadMethodCallException
69 */
70 public function offsetGet($offset)
71 {
72 throw new BadMethodCallException('Buttons cannot have children.');
73 }
74
75 /**
76 * Unsupported method.
77 *
78 * This method should not be invoked.
79 *
80 * @param mixed $offset
81 * @param mixed $value
82 *
83 * @throws BadMethodCallException
84 */
85 public function offsetSet($offset, $value)
86 {
87 throw new BadMethodCallException('Buttons cannot have children.');
88 }
89
90 /**
91 * Unsupported method.
92 *
93 * This method should not be invoked.
94 *
95 * @param mixed $offset
96 *
97 * @throws BadMethodCallException
98 */
99 public function offsetUnset($offset)
100 {
101 throw new BadMethodCallException('Buttons cannot have children.');
102 }
103
104 /**
105 * {@inheritdoc}
106 */
107 public function setParent(FormInterface $parent = null)
108 {
109 $this->parent = $parent;
110 }
111
112 /**
113 * {@inheritdoc}
114 */
115 public function getParent()
116 {
117 return $this->parent;
118 }
119
120 /**
121 * Unsupported method.
122 *
123 * This method should not be invoked.
124 *
125 * @param int|string|FormInterface $child
126 * @param null $type
127 * @param array $options
128 *
129 * @throws BadMethodCallException
130 */
131 public function add($child, $type = null, array $options = array())
132 {
133 throw new BadMethodCallException('Buttons cannot have children.');
134 }
135
136 /**
137 * Unsupported method.
138 *
139 * This method should not be invoked.
140 *
141 * @param string $name
142 *
143 * @throws BadMethodCallException
144 */
145 public function get($name)
146 {
147 throw new BadMethodCallException('Buttons cannot have children.');
148 }
149
150 /**
151 * Unsupported method.
152 *
153 * @param string $name
154 *
155 * @return Boolean Always returns false.
156 */
157 public function has($name)
158 {
159 return false;
160 }
161
162 /**
163 * Unsupported method.
164 *
165 * This method should not be invoked.
166 *
167 * @param string $name
168 *
169 * @throws BadMethodCallException
170 */
171 public function remove($name)
172 {
173 throw new BadMethodCallException('Buttons cannot have children.');
174 }
175
176 /**
177 * {@inheritdoc}
178 */
179 public function all()
180 {
181 return array();
182 }
183
184 /**
185 * {@inheritdoc}
186 */
187 public function getErrors()
188 {
189 return array();
190 }
191
192 /**
193 * Unsupported method.
194 *
195 * This method should not be invoked.
196 *
197 * @param string $modelData
198 *
199 * @throws BadMethodCallException
200 */
201 public function setData($modelData)
202 {
203 throw new BadMethodCallException('Buttons cannot have data.');
204 }
205
206 /**
207 * Unsupported method.
208 *
209 * @return null Always returns null.
210 */
211 public function getData()
212 {
213 return null;
214 }
215
216 /**
217 * Unsupported method.
218 *
219 * @return null Always returns null.
220 */
221 public function getNormData()
222 {
223 return null;
224 }
225
226 /**
227 * Unsupported method.
228 *
229 * @return null Always returns null.
230 */
231 public function getViewData()
232 {
233 return null;
234 }
235
236 /**
237 * Unsupported method.
238 *
239 * @return array Always returns an empty array.
240 */
241 public function getExtraData()
242 {
243 return array();
244 }
245
246 /**
247 * Returns the button's configuration.
248 *
249 * @return FormConfigInterface The configuration.
250 */
251 public function getConfig()
252 {
253 return $this->config;
254 }
255
256 /**
257 * Returns whether the button is submitted.
258 *
259 * @return Boolean true if the button was submitted.
260 */
261 public function isSubmitted()
262 {
263 return $this->submitted;
264 }
265
266 /**
267 * Returns the name by which the button is identified in forms.
268 *
269 * @return string The name of the button.
270 */
271 public function getName()
272 {
273 return $this->config->getName();
274 }
275
276 /**
277 * Unsupported method.
278 *
279 * @return null Always returns null.
280 */
281 public function getPropertyPath()
282 {
283 return null;
284 }
285
286 /**
287 * Unsupported method.
288 *
289 * @param FormError $error
290 *
291 * @throws BadMethodCallException
292 */
293 public function addError(FormError $error)
294 {
295 throw new BadMethodCallException('Buttons cannot have errors.');
296 }
297
298 /**
299 * Unsupported method.
300 *
301 * @return Boolean Always returns true.
302 */
303 public function isValid()
304 {
305 return true;
306 }
307
308 /**
309 * Unsupported method.
310 *
311 * @return Boolean Always returns false.
312 */
313 public function isRequired()
314 {
315 return false;
316 }
317
318 /**
319 * {@inheritdoc}
320 */
321 public function isDisabled()
322 {
323 return $this->config->getDisabled();
324 }
325
326 /**
327 * Unsupported method.
328 *
329 * @return Boolean Always returns true.
330 */
331 public function isEmpty()
332 {
333 return true;
334 }
335
336 /**
337 * Unsupported method.
338 *
339 * @return Boolean Always returns true.
340 */
341 public function isSynchronized()
342 {
343 return true;
344 }
345
346 /**
347 * Unsupported method.
348 *
349 * @throws BadMethodCallException
350 */
351 public function initialize()
352 {
353 throw new BadMethodCallException('Buttons cannot be initialized. Call initialize() on the root form instead.');
354 }
355
356 /**
357 * Unsupported method.
358 *
359 * @param mixed $request
360 *
361 * @throws BadMethodCallException
362 */
363 public function handleRequest($request = null)
364 {
365 throw new BadMethodCallException('Buttons cannot handle requests. Call handleRequest() on the root form instead.');
366 }
367
368 /**
369 * Submits data to the button.
370 *
371 * @param null|string $submittedData The data.
372 * @param Boolean $clearMissing Not used.
373 *
374 * @return Button The button instance
375 *
376 * @throws Exception\AlreadySubmittedException If the button has already been submitted.
377 */
378 public function submit($submittedData, $clearMissing = true)
379 {
380 if ($this->submitted) {
381 throw new AlreadySubmittedException('A form can only be submitted once');
382 }
383
384 $this->submitted = true;
385
386 return $this;
387 }
388
389 /**
390 * {@inheritdoc}
391 */
392 public function getRoot()
393 {
394 return $this->parent ? $this->parent->getRoot() : $this;
395 }
396
397 /**
398 * {@inheritdoc}
399 */
400 public function isRoot()
401 {
402 return null === $this->parent;
403 }
404
405 /**
406 * {@inheritdoc}
407 */
408 public function createView(FormView $parent = null)
409 {
410 if (null === $parent && $this->parent) {
411 $parent = $this->parent->createView();
412 }
413
414 return $this->config->getType()->createView($this, $parent);
415 }
416
417 /**
418 * Unsupported method.
419 *
420 * @return integer Always returns 0.
421 */
422 public function count()
423 {
424 return 0;
425 }
426
427 /**
428 * Unsupported method.
429 *
430 * @return \EmptyIterator Always returns an empty iterator.
431 */
432 public function getIterator()
433 {
434 return new \EmptyIterator();
435 }
436}