[Form] Backport type fixes
Signed-off-by: Alexander M. Turek <me@derrabus.de>
This commit is contained in:
parent
c9e4c33c0f
commit
289a7680ff
@ -22,14 +22,14 @@ abstract class AbstractExtension implements FormExtensionInterface
|
||||
/**
|
||||
* The types provided by this extension.
|
||||
*
|
||||
* @var FormTypeInterface[] An array of FormTypeInterface
|
||||
* @var FormTypeInterface[]
|
||||
*/
|
||||
private $types;
|
||||
|
||||
/**
|
||||
* The type extensions provided by this extension.
|
||||
*
|
||||
* @var FormTypeExtensionInterface[] An array of FormTypeExtensionInterface
|
||||
* @var FormTypeExtensionInterface[][]
|
||||
*/
|
||||
private $typeExtensions;
|
||||
|
||||
@ -153,7 +153,7 @@ abstract class AbstractExtension implements FormExtensionInterface
|
||||
|
||||
foreach ($this->loadTypes() as $type) {
|
||||
if (!$type instanceof FormTypeInterface) {
|
||||
throw new UnexpectedTypeException($type, 'Symfony\Component\Form\FormTypeInterface');
|
||||
throw new UnexpectedTypeException($type, FormTypeInterface::class);
|
||||
}
|
||||
|
||||
$this->types[\get_class($type)] = $type;
|
||||
@ -172,7 +172,7 @@ abstract class AbstractExtension implements FormExtensionInterface
|
||||
|
||||
foreach ($this->loadTypeExtensions() as $extension) {
|
||||
if (!$extension instanceof FormTypeExtensionInterface) {
|
||||
throw new UnexpectedTypeException($extension, 'Symfony\Component\Form\FormTypeExtensionInterface');
|
||||
throw new UnexpectedTypeException($extension, FormTypeExtensionInterface::class);
|
||||
}
|
||||
|
||||
if (method_exists($extension, 'getExtendedTypes')) {
|
||||
@ -204,7 +204,7 @@ abstract class AbstractExtension implements FormExtensionInterface
|
||||
|
||||
$this->typeGuesser = $this->loadTypeGuesser();
|
||||
if (null !== $this->typeGuesser && !$this->typeGuesser instanceof FormTypeGuesserInterface) {
|
||||
throw new UnexpectedTypeException($this->typeGuesser, 'Symfony\Component\Form\FormTypeGuesserInterface');
|
||||
throw new UnexpectedTypeException($this->typeGuesser, FormTypeGuesserInterface::class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,29 @@ abstract class AbstractRendererEngine implements FormRendererEngineInterface
|
||||
*/
|
||||
public const CACHE_KEY_VAR = 'cache_key';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $defaultThemes;
|
||||
|
||||
/**
|
||||
* @var array[]
|
||||
*/
|
||||
protected $themes = [];
|
||||
|
||||
/**
|
||||
* @var bool[]
|
||||
*/
|
||||
protected $useDefaultThemes = [];
|
||||
|
||||
/**
|
||||
* @var array[]
|
||||
*/
|
||||
protected $resources = [];
|
||||
|
||||
/**
|
||||
* @var array<array<int|false>>
|
||||
*/
|
||||
private $resourceHierarchyLevels = [];
|
||||
|
||||
/**
|
||||
@ -127,7 +145,7 @@ abstract class AbstractRendererEngine implements FormRendererEngineInterface
|
||||
*
|
||||
* @see getResourceForBlockHierarchy()
|
||||
*/
|
||||
private function loadResourceForBlockNameHierarchy(string $cacheKey, FormView $view, array $blockNameHierarchy, $hierarchyLevel): bool
|
||||
private function loadResourceForBlockNameHierarchy(string $cacheKey, FormView $view, array $blockNameHierarchy, int $hierarchyLevel): bool
|
||||
{
|
||||
$blockName = $blockNameHierarchy[$hierarchyLevel];
|
||||
|
||||
|
@ -22,7 +22,7 @@ use Symfony\Component\Form\Exception\BadMethodCallException;
|
||||
class Button implements \IteratorAggregate, FormInterface
|
||||
{
|
||||
/**
|
||||
* @var FormInterface
|
||||
* @var FormInterface|null
|
||||
*/
|
||||
private $parent;
|
||||
|
||||
|
@ -29,8 +29,8 @@ abstract class BaseDateTimeTransformer implements DataTransformerInterface
|
||||
protected $outputTimezone;
|
||||
|
||||
/**
|
||||
* @param string $inputTimezone The name of the input timezone
|
||||
* @param string $outputTimezone The name of the output timezone
|
||||
* @param string|null $inputTimezone The name of the input timezone
|
||||
* @param string|null $outputTimezone The name of the output timezone
|
||||
*
|
||||
* @throws InvalidArgumentException if a timezone is not valid
|
||||
*/
|
||||
|
@ -43,15 +43,12 @@ class DateIntervalToArrayTransformer implements DataTransformerInterface
|
||||
private $pad;
|
||||
|
||||
/**
|
||||
* @param string[] $fields The date fields
|
||||
* @param bool $pad Whether to use padding
|
||||
* @param string[]|null $fields The date fields
|
||||
* @param bool $pad Whether to use padding
|
||||
*/
|
||||
public function __construct(array $fields = null, bool $pad = false)
|
||||
{
|
||||
if (null === $fields) {
|
||||
$fields = ['years', 'months', 'days', 'hours', 'minutes', 'seconds', 'invert'];
|
||||
}
|
||||
$this->fields = $fields;
|
||||
$this->fields = $fields ?? ['years', 'months', 'days', 'hours', 'minutes', 'seconds', 'invert'];
|
||||
$this->pad = $pad;
|
||||
}
|
||||
|
||||
|
@ -22,25 +22,20 @@ use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
class DateTimeToArrayTransformer extends BaseDateTimeTransformer
|
||||
{
|
||||
private $pad;
|
||||
|
||||
private $fields;
|
||||
private $referenceDate;
|
||||
|
||||
/**
|
||||
* @param string $inputTimezone The input timezone
|
||||
* @param string $outputTimezone The output timezone
|
||||
* @param array $fields The date fields
|
||||
* @param bool $pad Whether to use padding
|
||||
* @param string|null $inputTimezone The input timezone
|
||||
* @param string|null $outputTimezone The output timezone
|
||||
* @param string[]|null $fields The date fields
|
||||
* @param bool $pad Whether to use padding
|
||||
*/
|
||||
public function __construct(string $inputTimezone = null, string $outputTimezone = null, array $fields = null, bool $pad = false, \DateTimeInterface $referenceDate = null)
|
||||
{
|
||||
parent::__construct($inputTimezone, $outputTimezone);
|
||||
|
||||
if (null === $fields) {
|
||||
$fields = ['year', 'month', 'day', 'hour', 'minute', 'second'];
|
||||
}
|
||||
|
||||
$this->fields = $fields;
|
||||
$this->fields = $fields ?? ['year', 'month', 'day', 'hour', 'minute', 'second'];
|
||||
$this->pad = $pad;
|
||||
$this->referenceDate = $referenceDate ?? new \DateTimeImmutable('1970-01-01 00:00:00');
|
||||
}
|
||||
|
@ -30,12 +30,12 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
||||
/**
|
||||
* @see BaseDateTimeTransformer::formats for available format options
|
||||
*
|
||||
* @param string $inputTimezone The name of the input timezone
|
||||
* @param string $outputTimezone The name of the output timezone
|
||||
* @param int $dateFormat The date format
|
||||
* @param int $timeFormat The time format
|
||||
* @param int $calendar One of the \IntlDateFormatter calendar constants
|
||||
* @param string $pattern A pattern to pass to \IntlDateFormatter
|
||||
* @param string|null $inputTimezone The name of the input timezone
|
||||
* @param string|null $outputTimezone The name of the output timezone
|
||||
* @param int|null $dateFormat The date format
|
||||
* @param int|null $timeFormat The time format
|
||||
* @param int $calendar One of the \IntlDateFormatter calendar constants
|
||||
* @param string|null $pattern A pattern to pass to \IntlDateFormatter
|
||||
*
|
||||
* @throws UnexpectedTypeException If a format is not supported or if a timezone is not a string
|
||||
*/
|
||||
@ -70,7 +70,7 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
|
||||
*
|
||||
* @param \DateTimeInterface $dateTime A DateTimeInterface object
|
||||
*
|
||||
* @return string|array Localized date string/array
|
||||
* @return string Localized date string
|
||||
*
|
||||
* @throws TransformationFailedException if the given value is not a \DateTimeInterface
|
||||
* or if the date could not be transformed
|
||||
|
@ -44,9 +44,9 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
|
||||
*
|
||||
* @see \DateTime::format() for supported formats
|
||||
*
|
||||
* @param string $inputTimezone The name of the input timezone
|
||||
* @param string $outputTimezone The name of the output timezone
|
||||
* @param string $format The date format
|
||||
* @param string|null $inputTimezone The name of the input timezone
|
||||
* @param string|null $outputTimezone The name of the output timezone
|
||||
* @param string $format The date format
|
||||
*/
|
||||
public function __construct(string $inputTimezone = null, string $outputTimezone = null, string $format = 'Y-m-d H:i:s')
|
||||
{
|
||||
|
@ -25,21 +25,9 @@ class MoneyToLocalizedStringTransformer extends NumberToLocalizedStringTransform
|
||||
|
||||
public function __construct(?int $scale = 2, ?bool $grouping = true, ?int $roundingMode = self::ROUND_HALF_UP, ?int $divisor = 1)
|
||||
{
|
||||
if (null === $grouping) {
|
||||
$grouping = true;
|
||||
}
|
||||
parent::__construct($scale ?? 2, $grouping ?? true, $roundingMode);
|
||||
|
||||
if (null === $scale) {
|
||||
$scale = 2;
|
||||
}
|
||||
|
||||
parent::__construct($scale, $grouping, $roundingMode);
|
||||
|
||||
if (null === $divisor) {
|
||||
$divisor = 1;
|
||||
}
|
||||
|
||||
$this->divisor = $divisor;
|
||||
$this->divisor = $divisor ?? 1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,17 +81,9 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
|
||||
|
||||
public function __construct(int $scale = null, ?bool $grouping = false, ?int $roundingMode = self::ROUND_HALF_UP, string $locale = null)
|
||||
{
|
||||
if (null === $grouping) {
|
||||
$grouping = false;
|
||||
}
|
||||
|
||||
if (null === $roundingMode) {
|
||||
$roundingMode = self::ROUND_HALF_UP;
|
||||
}
|
||||
|
||||
$this->scale = $scale;
|
||||
$this->grouping = $grouping;
|
||||
$this->roundingMode = $roundingMode;
|
||||
$this->grouping = $grouping ?? false;
|
||||
$this->roundingMode = $roundingMode ?? self::ROUND_HALF_UP;
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
|
@ -37,17 +37,10 @@ class PercentToLocalizedStringTransformer implements DataTransformerInterface
|
||||
/**
|
||||
* @see self::$types for a list of supported types
|
||||
*
|
||||
* @param int $scale The scale
|
||||
* @param string $type One of the supported types
|
||||
*
|
||||
* @throws UnexpectedTypeException if the given value of type is unknown
|
||||
*/
|
||||
public function __construct(int $scale = null, string $type = null)
|
||||
{
|
||||
if (null === $scale) {
|
||||
$scale = 0;
|
||||
}
|
||||
|
||||
if (null === $type) {
|
||||
$type = self::FRACTIONAL;
|
||||
}
|
||||
@ -57,7 +50,7 @@ class PercentToLocalizedStringTransformer implements DataTransformerInterface
|
||||
}
|
||||
|
||||
$this->type = $type;
|
||||
$this->scale = $scale;
|
||||
$this->scale = $scale ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
*/
|
||||
class DateIntervalType extends AbstractType
|
||||
{
|
||||
private $timeParts = [
|
||||
private const TIME_PARTS = [
|
||||
'years',
|
||||
'months',
|
||||
'weeks',
|
||||
@ -96,7 +96,7 @@ class DateIntervalType extends AbstractType
|
||||
if ('single_text' === $options['widget']) {
|
||||
$builder->addViewTransformer(new DateIntervalToStringTransformer($format));
|
||||
} else {
|
||||
foreach ($this->timeParts as $part) {
|
||||
foreach (self::TIME_PARTS as $part) {
|
||||
if ($options['with_'.$part]) {
|
||||
$childOptions = [
|
||||
'error_bubbling' => true,
|
||||
@ -157,7 +157,7 @@ class DateIntervalType extends AbstractType
|
||||
'widget' => $options['widget'],
|
||||
'with_invert' => $options['with_invert'],
|
||||
];
|
||||
foreach ($this->timeParts as $part) {
|
||||
foreach (self::TIME_PARTS as $part) {
|
||||
$vars['with_'.$part] = $options['with_'.$part];
|
||||
}
|
||||
$view->vars = array_replace($view->vars, $vars);
|
||||
@ -168,7 +168,6 @@ class DateIntervalType extends AbstractType
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$timeParts = $this->timeParts;
|
||||
$compound = function (Options $options) {
|
||||
return 'single_text' !== $options['widget'];
|
||||
};
|
||||
@ -180,14 +179,14 @@ class DateIntervalType extends AbstractType
|
||||
return $options['required'] ? null : '';
|
||||
};
|
||||
|
||||
$placeholderNormalizer = function (Options $options, $placeholder) use ($placeholderDefault, $timeParts) {
|
||||
$placeholderNormalizer = function (Options $options, $placeholder) use ($placeholderDefault) {
|
||||
if (\is_array($placeholder)) {
|
||||
$default = $placeholderDefault($options);
|
||||
|
||||
return array_merge(array_fill_keys($timeParts, $default), $placeholder);
|
||||
return array_merge(array_fill_keys(self::TIME_PARTS, $default), $placeholder);
|
||||
}
|
||||
|
||||
return array_fill_keys($timeParts, $placeholder);
|
||||
return array_fill_keys(self::TIME_PARTS, $placeholder);
|
||||
};
|
||||
|
||||
$labelsNormalizer = function (Options $options, array $labels) {
|
||||
|
@ -39,8 +39,8 @@ class DateType extends AbstractType
|
||||
];
|
||||
|
||||
private const WIDGETS = [
|
||||
'text' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
'choice' => 'Symfony\Component\Form\Extension\Core\Type\ChoiceType',
|
||||
'text' => TextType::class,
|
||||
'choice' => ChoiceType::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -29,8 +29,8 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
class TimeType extends AbstractType
|
||||
{
|
||||
private const WIDGETS = [
|
||||
'text' => 'Symfony\Component\Form\Extension\Core\Type\TextType',
|
||||
'choice' => 'Symfony\Component\Form\Extension\Core\Type\ChoiceType',
|
||||
'text' => TextType::class,
|
||||
'choice' => ChoiceType::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Form\Extension\Csrf\Type;
|
||||
|
||||
use Symfony\Component\Form\AbstractTypeExtension;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\Extension\Csrf\EventListener\CsrfValidationListener;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
@ -83,7 +84,7 @@ class FormTypeCsrfExtension extends AbstractTypeExtension
|
||||
$tokenId = $options['csrf_token_id'] ?: ($form->getName() ?: \get_class($form->getConfig()->getType()->getInnerType()));
|
||||
$data = (string) $options['csrf_token_manager']->getToken($tokenId);
|
||||
|
||||
$csrfForm = $factory->createNamed($options['csrf_field_name'], 'Symfony\Component\Form\Extension\Core\Type\HiddenType', $data, [
|
||||
$csrfForm = $factory->createNamed($options['csrf_field_name'], HiddenType::class, $data, [
|
||||
'block_prefix' => 'csrf_token',
|
||||
'mapped' => false,
|
||||
]);
|
||||
|
@ -23,6 +23,7 @@ use Symfony\Component\Form\Exception\OutOfBoundsException;
|
||||
use Symfony\Component\Form\Exception\RuntimeException;
|
||||
use Symfony\Component\Form\Exception\TransformationFailedException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\Util\FormUtil;
|
||||
use Symfony\Component\Form\Util\InheritDataAwareIterator;
|
||||
use Symfony\Component\Form\Util\OrderedHashMap;
|
||||
@ -80,12 +81,14 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
|
||||
private $parent;
|
||||
|
||||
/**
|
||||
* @var FormInterface[]|OrderedHashMap A map of FormInterface instances
|
||||
* A map of FormInterface instances.
|
||||
*
|
||||
* @var FormInterface[]|OrderedHashMap
|
||||
*/
|
||||
private $children;
|
||||
|
||||
/**
|
||||
* @var FormError[] An array of FormError instances
|
||||
* @var FormError[]
|
||||
*/
|
||||
private $errors = [];
|
||||
|
||||
@ -95,7 +98,9 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
|
||||
private $submitted = false;
|
||||
|
||||
/**
|
||||
* @var FormInterface|ClickableInterface|null The button that was used to submit the form
|
||||
* The button that was used to submit the form.
|
||||
*
|
||||
* @var FormInterface|ClickableInterface|null
|
||||
*/
|
||||
private $clickedButton;
|
||||
|
||||
@ -115,12 +120,16 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
|
||||
private $viewData;
|
||||
|
||||
/**
|
||||
* @var array The submitted values that don't belong to any children
|
||||
* The submitted values that don't belong to any children.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $extraData = [];
|
||||
|
||||
/**
|
||||
* @var TransformationFailedException|null The transformation failure generated during submission, if any
|
||||
* The transformation failure generated during submission, if any.
|
||||
*
|
||||
* @var TransformationFailedException|null
|
||||
*/
|
||||
private $transformationFailure;
|
||||
|
||||
@ -151,7 +160,9 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
|
||||
private $name = '';
|
||||
|
||||
/**
|
||||
* @var bool Whether the form inherits its underlying data from its parent
|
||||
* Whether the form inherits its underlying data from its parent.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $inheritData;
|
||||
|
||||
@ -857,7 +868,7 @@ class Form implements \IteratorAggregate, FormInterface, ClearableErrorsInterfac
|
||||
$options['auto_initialize'] = false;
|
||||
|
||||
if (null === $type && null === $this->config->getDataClass()) {
|
||||
$type = 'Symfony\Component\Form\Extension\Core\Type\TextType';
|
||||
$type = TextType::class;
|
||||
}
|
||||
|
||||
if (null === $type) {
|
||||
|
@ -15,6 +15,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\Form\Exception\BadMethodCallException;
|
||||
use Symfony\Component\Form\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
|
||||
/**
|
||||
* A builder for creating {@link Form} instances.
|
||||
@ -87,7 +88,7 @@ class FormBuilder extends FormConfigBuilder implements \IteratorAggregate, FormB
|
||||
}
|
||||
|
||||
if (null === $type && null === $this->getDataClass()) {
|
||||
$type = 'Symfony\Component\Form\Extension\Core\Type\TextType';
|
||||
$type = TextType::class;
|
||||
}
|
||||
|
||||
if (null !== $type) {
|
||||
|
@ -12,6 +12,8 @@
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
|
||||
class FormFactory implements FormFactoryInterface
|
||||
{
|
||||
@ -25,7 +27,7 @@ class FormFactory implements FormFactoryInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function create($type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = [])
|
||||
public function create($type = FormType::class, $data = null, array $options = [])
|
||||
{
|
||||
return $this->createBuilder($type, $data, $options)->getForm();
|
||||
}
|
||||
@ -33,7 +35,7 @@ class FormFactory implements FormFactoryInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createNamed($name, $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = [])
|
||||
public function createNamed($name, $type = FormType::class, $data = null, array $options = [])
|
||||
{
|
||||
return $this->createNamedBuilder($name, $type, $data, $options)->getForm();
|
||||
}
|
||||
@ -49,7 +51,7 @@ class FormFactory implements FormFactoryInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createBuilder($type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = [])
|
||||
public function createBuilder($type = FormType::class, $data = null, array $options = [])
|
||||
{
|
||||
if (!\is_string($type)) {
|
||||
throw new UnexpectedTypeException($type, 'string');
|
||||
@ -61,7 +63,7 @@ class FormFactory implements FormFactoryInterface
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createNamedBuilder($name, $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = [])
|
||||
public function createNamedBuilder($name, $type = FormType::class, $data = null, array $options = [])
|
||||
{
|
||||
if (null !== $data && !\array_key_exists('data', $options)) {
|
||||
$options['data'] = $data;
|
||||
@ -88,7 +90,7 @@ class FormFactory implements FormFactoryInterface
|
||||
public function createBuilderForProperty($class, $property, $data = null, array $options = [])
|
||||
{
|
||||
if (null === $guesser = $this->registry->getTypeGuesser()) {
|
||||
return $this->createNamedBuilder($property, 'Symfony\Component\Form\Extension\Core\Type\TextType', $data, $options);
|
||||
return $this->createNamedBuilder($property, TextType::class, $data, $options);
|
||||
}
|
||||
|
||||
$typeGuess = $guesser->guessType($class, $property);
|
||||
@ -96,7 +98,7 @@ class FormFactory implements FormFactoryInterface
|
||||
$requiredGuess = $guesser->guessRequired($class, $property);
|
||||
$patternGuess = $guesser->guessPattern($class, $property);
|
||||
|
||||
$type = $typeGuess ? $typeGuess->getType() : 'Symfony\Component\Form\Extension\Core\Type\TextType';
|
||||
$type = $typeGuess ? $typeGuess->getType() : TextType::class;
|
||||
|
||||
$maxLength = $maxLengthGuess ? $maxLengthGuess->getValue() : null;
|
||||
$pattern = $patternGuess ? $patternGuess->getValue() : null;
|
||||
|
@ -38,7 +38,7 @@ class FormFactoryBuilder implements FormFactoryBuilderInterface
|
||||
private $types = [];
|
||||
|
||||
/**
|
||||
* @var FormTypeExtensionInterface[]
|
||||
* @var FormTypeExtensionInterface[][]
|
||||
*/
|
||||
private $typeExtensions = [];
|
||||
|
||||
|
@ -11,6 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\Type\FormType;
|
||||
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
|
||||
|
||||
/**
|
||||
* Allows creating a form based on a name, a class or a property.
|
||||
*
|
||||
@ -28,9 +31,9 @@ interface FormFactoryInterface
|
||||
*
|
||||
* @return FormInterface The form named after the type
|
||||
*
|
||||
* @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the given type
|
||||
* @throws InvalidOptionsException if any given option is not applicable to the given type
|
||||
*/
|
||||
public function create($type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []);
|
||||
public function create($type = FormType::class, $data = null, array $options = []);
|
||||
|
||||
/**
|
||||
* Returns a form.
|
||||
@ -43,9 +46,9 @@ interface FormFactoryInterface
|
||||
*
|
||||
* @return FormInterface The form
|
||||
*
|
||||
* @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the given type
|
||||
* @throws InvalidOptionsException if any given option is not applicable to the given type
|
||||
*/
|
||||
public function createNamed($name, $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []);
|
||||
public function createNamed($name, $type = FormType::class, $data = null, array $options = []);
|
||||
|
||||
/**
|
||||
* Returns a form for a property of a class.
|
||||
@ -58,7 +61,7 @@ interface FormFactoryInterface
|
||||
*
|
||||
* @return FormInterface The form named after the property
|
||||
*
|
||||
* @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the form type
|
||||
* @throws InvalidOptionsException if any given option is not applicable to the form type
|
||||
*/
|
||||
public function createForProperty($class, $property, $data = null, array $options = []);
|
||||
|
||||
@ -70,9 +73,9 @@ interface FormFactoryInterface
|
||||
*
|
||||
* @return FormBuilderInterface The form builder
|
||||
*
|
||||
* @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the given type
|
||||
* @throws InvalidOptionsException if any given option is not applicable to the given type
|
||||
*/
|
||||
public function createBuilder($type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []);
|
||||
public function createBuilder($type = FormType::class, $data = null, array $options = []);
|
||||
|
||||
/**
|
||||
* Returns a form builder.
|
||||
@ -83,9 +86,9 @@ interface FormFactoryInterface
|
||||
*
|
||||
* @return FormBuilderInterface The form builder
|
||||
*
|
||||
* @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the given type
|
||||
* @throws InvalidOptionsException if any given option is not applicable to the given type
|
||||
*/
|
||||
public function createNamedBuilder($name, $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []);
|
||||
public function createNamedBuilder($name, $type = FormType::class, $data = null, array $options = []);
|
||||
|
||||
/**
|
||||
* Returns a form builder for a property of a class.
|
||||
@ -99,7 +102,7 @@ interface FormFactoryInterface
|
||||
*
|
||||
* @return FormBuilderInterface The form builder named after the property
|
||||
*
|
||||
* @throws \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException if any given option is not applicable to the form type
|
||||
* @throws InvalidOptionsException if any given option is not applicable to the form type
|
||||
*/
|
||||
public function createBuilderForProperty($class, $property, $data = null, array $options = []);
|
||||
}
|
||||
|
@ -24,8 +24,6 @@ use Symfony\Component\Form\Exception\UnexpectedTypeException;
|
||||
class FormRegistry implements FormRegistryInterface
|
||||
{
|
||||
/**
|
||||
* Extensions.
|
||||
*
|
||||
* @var FormExtensionInterface[]
|
||||
*/
|
||||
private $extensions = [];
|
||||
@ -48,7 +46,7 @@ class FormRegistry implements FormRegistryInterface
|
||||
private $checkedTypes = [];
|
||||
|
||||
/**
|
||||
* @param FormExtensionInterface[] $extensions An array of FormExtensionInterface
|
||||
* @param FormExtensionInterface[] $extensions
|
||||
*
|
||||
* @throws UnexpectedTypeException if any extension does not implement FormExtensionInterface
|
||||
*/
|
||||
@ -56,7 +54,7 @@ class FormRegistry implements FormRegistryInterface
|
||||
{
|
||||
foreach ($extensions as $extension) {
|
||||
if (!$extension instanceof FormExtensionInterface) {
|
||||
throw new UnexpectedTypeException($extension, 'Symfony\Component\Form\FormExtensionInterface');
|
||||
throw new UnexpectedTypeException($extension, FormExtensionInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,7 +82,7 @@ class FormRegistry implements FormRegistryInterface
|
||||
if (!class_exists($name)) {
|
||||
throw new InvalidArgumentException(sprintf('Could not load type "%s": class does not exist.', $name));
|
||||
}
|
||||
if (!is_subclass_of($name, 'Symfony\Component\Form\FormTypeInterface')) {
|
||||
if (!is_subclass_of($name, FormTypeInterface::class)) {
|
||||
throw new InvalidArgumentException(sprintf('Could not load type "%s": class does not implement "Symfony\Component\Form\FormTypeInterface".', $name));
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ class FormTypeGuesserChain implements FormTypeGuesserInterface
|
||||
{
|
||||
foreach ($guessers as $guesser) {
|
||||
if (!$guesser instanceof FormTypeGuesserInterface) {
|
||||
throw new UnexpectedTypeException($guesser, 'Symfony\Component\Form\FormTypeGuesserInterface');
|
||||
throw new UnexpectedTypeException($guesser, FormTypeGuesserInterface::class);
|
||||
}
|
||||
|
||||
if ($guesser instanceof self) {
|
||||
|
@ -80,8 +80,6 @@ abstract class Guess
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $confidence The confidence
|
||||
*
|
||||
* @throws InvalidArgumentException if the given value of confidence is unknown
|
||||
*/
|
||||
public function __construct(int $confidence)
|
||||
|
@ -43,11 +43,14 @@ class ResolvedFormType implements ResolvedFormTypeInterface
|
||||
*/
|
||||
private $optionsResolver;
|
||||
|
||||
/**
|
||||
* @param FormTypeExtensionInterface[] $typeExtensions
|
||||
*/
|
||||
public function __construct(FormTypeInterface $innerType, array $typeExtensions = [], ResolvedFormTypeInterface $parent = null)
|
||||
{
|
||||
foreach ($typeExtensions as $extension) {
|
||||
if (!$extension instanceof FormTypeExtensionInterface) {
|
||||
throw new UnexpectedTypeException($extension, 'Symfony\Component\Form\FormTypeExtensionInterface');
|
||||
throw new UnexpectedTypeException($extension, FormTypeExtensionInterface::class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,7 +120,7 @@ class ResolvedFormType implements ResolvedFormTypeInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a form builder for the type hierarchy.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
@ -133,9 +136,7 @@ class ResolvedFormType implements ResolvedFormTypeInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a form view for the type hierarchy.
|
||||
*
|
||||
* This method is called before the children of the view are built.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
@ -151,9 +152,7 @@ class ResolvedFormType implements ResolvedFormTypeInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Finishes a form view for the type hierarchy.
|
||||
*
|
||||
* This method is called after the children of the view have been built.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function finishView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
@ -170,9 +169,7 @@ class ResolvedFormType implements ResolvedFormTypeInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configured options resolver used for this type.
|
||||
*
|
||||
* @return \Symfony\Component\OptionsResolver\OptionsResolver The options resolver
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getOptionsResolver()
|
||||
{
|
||||
|
@ -13,9 +13,8 @@ namespace Symfony\Component\Form\Tests;
|
||||
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\AbstractTypeExtension;
|
||||
use Symfony\Component\Form\DataMapperInterface;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\Form;
|
||||
use Symfony\Component\Form\FormConfigInterface;
|
||||
@ -33,21 +32,6 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
*/
|
||||
class ResolvedFormTypeTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var MockObject
|
||||
*/
|
||||
private $dispatcher;
|
||||
|
||||
/**
|
||||
* @var MockObject
|
||||
*/
|
||||
private $factory;
|
||||
|
||||
/**
|
||||
* @var MockObject
|
||||
*/
|
||||
private $dataMapper;
|
||||
|
||||
/**
|
||||
* @var MockObject|FormTypeInterface
|
||||
*/
|
||||
@ -80,9 +64,6 @@ class ResolvedFormTypeTest extends TestCase
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->dispatcher = $this->createMock(EventDispatcherInterface::class);
|
||||
$this->factory = $this->createMock(FormFactoryInterface::class);
|
||||
$this->dataMapper = $this->createMock(DataMapperInterface::class);
|
||||
$this->parentType = $this->getMockFormType();
|
||||
$this->type = $this->getMockFormType();
|
||||
$this->extension1 = $this->getMockFormTypeExtension();
|
||||
@ -256,7 +237,7 @@ class ResolvedFormTypeTest extends TestCase
|
||||
|
||||
public function testCreateView()
|
||||
{
|
||||
$form = new Form($this->createMock(FormConfigInterface::class));
|
||||
$form = $this->bootstrapForm();
|
||||
|
||||
$view = $this->resolvedType->createView($form);
|
||||
|
||||
@ -266,7 +247,7 @@ class ResolvedFormTypeTest extends TestCase
|
||||
|
||||
public function testCreateViewWithParent()
|
||||
{
|
||||
$form = new Form($this->createMock(FormConfigInterface::class));
|
||||
$form = $this->bootstrapForm();
|
||||
$parentView = $this->createMock(FormView::class);
|
||||
|
||||
$view = $this->resolvedType->createView($form, $parentView);
|
||||
@ -278,7 +259,7 @@ class ResolvedFormTypeTest extends TestCase
|
||||
public function testBuildView()
|
||||
{
|
||||
$options = ['a' => '1', 'b' => '2'];
|
||||
$form = new Form($this->createMock(FormConfigInterface::class));
|
||||
$form = $this->bootstrapForm();
|
||||
$view = $this->createMock(FormView::class);
|
||||
|
||||
$i = 0;
|
||||
@ -320,7 +301,7 @@ class ResolvedFormTypeTest extends TestCase
|
||||
public function testFinishView()
|
||||
{
|
||||
$options = ['a' => '1', 'b' => '2'];
|
||||
$form = new Form($this->createMock(FormConfigInterface::class));
|
||||
$form = $this->bootstrapForm();
|
||||
$view = $this->createMock(FormView::class);
|
||||
|
||||
$i = 0;
|
||||
@ -392,7 +373,7 @@ class ResolvedFormTypeTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
private function getMockFormType($typeClass = 'Symfony\Component\Form\AbstractType'): MockObject
|
||||
private function getMockFormType($typeClass = AbstractType::class): MockObject
|
||||
{
|
||||
return $this->getMockBuilder($typeClass)->setMethods(['getBlockPrefix', 'configureOptions', 'finishView', 'buildView', 'buildForm'])->getMock();
|
||||
}
|
||||
@ -406,4 +387,13 @@ class ResolvedFormTypeTest extends TestCase
|
||||
{
|
||||
return $this->createMock(FormFactoryInterface::class);
|
||||
}
|
||||
|
||||
private function bootstrapForm(): Form
|
||||
{
|
||||
$config = $this->createMock(FormConfigInterface::class);
|
||||
$config->method('getInheritData')->willReturn(false);
|
||||
$config->method('getName')->willReturn('');
|
||||
|
||||
return new Form($config);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user