Source of file Button.php
Size: 8,621 Bytes - Last Modified: 2013-07-17T08:22:21+02:00
/home/theseer/Downloads/Symfony/vendor/symfony/symfony/src/Symfony/Component/Form/Button.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 | <?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Form; use Symfony\Component\Form\Exception\AlreadySubmittedException; use Symfony\Component\Form\Exception\BadMethodCallException; /** * A form button. * * @author Bernhard Schussek <bschussek@gmail.com> */ class Button implements \IteratorAggregate, FormInterface { /** * @var FormInterface */ private $parent; /** * @var FormConfigInterface */ private $config; /** * @var Boolean */ private $submitted = false; /** * Creates a new button from a form configuration. * * @param FormConfigInterface $config The button's configuration. */ public function __construct(FormConfigInterface $config) { $this->config = $config; } /** * Unsupported method. * * @param mixed $offset * * @return Boolean Always returns false. */ public function offsetExists($offset) { return false; } /** * Unsupported method. * * This method should not be invoked. * * @param mixed $offset * * @throws BadMethodCallException */ public function offsetGet($offset) { throw new BadMethodCallException('Buttons cannot have children.'); } /** * Unsupported method. * * This method should not be invoked. * * @param mixed $offset * @param mixed $value * * @throws BadMethodCallException */ public function offsetSet($offset, $value) { throw new BadMethodCallException('Buttons cannot have children.'); } /** * Unsupported method. * * This method should not be invoked. * * @param mixed $offset * * @throws BadMethodCallException */ public function offsetUnset($offset) { throw new BadMethodCallException('Buttons cannot have children.'); } /** * {@inheritdoc} */ public function setParent(FormInterface $parent = null) { $this->parent = $parent; } /** * {@inheritdoc} */ public function getParent() { return $this->parent; } /** * Unsupported method. * * This method should not be invoked. * * @param int|string|FormInterface $child * @param null $type * @param array $options * * @throws BadMethodCallException */ public function add($child, $type = null, array $options = array()) { throw new BadMethodCallException('Buttons cannot have children.'); } /** * Unsupported method. * * This method should not be invoked. * * @param string $name * * @throws BadMethodCallException */ public function get($name) { throw new BadMethodCallException('Buttons cannot have children.'); } /** * Unsupported method. * * @param string $name * * @return Boolean Always returns false. */ public function has($name) { return false; } /** * Unsupported method. * * This method should not be invoked. * * @param string $name * * @throws BadMethodCallException */ public function remove($name) { throw new BadMethodCallException('Buttons cannot have children.'); } /** * {@inheritdoc} */ public function all() { return array(); } /** * {@inheritdoc} */ public function getErrors() { return array(); } /** * Unsupported method. * * This method should not be invoked. * * @param string $modelData * * @throws BadMethodCallException */ public function setData($modelData) { throw new BadMethodCallException('Buttons cannot have data.'); } /** * Unsupported method. * * @return null Always returns null. */ public function getData() { return null; } /** * Unsupported method. * * @return null Always returns null. */ public function getNormData() { return null; } /** * Unsupported method. * * @return null Always returns null. */ public function getViewData() { return null; } /** * Unsupported method. * * @return array Always returns an empty array. */ public function getExtraData() { return array(); } /** * Returns the button's configuration. * * @return FormConfigInterface The configuration. */ public function getConfig() { return $this->config; } /** * Returns whether the button is submitted. * * @return Boolean true if the button was submitted. */ public function isSubmitted() { return $this->submitted; } /** * Returns the name by which the button is identified in forms. * * @return string The name of the button. */ public function getName() { return $this->config->getName(); } /** * Unsupported method. * * @return null Always returns null. */ public function getPropertyPath() { return null; } /** * Unsupported method. * * @param FormError $error * * @throws BadMethodCallException */ public function addError(FormError $error) { throw new BadMethodCallException('Buttons cannot have errors.'); } /** * Unsupported method. * * @return Boolean Always returns true. */ public function isValid() { return true; } /** * Unsupported method. * * @return Boolean Always returns false. */ public function isRequired() { return false; } /** * {@inheritdoc} */ public function isDisabled() { return $this->config->getDisabled(); } /** * Unsupported method. * * @return Boolean Always returns true. */ public function isEmpty() { return true; } /** * Unsupported method. * * @return Boolean Always returns true. */ public function isSynchronized() { return true; } /** * Unsupported method. * * @throws BadMethodCallException */ public function initialize() { throw new BadMethodCallException('Buttons cannot be initialized. Call initialize() on the root form instead.'); } /** * Unsupported method. * * @param mixed $request * * @throws BadMethodCallException */ public function handleRequest($request = null) { throw new BadMethodCallException('Buttons cannot handle requests. Call handleRequest() on the root form instead.'); } /** * Submits data to the button. * * @param null|string $submittedData The data. * @param Boolean $clearMissing Not used. * * @return Button The button instance * * @throws Exception\AlreadySubmittedException If the button has already been submitted. */ public function submit($submittedData, $clearMissing = true) { if ($this->submitted) { throw new AlreadySubmittedException('A form can only be submitted once'); } $this->submitted = true; return $this; } /** * {@inheritdoc} */ public function getRoot() { return $this->parent ? $this->parent->getRoot() : $this; } /** * {@inheritdoc} */ public function isRoot() { return null === $this->parent; } /** * {@inheritdoc} */ public function createView(FormView $parent = null) { if (null === $parent && $this->parent) { $parent = $this->parent->createView(); } return $this->config->getType()->createView($this, $parent); } /** * Unsupported method. * * @return integer Always returns 0. */ public function count() { return 0; } /** * Unsupported method. * * @return \EmptyIterator Always returns an empty iterator. */ public function getIterator() { return new \EmptyIterator(); } } |