package and depencies
This commit is contained in:
@@ -20,29 +20,17 @@ namespace Symfony\Component\DomCrawler\Field;
|
||||
*/
|
||||
class ChoiceFormField extends FormField
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $type;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $multiple;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $options;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $validationDisabled = false;
|
||||
private string $type;
|
||||
private bool $multiple;
|
||||
private array $options;
|
||||
private bool $validationDisabled = false;
|
||||
|
||||
/**
|
||||
* Returns true if the field should be included in the submitted values.
|
||||
*
|
||||
* @return bool true if the field should be included in the submitted values, false otherwise
|
||||
*/
|
||||
public function hasValue()
|
||||
public function hasValue(): bool
|
||||
{
|
||||
// don't send a value for unchecked checkboxes
|
||||
if (\in_array($this->type, ['checkbox', 'radio']) && null === $this->value) {
|
||||
@@ -54,10 +42,8 @@ class ChoiceFormField extends FormField
|
||||
|
||||
/**
|
||||
* Check if the current selected option is disabled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDisabled()
|
||||
public function isDisabled(): bool
|
||||
{
|
||||
if (parent::isDisabled() && 'select' === $this->type) {
|
||||
return true;
|
||||
@@ -74,10 +60,8 @@ class ChoiceFormField extends FormField
|
||||
|
||||
/**
|
||||
* Sets the value of the field.
|
||||
*
|
||||
* @param string|array $value The value of the field
|
||||
*/
|
||||
public function select($value)
|
||||
public function select(string|array|bool $value)
|
||||
{
|
||||
$this->setValue($value);
|
||||
}
|
||||
@@ -113,11 +97,9 @@ class ChoiceFormField extends FormField
|
||||
/**
|
||||
* Sets the value of the field.
|
||||
*
|
||||
* @param string|array|bool|null $value The value of the field
|
||||
*
|
||||
* @throws \InvalidArgumentException When value type provided is not correct
|
||||
*/
|
||||
public function setValue($value)
|
||||
public function setValue(string|array|bool|null $value)
|
||||
{
|
||||
if ('checkbox' === $this->type && false === $value) {
|
||||
// uncheck
|
||||
@@ -175,20 +157,16 @@ class ChoiceFormField extends FormField
|
||||
|
||||
/**
|
||||
* Returns the type of the choice field (radio, select, or checkbox).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the field accepts multiple values.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMultiple()
|
||||
public function isMultiple(): bool
|
||||
{
|
||||
return $this->multiple;
|
||||
}
|
||||
@@ -244,7 +222,7 @@ class ChoiceFormField extends FormField
|
||||
}
|
||||
|
||||
// if no option is selected and if it is a simple select box, take the first option as the value
|
||||
if (!$found && !$this->multiple && !empty($this->options)) {
|
||||
if (!$found && !$this->multiple && $this->options) {
|
||||
$this->value = $this->options[0]['value'];
|
||||
}
|
||||
}
|
||||
@@ -268,11 +246,9 @@ class ChoiceFormField extends FormField
|
||||
/**
|
||||
* Checks whether given value is in the existing options.
|
||||
*
|
||||
* @internal since Symfony 5.3
|
||||
*
|
||||
* @return bool
|
||||
* @internal
|
||||
*/
|
||||
public function containsOption(string $optionValue, array $options)
|
||||
public function containsOption(string $optionValue, array $options): bool
|
||||
{
|
||||
if ($this->validationDisabled) {
|
||||
return true;
|
||||
@@ -290,11 +266,9 @@ class ChoiceFormField extends FormField
|
||||
/**
|
||||
* Returns list of available field options.
|
||||
*
|
||||
* @internal since Symfony 5.3
|
||||
*
|
||||
* @return array
|
||||
* @internal
|
||||
*/
|
||||
public function availableOptionValues()
|
||||
public function availableOptionValues(): array
|
||||
{
|
||||
$values = [];
|
||||
|
||||
@@ -308,11 +282,11 @@ class ChoiceFormField extends FormField
|
||||
/**
|
||||
* Disables the internal validation of the field.
|
||||
*
|
||||
* @internal since Symfony 5.3
|
||||
* @internal
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function disableValidation()
|
||||
public function disableValidation(): static
|
||||
{
|
||||
$this->validationDisabled = true;
|
||||
|
||||
|
20
vendor/symfony/dom-crawler/Field/FormField.php
vendored
20
vendor/symfony/dom-crawler/Field/FormField.php
vendored
@@ -57,10 +57,8 @@ abstract class FormField
|
||||
|
||||
/**
|
||||
* Returns the label tag associated to the field or null if none.
|
||||
*
|
||||
* @return \DOMElement|null
|
||||
*/
|
||||
public function getLabel()
|
||||
public function getLabel(): ?\DOMElement
|
||||
{
|
||||
$xpath = new \DOMXPath($this->node->ownerDocument);
|
||||
|
||||
@@ -78,20 +76,16 @@ abstract class FormField
|
||||
|
||||
/**
|
||||
* Returns the name of the field.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the field.
|
||||
*
|
||||
* @return string|array|null
|
||||
*/
|
||||
public function getValue()
|
||||
public function getValue(): string|array|null
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
@@ -106,20 +100,16 @@ abstract class FormField
|
||||
|
||||
/**
|
||||
* Returns true if the field should be included in the submitted values.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasValue()
|
||||
public function hasValue(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current field is disabled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDisabled()
|
||||
public function isDisabled(): bool
|
||||
{
|
||||
return $this->node->hasAttribute('disabled');
|
||||
}
|
||||
|
Reference in New Issue
Block a user