laravel-6 support

This commit is contained in:
RafficMohammed
2023-01-08 01:17:22 +05:30
parent 1a5c16ae4b
commit 774eed8b0e
4962 changed files with 279380 additions and 297961 deletions

View File

@@ -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'];

View File

@@ -27,12 +27,12 @@ class FileFormField extends FormField
*/
public function setErrorCode($error)
{
$codes = array(UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_FORM_SIZE, UPLOAD_ERR_PARTIAL, UPLOAD_ERR_NO_FILE, UPLOAD_ERR_NO_TMP_DIR, UPLOAD_ERR_CANT_WRITE, UPLOAD_ERR_EXTENSION);
if (!in_array($error, $codes)) {
throw new \InvalidArgumentException(sprintf('The error code %s is not valid.', $error));
$codes = [\UPLOAD_ERR_INI_SIZE, \UPLOAD_ERR_FORM_SIZE, \UPLOAD_ERR_PARTIAL, \UPLOAD_ERR_NO_FILE, \UPLOAD_ERR_NO_TMP_DIR, \UPLOAD_ERR_CANT_WRITE, \UPLOAD_ERR_EXTENSION];
if (!\in_array($error, $codes)) {
throw new \InvalidArgumentException(sprintf('The error code "%s" is not valid.', $error));
}
$this->value = array('name' => '', 'type' => '', 'tmp_name' => '', 'error' => $error, 'size' => 0);
$this->value = ['name' => '', 'type' => '', 'tmp_name' => '', 'error' => $error, 'size' => 0];
}
/**
@@ -48,19 +48,19 @@ class FileFormField extends FormField
/**
* Sets the value of the field.
*
* @param string $value The value of the field
* @param string|null $value The value of the field
*/
public function setValue($value)
{
if (null !== $value && is_readable($value)) {
$error = UPLOAD_ERR_OK;
$error = \UPLOAD_ERR_OK;
$size = filesize($value);
$info = pathinfo($value);
$name = $info['basename'];
// copy to a tmp location
$tmp = sys_get_temp_dir().'/'.sha1(uniqid(mt_rand(), true));
if (array_key_exists('extension', $info)) {
$tmp = sys_get_temp_dir().'/'.strtr(substr(base64_encode(hash('sha256', uniqid(mt_rand(), true), true)), 0, 7), '/', '_');
if (\array_key_exists('extension', $info)) {
$tmp .= '.'.$info['extension'];
}
if (is_file($tmp)) {
@@ -69,13 +69,13 @@ class FileFormField extends FormField
copy($value, $tmp);
$value = $tmp;
} else {
$error = UPLOAD_ERR_NO_FILE;
$error = \UPLOAD_ERR_NO_FILE;
$size = 0;
$name = '';
$value = '';
}
$this->value = array('name' => $name, 'type' => '', 'tmp_name' => $value, 'error' => $error, 'size' => $size);
$this->value = ['name' => $name, 'type' => '', 'tmp_name' => $value, 'error' => $error, 'size' => $size];
}
/**
@@ -100,7 +100,7 @@ class FileFormField extends FormField
}
if ('file' !== strtolower($this->node->getAttribute('type'))) {
throw new \LogicException(sprintf('A FileFormField can only be created from an input tag with a type of file (given type is %s).', $this->node->getAttribute('type')));
throw new \LogicException(sprintf('A FileFormField can only be created from an input tag with a type of file (given type is "%s").', $this->node->getAttribute('type')));
}
$this->setValue(null);

View File

@@ -44,8 +44,6 @@ abstract class FormField
protected $disabled;
/**
* Constructor.
*
* @param \DOMElement $node The node associated with this field
*/
public function __construct(\DOMElement $node)
@@ -57,6 +55,27 @@ abstract class FormField
$this->initialize();
}
/**
* Returns the label tag associated to the field or null if none.
*
* @return \DOMElement|null
*/
public function getLabel()
{
$xpath = new \DOMXPath($this->node->ownerDocument);
if ($this->node->hasAttribute('id')) {
$labels = $xpath->query(sprintf('descendant::label[@for="%s"]', $this->node->getAttribute('id')));
if ($labels->length > 0) {
return $labels->item(0);
}
}
$labels = $xpath->query('ancestor::label[1]', $this->node);
return $labels->length > 0 ? $labels->item(0) : null;
}
/**
* Returns the name of the field.
*
@@ -80,7 +99,7 @@ abstract class FormField
/**
* Sets the value of the field.
*
* @param string $value The value of the field
* @param string|array|bool|null $value The value of the field
*/
public function setValue($value)
{

View File

@@ -32,11 +32,12 @@ class InputFormField extends FormField
throw new \LogicException(sprintf('An InputFormField can only be created from an input or button tag (%s given).', $this->node->nodeName));
}
if ('checkbox' === strtolower($this->node->getAttribute('type'))) {
$type = strtolower($this->node->getAttribute('type'));
if ('checkbox' === $type) {
throw new \LogicException('Checkboxes should be instances of ChoiceFormField.');
}
if ('file' === strtolower($this->node->getAttribute('type'))) {
if ('file' === $type) {
throw new \LogicException('File inputs should be instances of FileFormField.');
}