Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\DomCrawler\Field; Chris@0: Chris@0: /** Chris@0: * InputFormField represents an input form field (an HTML input tag). Chris@0: * Chris@0: * For inputs with type of file, checkbox, or radio, there are other more Chris@0: * specialized classes (cf. FileFormField and ChoiceFormField). Chris@0: * Chris@0: * @author Fabien Potencier Chris@0: */ Chris@0: class InputFormField extends FormField Chris@0: { Chris@0: /** Chris@0: * Initializes the form field. Chris@0: * Chris@0: * @throws \LogicException When node type is incorrect Chris@0: */ Chris@0: protected function initialize() Chris@0: { Chris@0: if ('input' !== $this->node->nodeName && 'button' !== $this->node->nodeName) { Chris@0: throw new \LogicException(sprintf('An InputFormField can only be created from an input or button tag (%s given).', $this->node->nodeName)); Chris@0: } Chris@0: Chris@13: $type = strtolower($this->node->getAttribute('type')); Chris@13: if ('checkbox' === $type) { Chris@0: throw new \LogicException('Checkboxes should be instances of ChoiceFormField.'); Chris@0: } Chris@0: Chris@13: if ('file' === $type) { Chris@0: throw new \LogicException('File inputs should be instances of FileFormField.'); Chris@0: } Chris@0: Chris@0: $this->value = $this->node->getAttribute('value'); Chris@0: } Chris@0: }