X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=vendor%2Fsymfony%2Fdom-crawler%2FForm.php;h=8584e016b0d7e61ca7b43a3a65be938695a0907b;hb=refs%2Fheads%2Fmaster;hp=bad1b34935d04d400975bfe85c359a371e86191f;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/vendor/symfony/dom-crawler/Form.php b/vendor/symfony/dom-crawler/Form.php index bad1b3493..8584e016b 100644 --- a/vendor/symfony/dom-crawler/Form.php +++ b/vendor/symfony/dom-crawler/Form.php @@ -37,8 +37,6 @@ class Form extends Link implements \ArrayAccess private $baseHref; /** - * Constructor. - * * @param \DOMElement $node A \DOMElement instance * @param string $currentUri The URI of the page where the form is embedded * @param string $method The method to use for the link (if null, it defaults to the method defined by the form) @@ -110,7 +108,7 @@ class Form extends Link implements \ArrayAccess */ public function getFiles() { - if (!in_array($this->getMethod(), array('POST', 'PUT', 'DELETE', 'PATCH'))) { + if (!\in_array($this->getMethod(), array('POST', 'PUT', 'DELETE', 'PATCH'))) { return array(); } @@ -144,7 +142,7 @@ class Form extends Link implements \ArrayAccess $qs = http_build_query(array($name => $value), '', '&'); if (!empty($qs)) { parse_str($qs, $expandedValue); - $varName = substr($name, 0, strlen(key($expandedValue))); + $varName = substr($name, 0, \strlen(key($expandedValue))); $values = array_replace_recursive($values, array($varName => current($expandedValue))); } } @@ -171,7 +169,19 @@ class Form extends Link implements \ArrayAccess $qs = http_build_query(array($name => $value), '', '&'); if (!empty($qs)) { parse_str($qs, $expandedValue); - $varName = substr($name, 0, strlen(key($expandedValue))); + $varName = substr($name, 0, \strlen(key($expandedValue))); + + array_walk_recursive( + $expandedValue, + function (&$value, $key) { + if (ctype_digit($value) && ('size' === $key || 'error' === $key)) { + $value = (int) $value; + } + } + ); + + reset($expandedValue); + $values = array_replace_recursive($values, array($varName => current($expandedValue))); } } @@ -192,14 +202,14 @@ class Form extends Link implements \ArrayAccess { $uri = parent::getUri(); - if (!in_array($this->getMethod(), array('POST', 'PUT', 'DELETE', 'PATCH'))) { + if (!\in_array($this->getMethod(), array('POST', 'PUT', 'DELETE', 'PATCH'))) { $query = parse_url($uri, PHP_URL_QUERY); $currentParameters = array(); if ($query) { parse_str($query, $currentParameters); } - $queryString = http_build_query(array_merge($currentParameters, $this->getValues()), null, '&'); + $queryString = http_build_query(array_merge($currentParameters, $this->getValues()), '', '&'); $pos = strpos($uri, '?'); $base = false === $pos ? $uri : substr($uri, 0, $pos); @@ -211,6 +221,11 @@ class Form extends Link implements \ArrayAccess protected function getRawUri() { + // If the form was created from a button rather than the form node, check for HTML5 action overrides + if ($this->button !== $this->node && $this->button->getAttribute('formaction')) { + return $this->button->getAttribute('formaction'); + } + return $this->node->getAttribute('action'); } @@ -227,6 +242,11 @@ class Form extends Link implements \ArrayAccess return $this->method; } + // If the form was created from a button rather than the form node, check for HTML5 method override + if ($this->button !== $this->node && $this->button->getAttribute('formmethod')) { + return strtoupper($this->button->getAttribute('formmethod')); + } + return $this->node->getAttribute('method') ? strtoupper($this->node->getAttribute('method')) : 'GET'; } @@ -268,8 +288,6 @@ class Form extends Link implements \ArrayAccess /** * Sets a named field. - * - * @param FormField $field The field */ public function set(FormField $field) { @@ -356,14 +374,12 @@ class Form extends Link implements \ArrayAccess * * Expects a 'submit' button \DOMElement and finds the corresponding form element, or the form element itself. * - * @param \DOMElement $node A \DOMElement instance - * * @throws \LogicException If given node is not a button or input or does not have a form ancestor */ protected function setNode(\DOMElement $node) { $this->button = $node; - if ('button' === $node->nodeName || ('input' === $node->nodeName && in_array(strtolower($node->getAttribute('type')), array('submit', 'button', 'image')))) { + if ('button' === $node->nodeName || ('input' === $node->nodeName && \in_array(strtolower($node->getAttribute('type')), array('submit', 'button', 'image')))) { if ($node->hasAttribute('form')) { // if the node has the HTML5-compliant 'form' attribute, use it $formId = $node->getAttribute('form'); @@ -427,7 +443,7 @@ class Form extends Link implements \ArrayAccess // corresponding elements are either descendants or have a matching HTML5 form attribute $formId = Crawler::xpathLiteral($this->node->getAttribute('id')); - $fieldNodes = $xpath->query(sprintf('descendant::input[@form=%s] | descendant::button[@form=%s] | descendant::textarea[@form=%s] | descendant::select[@form=%s] | //form[@id=%s]//input[not(@form)] | //form[@id=%s]//button[not(@form)] | //form[@id=%s]//textarea[not(@form)] | //form[@id=%s]//select[not(@form)]', $formId, $formId, $formId, $formId, $formId, $formId, $formId, $formId)); + $fieldNodes = $xpath->query(sprintf('descendant::input[@form=%s] | descendant::button[@form=%1$s] | descendant::textarea[@form=%1$s] | descendant::select[@form=%1$s] | //form[@id=%1$s]//input[not(@form)] | //form[@id=%1$s]//button[not(@form)] | //form[@id=%1$s]//textarea[not(@form)] | //form[@id=%1$s]//select[not(@form)]', $formId)); foreach ($fieldNodes as $node) { $this->addField($node); } @@ -464,7 +480,7 @@ class Form extends Link implements \ArrayAccess } } elseif ('input' == $nodeName && 'file' == strtolower($node->getAttribute('type'))) { $this->set(new Field\FileFormField($node)); - } elseif ('input' == $nodeName && !in_array(strtolower($node->getAttribute('type')), array('submit', 'button', 'image'))) { + } elseif ('input' == $nodeName && !\in_array(strtolower($node->getAttribute('type')), array('submit', 'button', 'image'))) { $this->set(new Field\InputFormField($node)); } elseif ('textarea' == $nodeName) { $this->set(new Field\TextareaFormField($node));