InputFormField.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\DomCrawler\Field;
  11. /**
  12. * InputFormField represents an input form field (an HTML input tag).
  13. *
  14. * For inputs with type of file, checkbox, or radio, there are other more
  15. * specialized classes (cf. FileFormField and ChoiceFormField).
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. *
  19. * @api
  20. */
  21. class InputFormField extends FormField
  22. {
  23. /**
  24. * Initializes the form field.
  25. *
  26. * @throws \LogicException When node type is incorrect
  27. */
  28. protected function initialize()
  29. {
  30. if ('input' != $this->node->nodeName && 'button' != $this->node->nodeName) {
  31. throw new \LogicException(sprintf('An InputFormField can only be created from an input or button tag (%s given).', $this->node->nodeName));
  32. }
  33. if ('checkbox' == $this->node->getAttribute('type')) {
  34. throw new \LogicException('Checkboxes should be instances of ChoiceFormField.');
  35. }
  36. if ('file' == $this->node->getAttribute('type')) {
  37. throw new \LogicException('File inputs should be instances of FileFormField.');
  38. }
  39. $this->value = $this->node->getAttribute('value');
  40. }
  41. }