123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- namespace Symfony\Component\DomCrawler\Field;
- abstract class FormField
- {
-
- protected $node;
-
- protected $name;
-
- protected $value;
-
- protected $document;
-
- protected $xpath;
-
- protected $disabled;
-
- public function __construct(\DOMElement $node)
- {
- $this->node = $node;
- $this->name = $node->getAttribute('name');
- $this->xpath = new \DOMXPath($node->ownerDocument);
- $this->initialize();
- }
-
- public function getLabel()
- {
- $xpath = new \DOMXPath($this->node->ownerDocument);
- if ($this->node->hasAttribute('id')) {
- $labels = $xpath->query(sprintf('descendant::label[@for="%s"]', $this->node->getAttribute('id')));
- if ($labels->length > 0) {
- return $labels->item(0);
- }
- }
- $labels = $xpath->query('ancestor::label[1]', $this->node);
- if ($labels->length > 0) {
- return $labels->item(0);
- }
- }
-
- public function getName()
- {
- return $this->name;
- }
-
- public function getValue()
- {
- return $this->value;
- }
-
- public function setValue($value)
- {
- $this->value = (string) $value;
- }
-
- public function hasValue()
- {
- return true;
- }
-
- public function isDisabled()
- {
- return $this->node->hasAttribute('disabled');
- }
-
- abstract protected function initialize();
- }
|