laravel-6 support
This commit is contained in:
@@ -14,7 +14,7 @@ namespace Symfony\Component\DomCrawler\Field;
|
||||
/**
|
||||
* ChoiceFormField represents a choice form field.
|
||||
*
|
||||
* It is constructed from a HTML select tag, or a HTML checkbox, or radio inputs.
|
||||
* It is constructed from an HTML select tag, or an HTML checkbox, or radio inputs.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
@@ -45,7 +45,7 @@ class ChoiceFormField extends FormField
|
||||
public function hasValue()
|
||||
{
|
||||
// don't send a value for unchecked checkboxes
|
||||
if (in_array($this->type, array('checkbox', 'radio')) && null === $this->value) {
|
||||
if (\in_array($this->type, ['checkbox', 'radio']) && null === $this->value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ class ChoiceFormField extends FormField
|
||||
/**
|
||||
* Sets the value of the field.
|
||||
*
|
||||
* @param string $value The value of the field
|
||||
* @param string|array $value The value of the field
|
||||
*/
|
||||
public function select($value)
|
||||
{
|
||||
@@ -97,14 +97,14 @@ class ChoiceFormField extends FormField
|
||||
}
|
||||
|
||||
/**
|
||||
* Ticks a checkbox.
|
||||
* Unticks a checkbox.
|
||||
*
|
||||
* @throws \LogicException When the type provided is not correct
|
||||
*/
|
||||
public function untick()
|
||||
{
|
||||
if ('checkbox' !== $this->type) {
|
||||
throw new \LogicException(sprintf('You cannot tick "%s" as it is not a checkbox (%s).', $this->name, $this->type));
|
||||
throw new \LogicException(sprintf('You cannot untick "%s" as it is not a checkbox (%s).', $this->name, $this->type));
|
||||
}
|
||||
|
||||
$this->setValue(false);
|
||||
@@ -113,7 +113,7 @@ class ChoiceFormField extends FormField
|
||||
/**
|
||||
* Sets the value of the field.
|
||||
*
|
||||
* @param string $value The value of the field
|
||||
* @param string|array|bool $value The value of the field
|
||||
*
|
||||
* @throws \InvalidArgumentException When value type provided is not correct
|
||||
*/
|
||||
@@ -126,25 +126,25 @@ class ChoiceFormField extends FormField
|
||||
// check
|
||||
$this->value = $this->options[0]['value'];
|
||||
} else {
|
||||
if (is_array($value)) {
|
||||
if (\is_array($value)) {
|
||||
if (!$this->multiple) {
|
||||
throw new \InvalidArgumentException(sprintf('The value for "%s" cannot be an array.', $this->name));
|
||||
}
|
||||
|
||||
foreach ($value as $v) {
|
||||
if (!$this->containsOption($v, $this->options)) {
|
||||
throw new \InvalidArgumentException(sprintf('Input "%s" cannot take "%s" as a value (possible values: %s).', $this->name, $v, implode(', ', $this->availableOptionValues())));
|
||||
throw new \InvalidArgumentException(sprintf('Input "%s" cannot take "%s" as a value (possible values: "%s").', $this->name, $v, implode('", "', $this->availableOptionValues())));
|
||||
}
|
||||
}
|
||||
} elseif (!$this->containsOption($value, $this->options)) {
|
||||
throw new \InvalidArgumentException(sprintf('Input "%s" cannot take "%s" as a value (possible values: %s).', $this->name, $value, implode(', ', $this->availableOptionValues())));
|
||||
throw new \InvalidArgumentException(sprintf('Input "%s" cannot take "%s" as a value (possible values: "%s").', $this->name, $value, implode('", "', $this->availableOptionValues())));
|
||||
}
|
||||
|
||||
if ($this->multiple) {
|
||||
$value = (array) $value;
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
if (\is_array($value)) {
|
||||
$this->value = $value;
|
||||
} else {
|
||||
parent::setValue($value);
|
||||
@@ -155,8 +155,6 @@ class ChoiceFormField extends FormField
|
||||
/**
|
||||
* Adds a choice to the current ones.
|
||||
*
|
||||
* @param \DOMElement $node
|
||||
*
|
||||
* @throws \LogicException When choice provided is not multiple nor radio
|
||||
*
|
||||
* @internal
|
||||
@@ -207,11 +205,11 @@ class ChoiceFormField extends FormField
|
||||
}
|
||||
|
||||
if ('input' === $this->node->nodeName && 'checkbox' !== strtolower($this->node->getAttribute('type')) && 'radio' !== strtolower($this->node->getAttribute('type'))) {
|
||||
throw new \LogicException(sprintf('A ChoiceFormField can only be created from an input tag with a type of checkbox or radio (given type is %s).', $this->node->getAttribute('type')));
|
||||
throw new \LogicException(sprintf('A ChoiceFormField can only be created from an input tag with a type of checkbox or radio (given type is "%s").', $this->node->getAttribute('type')));
|
||||
}
|
||||
|
||||
$this->value = null;
|
||||
$this->options = array();
|
||||
$this->options = [];
|
||||
$this->multiple = false;
|
||||
|
||||
if ('input' == $this->node->nodeName) {
|
||||
@@ -226,7 +224,7 @@ class ChoiceFormField extends FormField
|
||||
$this->type = 'select';
|
||||
if ($this->node->hasAttribute('multiple')) {
|
||||
$this->multiple = true;
|
||||
$this->value = array();
|
||||
$this->value = [];
|
||||
$this->name = str_replace('[]', '', $this->name);
|
||||
}
|
||||
|
||||
@@ -254,14 +252,10 @@ class ChoiceFormField extends FormField
|
||||
|
||||
/**
|
||||
* Returns option value with associated disabled flag.
|
||||
*
|
||||
* @param \DOMElement $node
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function buildOptionValue(\DOMElement $node)
|
||||
private function buildOptionValue(\DOMElement $node): array
|
||||
{
|
||||
$option = array();
|
||||
$option = [];
|
||||
|
||||
$defaultDefaultValue = 'select' === $this->node->nodeName ? '' : 'on';
|
||||
$defaultValue = (isset($node->nodeValue) && !empty($node->nodeValue)) ? $node->nodeValue : $defaultDefaultValue;
|
||||
@@ -301,7 +295,7 @@ class ChoiceFormField extends FormField
|
||||
*/
|
||||
public function availableOptionValues()
|
||||
{
|
||||
$values = array();
|
||||
$values = [];
|
||||
|
||||
foreach ($this->options as $option) {
|
||||
$values[] = $option['value'];
|
||||
|
Reference in New Issue
Block a user