Added the Porter Stemmer module to improve searches. This doesn't deal with some...
[yaffs-website] / vendor / symfony / dom-crawler / Field / FormField.php
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
12 namespace Symfony\Component\DomCrawler\Field;
13
14 /**
15  * FormField is the abstract class for all form fields.
16  *
17  * @author Fabien Potencier <fabien@symfony.com>
18  */
19 abstract class FormField
20 {
21     /**
22      * @var \DOMElement
23      */
24     protected $node;
25     /**
26      * @var string
27      */
28     protected $name;
29     /**
30      * @var string
31      */
32     protected $value;
33     /**
34      * @var \DOMDocument
35      */
36     protected $document;
37     /**
38      * @var \DOMXPath
39      */
40     protected $xpath;
41     /**
42      * @var bool
43      */
44     protected $disabled;
45
46     /**
47      * @param \DOMElement $node The node associated with this field
48      */
49     public function __construct(\DOMElement $node)
50     {
51         $this->node = $node;
52         $this->name = $node->getAttribute('name');
53         $this->xpath = new \DOMXPath($node->ownerDocument);
54
55         $this->initialize();
56     }
57
58     /**
59      * Returns the label tag associated to the field or null if none.
60      *
61      * @return \DOMElement|null
62      */
63     public function getLabel()
64     {
65         $xpath = new \DOMXPath($this->node->ownerDocument);
66
67         if ($this->node->hasAttribute('id')) {
68             $labels = $xpath->query(sprintf('descendant::label[@for="%s"]', $this->node->getAttribute('id')));
69             if ($labels->length > 0) {
70                 return $labels->item(0);
71             }
72         }
73
74         $labels = $xpath->query('ancestor::label[1]', $this->node);
75         if ($labels->length > 0) {
76             return $labels->item(0);
77         }
78     }
79
80     /**
81      * Returns the name of the field.
82      *
83      * @return string The name of the field
84      */
85     public function getName()
86     {
87         return $this->name;
88     }
89
90     /**
91      * Gets the value of the field.
92      *
93      * @return string|array The value of the field
94      */
95     public function getValue()
96     {
97         return $this->value;
98     }
99
100     /**
101      * Sets the value of the field.
102      *
103      * @param string $value The value of the field
104      */
105     public function setValue($value)
106     {
107         $this->value = (string) $value;
108     }
109
110     /**
111      * Returns true if the field should be included in the submitted values.
112      *
113      * @return bool true if the field should be included in the submitted values, false otherwise
114      */
115     public function hasValue()
116     {
117         return true;
118     }
119
120     /**
121      * Check if the current field is disabled.
122      *
123      * @return bool
124      */
125     public function isDisabled()
126     {
127         return $this->node->hasAttribute('disabled');
128     }
129
130     /**
131      * Initializes the form field.
132      */
133     abstract protected function initialize();
134 }