vendor/symfony/src/Symfony/Component/DomCrawler/Field/FormField.php
changeset 0 7f95f8617b0b
equal deleted inserted replaced
-1:000000000000 0:7f95f8617b0b
       
     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     protected $node;
       
    22     protected $name;
       
    23     protected $value;
       
    24     protected $document;
       
    25     protected $xpath;
       
    26     protected $disabled;
       
    27 
       
    28     /**
       
    29      * Constructor.
       
    30      *
       
    31      * @param \DOMNode $node The node associated with this field
       
    32      */
       
    33     public function __construct(\DOMNode $node)
       
    34     {
       
    35         $this->node = $node;
       
    36         $this->name = $node->getAttribute('name');
       
    37 
       
    38         $this->document = new \DOMDocument('1.0', 'UTF-8');
       
    39         $this->node = $this->document->importNode($this->node, true);
       
    40 
       
    41         $root = $this->document->appendChild($this->document->createElement('_root'));
       
    42         $root->appendChild($this->node);
       
    43         $this->xpath = new \DOMXPath($this->document);
       
    44 
       
    45         $this->initialize();
       
    46     }
       
    47 
       
    48     /**
       
    49      * Returns the name of the field.
       
    50      *
       
    51      * @return string The name of the field
       
    52      */
       
    53     public function getName()
       
    54     {
       
    55         return $this->name;
       
    56     }
       
    57 
       
    58     /**
       
    59      * Gets the value of the field.
       
    60      *
       
    61      * @return string|array The value of the field
       
    62      */
       
    63     public function getValue()
       
    64     {
       
    65         return $this->value;
       
    66     }
       
    67 
       
    68     /**
       
    69      * Sets the value of the field.
       
    70      *
       
    71      * @param string $value The value of the field
       
    72      *
       
    73      * @api
       
    74      */
       
    75     public function setValue($value)
       
    76     {
       
    77         $this->value = (string) $value;
       
    78     }
       
    79 
       
    80     /**
       
    81      * Returns true if the field should be included in the submitted values.
       
    82      *
       
    83      * @return Boolean true if the field should be included in the submitted values, false otherwise
       
    84      */
       
    85     public function hasValue()
       
    86     {
       
    87         return true;
       
    88     }
       
    89 
       
    90     public function isDisabled()
       
    91     {
       
    92         return $this->node->hasAttribute('disabled');
       
    93     }
       
    94 
       
    95     /**
       
    96      * Initializes the form field.
       
    97      */
       
    98     abstract protected function initialize();
       
    99 }