Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/dom-crawler/Form.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 5fb285c0d0e3 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
85 * | 85 * |
86 * @return array An array of field values | 86 * @return array An array of field values |
87 */ | 87 */ |
88 public function getValues() | 88 public function getValues() |
89 { | 89 { |
90 $values = array(); | 90 $values = []; |
91 foreach ($this->fields->all() as $name => $field) { | 91 foreach ($this->fields->all() as $name => $field) { |
92 if ($field->isDisabled()) { | 92 if ($field->isDisabled()) { |
93 continue; | 93 continue; |
94 } | 94 } |
95 | 95 |
106 * | 106 * |
107 * @return array An array of file field values | 107 * @return array An array of file field values |
108 */ | 108 */ |
109 public function getFiles() | 109 public function getFiles() |
110 { | 110 { |
111 if (!in_array($this->getMethod(), array('POST', 'PUT', 'DELETE', 'PATCH'))) { | 111 if (!\in_array($this->getMethod(), ['POST', 'PUT', 'DELETE', 'PATCH'])) { |
112 return array(); | 112 return []; |
113 } | 113 } |
114 | 114 |
115 $files = array(); | 115 $files = []; |
116 | 116 |
117 foreach ($this->fields->all() as $name => $field) { | 117 foreach ($this->fields->all() as $name => $field) { |
118 if ($field->isDisabled()) { | 118 if ($field->isDisabled()) { |
119 continue; | 119 continue; |
120 } | 120 } |
135 * | 135 * |
136 * @return array An array of field values | 136 * @return array An array of field values |
137 */ | 137 */ |
138 public function getPhpValues() | 138 public function getPhpValues() |
139 { | 139 { |
140 $values = array(); | 140 $values = []; |
141 foreach ($this->getValues() as $name => $value) { | 141 foreach ($this->getValues() as $name => $value) { |
142 $qs = http_build_query(array($name => $value), '', '&'); | 142 $qs = http_build_query([$name => $value], '', '&'); |
143 if (!empty($qs)) { | 143 if (!empty($qs)) { |
144 parse_str($qs, $expandedValue); | 144 parse_str($qs, $expandedValue); |
145 $varName = substr($name, 0, strlen(key($expandedValue))); | 145 $varName = substr($name, 0, \strlen(key($expandedValue))); |
146 $values = array_replace_recursive($values, array($varName => current($expandedValue))); | 146 $values = array_replace_recursive($values, [$varName => current($expandedValue)]); |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 return $values; | 150 return $values; |
151 } | 151 } |
162 * | 162 * |
163 * @return array An array of file field values | 163 * @return array An array of file field values |
164 */ | 164 */ |
165 public function getPhpFiles() | 165 public function getPhpFiles() |
166 { | 166 { |
167 $values = array(); | 167 $values = []; |
168 foreach ($this->getFiles() as $name => $value) { | 168 foreach ($this->getFiles() as $name => $value) { |
169 $qs = http_build_query(array($name => $value), '', '&'); | 169 $qs = http_build_query([$name => $value], '', '&'); |
170 if (!empty($qs)) { | 170 if (!empty($qs)) { |
171 parse_str($qs, $expandedValue); | 171 parse_str($qs, $expandedValue); |
172 $varName = substr($name, 0, strlen(key($expandedValue))); | 172 $varName = substr($name, 0, \strlen(key($expandedValue))); |
173 | 173 |
174 array_walk_recursive( | 174 array_walk_recursive( |
175 $expandedValue, | 175 $expandedValue, |
176 function (&$value, $key) { | 176 function (&$value, $key) { |
177 if (ctype_digit($value) && ('size' === $key || 'error' === $key)) { | 177 if (ctype_digit($value) && ('size' === $key || 'error' === $key)) { |
180 } | 180 } |
181 ); | 181 ); |
182 | 182 |
183 reset($expandedValue); | 183 reset($expandedValue); |
184 | 184 |
185 $values = array_replace_recursive($values, array($varName => current($expandedValue))); | 185 $values = array_replace_recursive($values, [$varName => current($expandedValue)]); |
186 } | 186 } |
187 } | 187 } |
188 | 188 |
189 return $values; | 189 return $values; |
190 } | 190 } |
200 */ | 200 */ |
201 public function getUri() | 201 public function getUri() |
202 { | 202 { |
203 $uri = parent::getUri(); | 203 $uri = parent::getUri(); |
204 | 204 |
205 if (!in_array($this->getMethod(), array('POST', 'PUT', 'DELETE', 'PATCH'))) { | 205 if (!\in_array($this->getMethod(), ['POST', 'PUT', 'DELETE', 'PATCH'])) { |
206 $query = parse_url($uri, PHP_URL_QUERY); | 206 $query = parse_url($uri, PHP_URL_QUERY); |
207 $currentParameters = array(); | 207 $currentParameters = []; |
208 if ($query) { | 208 if ($query) { |
209 parse_str($query, $currentParameters); | 209 parse_str($query, $currentParameters); |
210 } | 210 } |
211 | 211 |
212 $queryString = http_build_query(array_merge($currentParameters, $this->getValues()), '', '&'); | 212 $queryString = http_build_query(array_merge($currentParameters, $this->getValues()), '', '&'); |
377 * @throws \LogicException If given node is not a button or input or does not have a form ancestor | 377 * @throws \LogicException If given node is not a button or input or does not have a form ancestor |
378 */ | 378 */ |
379 protected function setNode(\DOMElement $node) | 379 protected function setNode(\DOMElement $node) |
380 { | 380 { |
381 $this->button = $node; | 381 $this->button = $node; |
382 if ('button' === $node->nodeName || ('input' === $node->nodeName && in_array(strtolower($node->getAttribute('type')), array('submit', 'button', 'image')))) { | 382 if ('button' === $node->nodeName || ('input' === $node->nodeName && \in_array(strtolower($node->getAttribute('type')), ['submit', 'button', 'image']))) { |
383 if ($node->hasAttribute('form')) { | 383 if ($node->hasAttribute('form')) { |
384 // if the node has the HTML5-compliant 'form' attribute, use it | 384 // if the node has the HTML5-compliant 'form' attribute, use it |
385 $formId = $node->getAttribute('form'); | 385 $formId = $node->getAttribute('form'); |
386 $form = $node->ownerDocument->getElementById($formId); | 386 $form = $node->ownerDocument->getElementById($formId); |
387 if (null === $form) { | 387 if (null === $form) { |
441 // find form elements corresponding to the current form | 441 // find form elements corresponding to the current form |
442 if ($this->node->hasAttribute('id')) { | 442 if ($this->node->hasAttribute('id')) { |
443 // corresponding elements are either descendants or have a matching HTML5 form attribute | 443 // corresponding elements are either descendants or have a matching HTML5 form attribute |
444 $formId = Crawler::xpathLiteral($this->node->getAttribute('id')); | 444 $formId = Crawler::xpathLiteral($this->node->getAttribute('id')); |
445 | 445 |
446 $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)); | 446 $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)] )[not(ancestor::template)]', $formId)); |
447 foreach ($fieldNodes as $node) { | 447 foreach ($fieldNodes as $node) { |
448 $this->addField($node); | 448 $this->addField($node); |
449 } | 449 } |
450 } else { | 450 } else { |
451 // do the xpath query with $this->node as the context node, to only find descendant elements | 451 // do the xpath query with $this->node as the context node, to only find descendant elements |
452 // however, descendant elements with form attribute are not part of this form | 452 // however, descendant elements with form attribute are not part of this form |
453 $fieldNodes = $xpath->query('descendant::input[not(@form)] | descendant::button[not(@form)] | descendant::textarea[not(@form)] | descendant::select[not(@form)]', $this->node); | 453 $fieldNodes = $xpath->query('( descendant::input[not(@form)] | descendant::button[not(@form)] | descendant::textarea[not(@form)] | descendant::select[not(@form)] )[not(ancestor::template)]', $this->node); |
454 foreach ($fieldNodes as $node) { | 454 foreach ($fieldNodes as $node) { |
455 $this->addField($node); | 455 $this->addField($node); |
456 } | 456 } |
457 } | 457 } |
458 | 458 |
478 } else { | 478 } else { |
479 $this->set(new Field\ChoiceFormField($node)); | 479 $this->set(new Field\ChoiceFormField($node)); |
480 } | 480 } |
481 } elseif ('input' == $nodeName && 'file' == strtolower($node->getAttribute('type'))) { | 481 } elseif ('input' == $nodeName && 'file' == strtolower($node->getAttribute('type'))) { |
482 $this->set(new Field\FileFormField($node)); | 482 $this->set(new Field\FileFormField($node)); |
483 } elseif ('input' == $nodeName && !in_array(strtolower($node->getAttribute('type')), array('submit', 'button', 'image'))) { | 483 } elseif ('input' == $nodeName && !\in_array(strtolower($node->getAttribute('type')), ['submit', 'button', 'image'])) { |
484 $this->set(new Field\InputFormField($node)); | 484 $this->set(new Field\InputFormField($node)); |
485 } elseif ('textarea' == $nodeName) { | 485 } elseif ('textarea' == $nodeName) { |
486 $this->set(new Field\TextareaFormField($node)); | 486 $this->set(new Field\TextareaFormField($node)); |
487 } | 487 } |
488 } | 488 } |