Upgrade 1-11.38

This commit is contained in:
xesmyd
2026-03-30 14:10:30 +02:00
parent f2a7e6d1fc
commit ac648ef29d
24665 changed files with 69682 additions and 2205004 deletions
-7
View File
@@ -26,14 +26,7 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
*/
class CoreExtension extends AbstractExtension
{
/**
* @var PropertyAccessorInterface
*/
private $propertyAccessor;
/**
* @var ChoiceListFactoryInterface
*/
private $choiceListFactory;
public function __construct(PropertyAccessorInterface $propertyAccessor = null, ChoiceListFactoryInterface $choiceListFactory = null)
@@ -23,16 +23,8 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
*/
class PropertyPathMapper implements DataMapperInterface
{
/**
* @var PropertyAccessorInterface
*/
private $propertyAccessor;
/**
* Creates a new property path mapper.
*
* @param PropertyAccessorInterface $propertyAccessor The property accessor
*/
public function __construct(PropertyAccessorInterface $propertyAccessor = null)
{
$this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor();
@@ -30,8 +30,6 @@ abstract class BaseDateTimeTransformer implements DataTransformerInterface
protected $outputTimezone;
/**
* Constructor.
*
* @param string $inputTimezone The name of the input timezone
* @param string $outputTimezone The name of the output timezone
*
@@ -22,17 +22,10 @@ use Symfony\Component\Form\Exception\TransformationFailedException;
*/
class BooleanToStringTransformer implements DataTransformerInterface
{
/**
* The value emitted upon transform if the input is true.
*
* @var string
*/
private $trueValue;
/**
* Sets the value emitted upon transform if the input is true.
*
* @param string $trueValue
* @param string $trueValue The value emitted upon transform if the input is true
*/
public function __construct($trueValue)
{
@@ -46,7 +39,7 @@ class BooleanToStringTransformer implements DataTransformerInterface
*
* @return string String value
*
* @throws TransformationFailedException If the given value is not a Boolean.
* @throws TransformationFailedException if the given value is not a Boolean
*/
public function transform($value)
{
@@ -68,7 +61,7 @@ class BooleanToStringTransformer implements DataTransformerInterface
*
* @return bool Boolean value
*
* @throws TransformationFailedException If the given value is not a string.
* @throws TransformationFailedException if the given value is not a string
*/
public function reverseTransform($value)
{
@@ -22,11 +22,6 @@ class ChoiceToValueTransformer implements DataTransformerInterface
{
private $choiceList;
/**
* Constructor.
*
* @param ChoiceListInterface $choiceList
*/
public function __construct(ChoiceListInterface $choiceList)
{
$this->choiceList = $choiceList;
@@ -22,22 +22,15 @@ class ChoicesToValuesTransformer implements DataTransformerInterface
{
private $choiceList;
/**
* Constructor.
*
* @param ChoiceListInterface $choiceList
*/
public function __construct(ChoiceListInterface $choiceList)
{
$this->choiceList = $choiceList;
}
/**
* @param array $array
*
* @return array
*
* @throws TransformationFailedException If the given value is not an array.
* @throws TransformationFailedException if the given value is not an array
*/
public function transform($array)
{
@@ -53,13 +46,11 @@ class ChoicesToValuesTransformer implements DataTransformerInterface
}
/**
* @param array $array
*
* @return array
*
* @throws TransformationFailedException If the given value is not an array
* @throws TransformationFailedException if the given value is not an array
* or if no matching choice could be
* found for some given value.
* found for some given value
*/
public function reverseTransform($array)
{
@@ -21,17 +21,12 @@ use Symfony\Component\Form\Exception\TransformationFailedException;
*/
class DataTransformerChain implements DataTransformerInterface
{
/**
* The value transformers.
*
* @var DataTransformerInterface[]
*/
protected $transformers;
/**
* Uses the given value transformers to transform values.
*
* @param array $transformers
* @param DataTransformerInterface[] $transformers
*/
public function __construct(array $transformers)
{
@@ -62,7 +62,7 @@ class DateIntervalToArrayTransformer implements DataTransformerInterface
*
* @return array Interval array
*
* @throws UnexpectedTypeException If the given value is not a \DateInterval instance.
* @throws UnexpectedTypeException if the given value is not a \DateInterval instance
*/
public function transform($dateInterval)
{
@@ -108,8 +108,8 @@ class DateIntervalToArrayTransformer implements DataTransformerInterface
*
* @return \DateInterval Normalized date interval
*
* @throws UnexpectedTypeException If the given value is not an array.
* @throws TransformationFailedException If the value could not be transformed.
* @throws UnexpectedTypeException if the given value is not an array
* @throws TransformationFailedException if the value could not be transformed
*/
public function reverseTransform($value)
{
@@ -135,7 +135,7 @@ class DateIntervalToArrayTransformer implements DataTransformerInterface
throw new TransformationFailedException('The value of "invert" must be boolean');
}
foreach (self::$availableFields as $field => $char) {
if ($field !== 'invert' && isset($value[$field]) && !ctype_digit((string) $value[$field])) {
if ('invert' !== $field && isset($value[$field]) && !ctype_digit((string) $value[$field])) {
throw new TransformationFailedException(sprintf('This amount of "%s" is invalid', $field));
}
}
@@ -23,20 +23,17 @@ use Symfony\Component\Form\Exception\UnexpectedTypeException;
class DateIntervalToStringTransformer implements DataTransformerInterface
{
private $format;
private $parseSigned;
/**
* Transforms a \DateInterval instance to a string.
*
* @see \DateInterval::format() for supported formats
*
* @param string $format The date format
* @param bool $parseSigned Whether to parse as a signed interval
* @param string $format The date format
*/
public function __construct($format = 'P%yY%mM%dDT%hH%iM%sS', $parseSigned = false)
public function __construct($format = 'P%yY%mM%dDT%hH%iM%sS')
{
$this->format = $format;
$this->parseSigned = $parseSigned;
}
/**
@@ -46,7 +43,7 @@ class DateIntervalToStringTransformer implements DataTransformerInterface
*
* @return string An ISO 8601 or relative date string like date interval presentation
*
* @throws UnexpectedTypeException If the given value is not a \DateInterval instance.
* @throws UnexpectedTypeException if the given value is not a \DateInterval instance
*/
public function transform($value)
{
@@ -67,8 +64,8 @@ class DateIntervalToStringTransformer implements DataTransformerInterface
*
* @return \DateInterval An instance of \DateInterval
*
* @throws UnexpectedTypeException If the given value is not a string.
* @throws TransformationFailedException If the date interval could not be parsed.
* @throws UnexpectedTypeException if the given value is not a string
* @throws TransformationFailedException if the date interval could not be parsed
*/
public function reverseTransform($value)
{
@@ -27,8 +27,6 @@ class DateTimeToArrayTransformer extends BaseDateTimeTransformer
private $fields;
/**
* Constructor.
*
* @param string $inputTimezone The input timezone
* @param string $outputTimezone The output timezone
* @param array $fields The date fields
@@ -28,8 +28,6 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
private $calendar;
/**
* Constructor.
*
* @see BaseDateTimeTransformer::formats for available format options
*
* @param string $inputTimezone The name of the input timezone
@@ -74,8 +72,8 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
*
* @return string|array Localized date string/array
*
* @throws TransformationFailedException If the given value is not a \DateTimeInterface
* or if the date could not be transformed.
* @throws TransformationFailedException if the given value is not a \DateTimeInterface
* or if the date could not be transformed
*/
public function transform($dateTime)
{
@@ -89,7 +87,7 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
$value = $this->getIntlDateFormatter()->format($dateTime->getTimestamp());
if (intl_get_error_code() != 0) {
if (0 != intl_get_error_code()) {
throw new TransformationFailedException(intl_get_error_message());
}
@@ -122,8 +120,11 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
$timestamp = $this->getIntlDateFormatter($dateOnly)->parse($value);
if (intl_get_error_code() != 0) {
if (0 != intl_get_error_code()) {
throw new TransformationFailedException(intl_get_error_message());
} elseif ($timestamp > 253402214400) {
// This timestamp represents UTC midnight of 9999-12-31 to prevent 5+ digit years
throw new TransformationFailedException('Years beyond 9999 are not supported.');
}
try {
@@ -151,11 +152,11 @@ class DateTimeToLocalizedStringTransformer extends BaseDateTimeTransformer
/**
* Returns a preconfigured IntlDateFormatter instance.
*
* @param bool $ignoreTimezone Use UTC regardless of the configured timezone.
* @param bool $ignoreTimezone Use UTC regardless of the configured timezone
*
* @return \IntlDateFormatter
*
* @throws TransformationFailedException in case the date formatter can not be constructed.
* @throws TransformationFailedException in case the date formatter can not be constructed
*/
protected function getIntlDateFormatter($ignoreTimezone = false)
{
@@ -49,17 +49,16 @@ class MoneyToLocalizedStringTransformer extends NumberToLocalizedStringTransform
*
* @return string Localized money string
*
* @throws TransformationFailedException If the given value is not numeric or
* if the value can not be transformed.
* @throws TransformationFailedException if the given value is not numeric or
* if the value can not be transformed
*/
public function transform($value)
{
if (null !== $value) {
if (null !== $value && 1 !== $this->divisor) {
if (!is_numeric($value)) {
throw new TransformationFailedException('Expected a numeric.');
}
$value /= $this->divisor;
$value = (string) ($value / $this->divisor);
}
return parent::transform($value);
@@ -72,15 +71,14 @@ class MoneyToLocalizedStringTransformer extends NumberToLocalizedStringTransform
*
* @return int|float Normalized number
*
* @throws TransformationFailedException If the given value is not a string
* or if the value can not be transformed.
* @throws TransformationFailedException if the given value is not a string
* or if the value can not be transformed
*/
public function reverseTransform($value)
{
$value = parent::reverseTransform($value);
if (null !== $value) {
$value *= $this->divisor;
if (null !== $value && 1 !== $this->divisor) {
$value = (float) (string) ($value * $this->divisor);
}
return $value;
@@ -100,8 +100,8 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
*
* @return string Localized value
*
* @throws TransformationFailedException If the given value is not numeric
* or if the value can not be transformed.
* @throws TransformationFailedException if the given value is not numeric
* or if the value can not be transformed
*/
public function transform($value)
{
@@ -133,8 +133,8 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
*
* @return int|float The numeric value
*
* @throws TransformationFailedException If the given value is not a string
* or if the value can not be transformed.
* @throws TransformationFailedException if the given value is not a string
* or if the value can not be transformed
*/
public function reverseTransform($value)
{
@@ -32,12 +32,9 @@ class PercentToLocalizedStringTransformer implements DataTransformerInterface
);
private $type;
private $scale;
/**
* Constructor.
*
* @see self::$types for a list of supported types
*
* @param int $scale The scale
@@ -70,8 +67,8 @@ class PercentToLocalizedStringTransformer implements DataTransformerInterface
*
* @return string Percentage value
*
* @throws TransformationFailedException If the given value is not numeric or
* if the value could not be transformed.
* @throws TransformationFailedException if the given value is not numeric or
* if the value could not be transformed
*/
public function transform($value)
{
@@ -105,8 +102,8 @@ class PercentToLocalizedStringTransformer implements DataTransformerInterface
*
* @return int|float Normalized value
*
* @throws TransformationFailedException If the given value is not a string or
* if the value could not be transformed.
* @throws TransformationFailedException if the given value is not a string or
* if the value could not be transformed
*/
public function reverseTransform($value)
{
@@ -118,19 +115,58 @@ class PercentToLocalizedStringTransformer implements DataTransformerInterface
return;
}
$position = 0;
$formatter = $this->getNumberFormatter();
$groupSep = $formatter->getSymbol(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL);
$decSep = $formatter->getSymbol(\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL);
$grouping = $formatter->getAttribute(\NumberFormatter::GROUPING_USED);
if ('.' !== $decSep && (!$grouping || '.' !== $groupSep)) {
$value = str_replace('.', $decSep, $value);
}
if (',' !== $decSep && (!$grouping || ',' !== $groupSep)) {
$value = str_replace(',', $decSep, $value);
}
if (false !== strpos($value, $decSep)) {
$type = \NumberFormatter::TYPE_DOUBLE;
} else {
$type = \PHP_INT_SIZE === 8 ? \NumberFormatter::TYPE_INT64 : \NumberFormatter::TYPE_INT32;
}
// replace normal spaces so that the formatter can read them
$value = $formatter->parse(str_replace(' ', "\xc2\xa0", $value));
$result = $formatter->parse(str_replace(' ', "\xc2\xa0", $value), $type, $position);
if (intl_is_failure($formatter->getErrorCode())) {
throw new TransformationFailedException($formatter->getErrorMessage());
}
if (self::FRACTIONAL == $this->type) {
$value /= 100;
$result /= 100;
}
return $value;
if (\function_exists('mb_detect_encoding') && false !== $encoding = mb_detect_encoding($value, null, true)) {
$length = mb_strlen($value, $encoding);
$remainder = mb_substr($value, $position, $length, $encoding);
} else {
$length = \strlen($value);
$remainder = substr($value, $position, $length);
}
// After parsing, position holds the index of the character where the
// parsing stopped
if ($position < $length) {
// Check if there are unrecognized characters at the end of the
// number (excluding whitespace characters)
$remainder = trim($remainder, " \t\n\r\0\x0b\xc2\xa0");
if ('' !== $remainder) {
throw new TransformationFailedException(sprintf('The number contains unrecognized characters: "%s"', $remainder));
}
}
return $result;
}
/**
@@ -47,12 +47,10 @@ class ValueToDuplicatesTransformer implements DataTransformerInterface
/**
* Extracts the duplicated value from an array.
*
* @param array $array
*
* @return mixed The value
*
* @throws TransformationFailedException If the given value is not an array or
* if the given array can not be transformed.
* @throws TransformationFailedException if the given value is not an array or
* if the given array can not be transformed
*/
public function reverseTransform($array)
{
@@ -25,8 +25,6 @@ class FixUrlProtocolListener implements EventSubscriberInterface
private $defaultProtocol;
/**
* Constructor.
*
* @param string|null $defaultProtocol The URL scheme to add when there is none or null to not modify the data
*/
public function __construct($defaultProtocol = 'http')
@@ -21,27 +21,12 @@ use Symfony\Component\Form\Exception\UnexpectedTypeException;
*/
class MergeCollectionListener implements EventSubscriberInterface
{
/**
* Whether elements may be added to the collection.
*
* @var bool
*/
private $allowAdd;
/**
* Whether elements may be removed from the collection.
*
* @var bool
*/
private $allowDelete;
/**
* Creates a new listener.
*
* @param bool $allowAdd Whether values might be added to the
* collection.
* @param bool $allowDelete Whether values might be removed from the
* collection.
* @param bool $allowAdd Whether values might be added to the collection
* @param bool $allowDelete Whether values might be removed from the collection
*/
public function __construct($allowAdd = false, $allowDelete = false)
{
@@ -80,7 +65,7 @@ class MergeCollectionListener implements EventSubscriberInterface
return;
}
if (!$dataToMergeInto) {
if (null === $dataToMergeInto) {
// No original data was set. Set it if allowed
if ($this->allowAdd) {
$dataToMergeInto = $data;
@@ -15,6 +15,7 @@ use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormInterface;
/**
* Resize a collection form element based on the data sent from the client.
@@ -23,35 +24,20 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
*/
class ResizeFormListener implements EventSubscriberInterface
{
/**
* @var string
*/
protected $type;
/**
* @var array
*/
protected $options;
/**
* Whether children could be added to the group.
*
* @var bool
*/
protected $allowAdd;
/**
* Whether children could be removed from the group.
*
* @var bool
*/
protected $allowDelete;
/**
* @var bool
*/
private $deleteEmpty;
/**
* @param string $type
* @param array $options
* @param bool $allowAdd Whether children could be added to the group
* @param bool $allowDelete Whether children could be removed from the group
* @param bool $deleteEmpty
*/
public function __construct($type, array $options = array(), $allowAdd = false, $allowDelete = false, $deleteEmpty = false)
{
$this->type = $type;
@@ -103,7 +89,7 @@ class ResizeFormListener implements EventSubscriberInterface
$data = $event->getData();
if ($data instanceof \Traversable && $data instanceof \ArrayAccess) {
@trigger_error('Support for objects implementing both \Traversable and \ArrayAccess is deprecated since version 3.1 and will be removed in 4.0. Use an array instead.', E_USER_DEPRECATED);
@trigger_error('Support for objects implementing both \Traversable and \ArrayAccess is deprecated since Symfony 3.1 and will be removed in 4.0. Use an array instead.', E_USER_DEPRECATED);
}
if (!is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) {
@@ -150,6 +136,7 @@ class ResizeFormListener implements EventSubscriberInterface
if ($this->deleteEmpty) {
$previousData = $event->getForm()->getData();
/** @var FormInterface $child */
foreach ($form as $name => $child) {
$isNew = !isset($previousData[$name]);
+2 -15
View File
@@ -37,11 +37,6 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
class ChoiceType extends AbstractType
{
/**
* Caches created choice lists.
*
* @var ChoiceListFactoryInterface
*/
private $choiceListFactory;
public function __construct(ChoiceListFactoryInterface $choiceListFactory = null)
@@ -116,6 +111,7 @@ class ChoiceType extends AbstractType
// Reconstruct the data as mapping from child names to values
$data = array();
/** @var FormInterface $child */
foreach ($form as $child) {
$value = $child->getConfig()->getOption('value');
@@ -284,7 +280,7 @@ class ChoiceType extends AbstractType
throw new \RuntimeException(sprintf('The "choices_as_values" option of the %s should not be used. Remove it and flip the contents of the "choices" option instead.', get_class($this)));
}
@trigger_error('The "choices_as_values" option is deprecated since version 3.1 and will be removed in 4.0. You should not use it anymore.', E_USER_DEPRECATED);
@trigger_error('The "choices_as_values" option is deprecated since Symfony 3.1 and will be removed in 4.0. You should not use it anymore.', E_USER_DEPRECATED);
return true;
};
@@ -368,10 +364,6 @@ class ChoiceType extends AbstractType
/**
* Adds the sub fields for an expanded choice field.
*
* @param FormBuilderInterface $builder The form builder
* @param array $choiceViews The choice view objects
* @param array $options The build options
*/
private function addSubForms(FormBuilderInterface $builder, array $choiceViews, array $options)
{
@@ -392,11 +384,6 @@ class ChoiceType extends AbstractType
}
/**
* @param FormBuilderInterface $builder
* @param $name
* @param $choiceView
* @param array $options
*
* @return mixed
*/
private function addSubForm(FormBuilderInterface $builder, $name, ChoiceView $choiceView, array $options)
+1 -1
View File
@@ -39,7 +39,7 @@ class CountryType extends AbstractType implements ChoiceLoaderInterface
$resolver->setDefaults(array(
'choice_loader' => function (Options $options) {
if ($options['choices']) {
@trigger_error(sprintf('Using the "choices" option in %s has been deprecated since version 3.3 and will be ignored in 4.0. Override the "choice_loader" option instead or set it to null.', __CLASS__), E_USER_DEPRECATED);
@trigger_error(sprintf('Using the "choices" option in %s has been deprecated since Symfony 3.3 and will be ignored in 4.0. Override the "choice_loader" option instead or set it to null.', __CLASS__), E_USER_DEPRECATED);
return null;
}
+1 -1
View File
@@ -39,7 +39,7 @@ class CurrencyType extends AbstractType implements ChoiceLoaderInterface
$resolver->setDefaults(array(
'choice_loader' => function (Options $options) {
if ($options['choices']) {
@trigger_error(sprintf('Using the "choices" option in %s has been deprecated since version 3.3 and will be ignored in 4.0. Override the "choice_loader" option instead or set it to null.', __CLASS__), E_USER_DEPRECATED);
@trigger_error(sprintf('Using the "choices" option in %s has been deprecated since Symfony 3.3 and will be ignored in 4.0. Override the "choice_loader" option instead or set it to null.', __CLASS__), E_USER_DEPRECATED);
return null;
}
@@ -178,7 +178,7 @@ class DateIntervalType extends AbstractType
{
$timeParts = $this->timeParts;
$compound = function (Options $options) {
return $options['widget'] !== 'single_text';
return 'single_text' !== $options['widget'];
};
$placeholderDefault = function (Options $options) {
@@ -30,7 +30,6 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
class DateTimeType extends AbstractType
{
const DEFAULT_DATE_FORMAT = \IntlDateFormatter::MEDIUM;
const DEFAULT_TIME_FORMAT = \IntlDateFormatter::MEDIUM;
/**
+1 -2
View File
@@ -27,7 +27,6 @@ use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
class DateType extends AbstractType
{
const DEFAULT_FORMAT = \IntlDateFormatter::MEDIUM;
const HTML5_FORMAT = 'yyyy-MM-dd';
private static $acceptedFormats = array(
@@ -286,7 +285,7 @@ class DateType extends AbstractType
private function formatTimestamps(\IntlDateFormatter $formatter, $regex, array $timestamps)
{
$pattern = $formatter->getPattern();
$timezone = $formatter->getTimezoneId();
$timezone = $formatter->getTimeZoneId();
$formattedTimestamps = array();
$formatter->setTimeZone('UTC');
+34 -11
View File
@@ -27,20 +27,40 @@ class FileType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if ($options['multiple']) {
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
$form = $event->getForm();
$data = $event->getData();
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use ($options) {
$form = $event->getForm();
$requestHandler = $form->getConfig()->getRequestHandler();
$data = null;
if ($options['multiple']) {
$data = array();
$files = $event->getData();
if (!is_array($files)) {
$files = array();
}
foreach ($files as $file) {
if ($requestHandler->isFileUpload($file)) {
$data[] = $file;
}
}
// submitted data for an input file (not required) without choosing any file
if (array(null) === $data) {
if (array(null) === $data || array() === $data) {
$emptyData = $form->getConfig()->getEmptyData();
$data = is_callable($emptyData) ? call_user_func($emptyData, $form, $data) : $emptyData;
$event->setData($data);
}
});
}
$event->setData($data);
} elseif (!$requestHandler->isFileUpload($event->getData())) {
$emptyData = $form->getConfig()->getEmptyData();
$data = is_callable($emptyData) ? call_user_func($emptyData, $form, $data) : $emptyData;
$event->setData($data);
}
});
}
/**
@@ -72,9 +92,12 @@ class FileType extends AbstractType
*/
public function configureOptions(OptionsResolver $resolver)
{
$dataClass = function (Options $options) {
return $options['multiple'] ? null : 'Symfony\Component\HttpFoundation\File\File';
};
$dataClass = null;
if (class_exists('Symfony\Component\HttpFoundation\File\File')) {
$dataClass = function (Options $options) {
return $options['multiple'] ? null : 'Symfony\Component\HttpFoundation\File\File';
};
}
$emptyData = function (Options $options) {
return $options['multiple'] ? array() : null;
-3
View File
@@ -24,9 +24,6 @@ use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
class FormType extends BaseType
{
/**
* @var PropertyAccessorInterface
*/
private $propertyAccessor;
public function __construct(PropertyAccessorInterface $propertyAccessor = null)
+1 -1
View File
@@ -39,7 +39,7 @@ class LanguageType extends AbstractType implements ChoiceLoaderInterface
$resolver->setDefaults(array(
'choice_loader' => function (Options $options) {
if ($options['choices']) {
@trigger_error(sprintf('Using the "choices" option in %s has been deprecated since version 3.3 and will be ignored in 4.0. Override the "choice_loader" option instead or set it to null.', __CLASS__), E_USER_DEPRECATED);
@trigger_error(sprintf('Using the "choices" option in %s has been deprecated since Symfony 3.3 and will be ignored in 4.0. Override the "choice_loader" option instead or set it to null.', __CLASS__), E_USER_DEPRECATED);
return null;
}
+1 -1
View File
@@ -39,7 +39,7 @@ class LocaleType extends AbstractType implements ChoiceLoaderInterface
$resolver->setDefaults(array(
'choice_loader' => function (Options $options) {
if ($options['choices']) {
@trigger_error(sprintf('Using the "choices" option in %s has been deprecated since version 3.3 and will be ignored in 4.0. Override the "choice_loader" option instead or set it to null.', __CLASS__), E_USER_DEPRECATED);
@trigger_error(sprintf('Using the "choices" option in %s has been deprecated since Symfony 3.3 and will be ignored in 4.0. Override the "choice_loader" option instead or set it to null.', __CLASS__), E_USER_DEPRECATED);
return null;
}
+2 -2
View File
@@ -36,7 +36,7 @@ class TimezoneType extends AbstractType implements ChoiceLoaderInterface
$resolver->setDefaults(array(
'choice_loader' => function (Options $options) {
if ($options['choices']) {
@trigger_error(sprintf('Using the "choices" option in %s has been deprecated since version 3.3 and will be ignored in 4.0. Override the "choice_loader" option instead or set it to null.', __CLASS__), E_USER_DEPRECATED);
@trigger_error(sprintf('Using the "choices" option in %s has been deprecated since Symfony 3.3 and will be ignored in 4.0. Override the "choice_loader" option instead or set it to null.', __CLASS__), E_USER_DEPRECATED);
return null;
}
@@ -72,7 +72,7 @@ class TimezoneType extends AbstractType implements ChoiceLoaderInterface
return $this->choiceList;
}
return $this->choiceList = new ArrayChoiceList($this->getTimezones(), $value);
return $this->choiceList = new ArrayChoiceList(self::getTimezones(), $value);
}
/**
-13
View File
@@ -22,24 +22,11 @@ use Symfony\Component\Translation\TranslatorInterface;
*/
class CsrfExtension extends AbstractExtension
{
/**
* @var CsrfTokenManagerInterface
*/
private $tokenManager;
/**
* @var TranslatorInterface
*/
private $translator;
/**
* @var null|string
*/
private $translationDomain;
/**
* Constructor.
*
* @param CsrfTokenManagerInterface $tokenManager The CSRF token manager
* @param TranslatorInterface $translator The translator for translating error messages
* @param null|string $translationDomain The translation domain for translating
@@ -25,50 +25,12 @@ use Symfony\Component\Translation\TranslatorInterface;
*/
class CsrfValidationListener implements EventSubscriberInterface
{
/**
* The name of the CSRF field.
*
* @var string
*/
private $fieldName;
/**
* The generator for CSRF tokens.
*
* @var CsrfTokenManagerInterface
*/
private $tokenManager;
/**
* A text mentioning the tokenId of the CSRF token.
*
* Validation of the token will only succeed if it was generated in the
* same session and with the same tokenId.
*
* @var string
*/
private $tokenId;
/**
* The message displayed in case of an error.
*
* @var string
*/
private $errorMessage;
/**
* @var TranslatorInterface
*/
private $translator;
/**
* @var null|string
*/
private $translationDomain;
/**
* @var ServerParams
*/
private $serverParams;
public static function getSubscribedEvents()
@@ -92,7 +54,7 @@ class CsrfValidationListener implements EventSubscriberInterface
public function preSubmit(FormEvent $event)
{
$form = $event->getForm();
$postRequestSizeExceeded = $form->getConfig()->getMethod() === 'POST' && $this->serverParams->hasPostMaxSizeBeenExceeded();
$postRequestSizeExceeded = 'POST' === $form->getConfig()->getMethod() && $this->serverParams->hasPostMaxSizeBeenExceeded();
if ($form->isRoot() && $form->getConfig()->getOption('compound') && !$postRequestSizeExceeded) {
$data = $event->getData();
@@ -26,36 +26,21 @@ use Symfony\Component\Translation\TranslatorInterface;
*/
class FormTypeCsrfExtension extends AbstractTypeExtension
{
/**
* @var CsrfTokenManagerInterface
*/
private $defaultTokenManager;
/**
* @var bool
*/
private $defaultEnabled;
/**
* @var string
*/
private $defaultFieldName;
/**
* @var TranslatorInterface
*/
private $translator;
/**
* @var null|string
*/
private $translationDomain;
/**
* @var ServerParams
*/
private $serverParams;
/**
* @param CsrfTokenManagerInterface $defaultTokenManager
* @param bool $defaultEnabled
* @param string $defaultFieldName
* @param TranslatorInterface $translator
* @param null|string $translationDomain
* @param ServerParams $serverParams
*/
public function __construct(CsrfTokenManagerInterface $defaultTokenManager, $defaultEnabled = true, $defaultFieldName = '_token', TranslatorInterface $translator = null, $translationDomain = null, ServerParams $serverParams = null)
{
$this->defaultTokenManager = $defaultTokenManager;
@@ -11,7 +11,6 @@
namespace Symfony\Component\Form\Extension\DataCollector;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\AbstractExtension;
/**
@@ -22,9 +21,6 @@ use Symfony\Component\Form\AbstractExtension;
*/
class DataCollectorExtension extends AbstractExtension
{
/**
* @var EventSubscriberInterface
*/
private $dataCollector;
public function __construct(FormDataCollectorInterface $dataCollector)
@@ -24,9 +24,6 @@ use Symfony\Component\Form\FormEvents;
*/
class DataCollectorListener implements EventSubscriberInterface
{
/**
* @var FormDataCollectorInterface
*/
private $dataCollector;
public function __construct(FormDataCollectorInterface $dataCollector)
@@ -49,8 +46,6 @@ class DataCollectorListener implements EventSubscriberInterface
/**
* Listener for the {@link FormEvents::POST_SET_DATA} event.
*
* @param FormEvent $event The event object
*/
public function postSetData(FormEvent $event)
{
@@ -65,8 +60,6 @@ class DataCollectorListener implements EventSubscriberInterface
/**
* Listener for the {@link FormEvents::POST_SUBMIT} event.
*
* @param FormEvent $event The event object
*/
public function postSubmit(FormEvent $event)
{
@@ -16,15 +16,10 @@ use Symfony\Component\Form\FormView;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter;
use Symfony\Component\Validator\ConstraintViolationInterface;
use Symfony\Component\VarDumper\Caster\Caster;
use Symfony\Component\VarDumper\Caster\ClassStub;
use Symfony\Component\VarDumper\Caster\CutStub;
use Symfony\Component\VarDumper\Cloner\ClonerInterface;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Cloner\Stub;
use Symfony\Component\VarDumper\Cloner\VarCloner;
/**
* Data collector for {@link FormInterface} instances.
@@ -34,9 +29,6 @@ use Symfony\Component\VarDumper\Cloner\VarCloner;
*/
class FormDataCollector extends DataCollector implements FormDataCollectorInterface
{
/**
* @var FormDataExtractor
*/
private $dataExtractor;
/**
@@ -72,16 +64,6 @@ class FormDataCollector extends DataCollector implements FormDataCollectorInterf
*/
private $formsByView;
/**
* @var ValueExporter
*/
private $valueExporter;
/**
* @var ClonerInterface
*/
private $cloner;
private $hasVarDumper;
public function __construct(FormDataExtractorInterface $dataExtractor)
@@ -255,61 +237,33 @@ class FormDataCollector extends DataCollector implements FormDataCollectorInterf
/**
* {@inheritdoc}
*/
protected function cloneVar($var, $isClass = false)
protected function getCasters()
{
if ($var instanceof Data) {
return $var;
}
if (null === $this->cloner) {
if ($this->hasVarDumper) {
$this->cloner = new VarCloner();
$this->cloner->setMaxItems(-1);
$this->cloner->addCasters(array(
'*' => function ($v, array $a, Stub $s, $isNested) {
foreach ($a as &$v) {
if (is_object($v) && !$v instanceof \DateTimeInterface) {
$v = new CutStub($v);
}
}
return parent::getCasters() + array(
\Exception::class => function (\Exception $e, array $a, Stub $s) {
foreach (array("\0Exception\0previous", "\0Exception\0trace") as $k) {
if (isset($a[$k])) {
unset($a[$k]);
++$s->cut;
}
}
return $a;
},
\Exception::class => function (\Exception $e, array $a, Stub $s) {
if (isset($a[$k = "\0Exception\0previous"])) {
unset($a[$k]);
++$s->cut;
}
return $a;
},
FormInterface::class => function (FormInterface $f, array $a) {
return array(
Caster::PREFIX_VIRTUAL.'name' => $f->getName(),
Caster::PREFIX_VIRTUAL.'type_class' => new ClassStub(get_class($f->getConfig()->getType()->getInnerType())),
);
},
ConstraintViolationInterface::class => function (ConstraintViolationInterface $v, array $a) {
return array(
Caster::PREFIX_VIRTUAL.'root' => $v->getRoot(),
Caster::PREFIX_VIRTUAL.'path' => $v->getPropertyPath(),
Caster::PREFIX_VIRTUAL.'value' => $v->getInvalidValue(),
);
},
));
} else {
@trigger_error(sprintf('Using the %s() method without the VarDumper component is deprecated since version 3.2 and won\'t be supported in 4.0. Install symfony/var-dumper version 3.2 or above.', __METHOD__), E_USER_DEPRECATED);
$this->cloner = false;
}
}
if (false !== $this->cloner) {
return $this->cloner->cloneVar($var, Caster::EXCLUDE_VERBOSE);
}
if (null === $this->valueExporter) {
$this->valueExporter = new ValueExporter();
}
return $this->valueExporter->exportValue($var);
return $a;
},
FormInterface::class => function (FormInterface $f, array $a) {
return array(
Caster::PREFIX_VIRTUAL.'name' => $f->getName(),
Caster::PREFIX_VIRTUAL.'type_class' => new ClassStub(get_class($f->getConfig()->getType()->getInnerType())),
);
},
ConstraintViolationInterface::class => function (ConstraintViolationInterface $v, array $a) {
return array(
Caster::PREFIX_VIRTUAL.'root' => $v->getRoot(),
Caster::PREFIX_VIRTUAL.'path' => $v->getPropertyPath(),
Caster::PREFIX_VIRTUAL.'value' => $v->getInvalidValue(),
);
},
);
}
private function &recursiveBuildPreliminaryFormTree(FormInterface $form, array &$outputByHash)
@@ -24,37 +24,26 @@ interface FormDataCollectorInterface extends DataCollectorInterface
{
/**
* Stores configuration data of the given form and its children.
*
* @param FormInterface $form A root form
*/
public function collectConfiguration(FormInterface $form);
/**
* Stores the default data of the given form and its children.
*
* @param FormInterface $form A root form
*/
public function collectDefaultData(FormInterface $form);
/**
* Stores the submitted data of the given form and its children.
*
* @param FormInterface $form A root form
*/
public function collectSubmittedData(FormInterface $form);
/**
* Stores the view variables of the given form view and its children.
*
* @param FormView $view A root form view
*/
public function collectViewVariables(FormView $view);
/**
* Specifies that the given objects represent the same conceptual form.
*
* @param FormInterface $form A form object
* @param FormView $view A view object
*/
public function associateFormWithView(FormInterface $form, FormView $view);
@@ -63,8 +52,6 @@ interface FormDataCollectorInterface extends DataCollectorInterface
* a tree-like data structure.
*
* The result can be queried using {@link getData()}.
*
* @param FormInterface $form A root form
*/
public function buildPreliminaryFormTree(FormInterface $form);
@@ -85,9 +72,6 @@ interface FormDataCollectorInterface extends DataCollectorInterface
* tree, only the view data will be included in the result. If a
* corresponding {@link FormInterface} exists otherwise, call
* {@link associateFormWithView()} before calling this method.
*
* @param FormInterface $form A root form
* @param FormView $view A root view
*/
public function buildFinalFormTree(FormInterface $form, FormView $view);
@@ -166,8 +166,6 @@ class FormDataExtractor implements FormDataExtractorInterface
/**
* Recursively builds an HTML ID for a form.
*
* @param FormInterface $form The form
*
* @return string The HTML ID
*/
private function buildId(FormInterface $form)
@@ -24,8 +24,6 @@ interface FormDataExtractorInterface
/**
* Extracts the configuration data of a form.
*
* @param FormInterface $form The form
*
* @return array Information about the form's configuration
*/
public function extractConfiguration(FormInterface $form);
@@ -33,8 +31,6 @@ interface FormDataExtractorInterface
/**
* Extracts the default data of a form.
*
* @param FormInterface $form The form
*
* @return array Information about the form's default data
*/
public function extractDefaultData(FormInterface $form);
@@ -42,8 +38,6 @@ interface FormDataExtractorInterface
/**
* Extracts the submitted data of a form.
*
* @param FormInterface $form The form
*
* @return array Information about the form's submitted data
*/
public function extractSubmittedData(FormInterface $form);
@@ -51,8 +45,6 @@ interface FormDataExtractorInterface
/**
* Extracts the view variables of a form.
*
* @param FormView $view The form view
*
* @return array Information about the view's variables
*/
public function extractViewVariables(FormView $view);
@@ -25,14 +25,7 @@ use Symfony\Component\Form\ResolvedFormTypeInterface;
*/
class ResolvedTypeDataCollectorProxy implements ResolvedFormTypeInterface
{
/**
* @var ResolvedFormTypeInterface
*/
private $proxiedType;
/**
* @var FormDataCollectorInterface
*/
private $dataCollector;
public function __construct(ResolvedFormTypeInterface $proxiedType, FormDataCollectorInterface $dataCollector)
@@ -24,14 +24,7 @@ use Symfony\Component\Form\ResolvedFormTypeInterface;
*/
class ResolvedTypeFactoryDataCollectorProxy implements ResolvedFormTypeFactoryInterface
{
/**
* @var ResolvedFormTypeFactoryInterface
*/
private $proxiedFactory;
/**
* @var FormDataCollectorInterface
*/
private $dataCollector;
public function __construct(ResolvedFormTypeFactoryInterface $proxiedFactory, FormDataCollectorInterface $dataCollector)
@@ -25,7 +25,7 @@ use Symfony\Component\Form\FormBuilderInterface;
class DataCollectorTypeExtension extends AbstractTypeExtension
{
/**
* @var \Symfony\Component\EventDispatcher\EventSubscriberInterface
* @var DataCollectorListener
*/
private $listener;
@@ -29,8 +29,6 @@ class DependencyInjectionExtension implements FormExtensionInterface
private $guesserServiceIds;
/**
* Constructor.
*
* @param ContainerInterface $typeContainer
* @param iterable[] $typeExtensionServices
* @param iterable $guesserServices
@@ -16,6 +16,7 @@ use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\RequestHandlerInterface;
use Symfony\Component\Form\Util\ServerParams;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\Request;
/**
@@ -26,14 +27,8 @@ use Symfony\Component\HttpFoundation\Request;
*/
class HttpFoundationRequestHandler implements RequestHandlerInterface
{
/**
* @var ServerParams
*/
private $serverParams;
/**
* {@inheritdoc}
*/
public function __construct(ServerParams $serverParams = null)
{
$this->serverParams = $serverParams ?: new ServerParams();
@@ -112,4 +107,12 @@ class HttpFoundationRequestHandler implements RequestHandlerInterface
$form->submit($data, 'PATCH' !== $method);
}
/**
* {@inheritdoc}
*/
public function isFileUpload($data)
{
return $data instanceof File;
}
}
@@ -21,14 +21,8 @@ use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler
*/
class FormTypeHttpFoundationExtension extends AbstractTypeExtension
{
/**
* @var RequestHandlerInterface
*/
private $requestHandler;
/**
* @param RequestHandlerInterface $requestHandler
*/
public function __construct(RequestHandlerInterface $requestHandler = null)
{
$this->requestHandler = $requestHandler ?: new HttpFoundationRequestHandler();
@@ -20,9 +20,6 @@ use Symfony\Component\Templating\EngineInterface;
*/
class TemplatingRendererEngine extends AbstractRendererEngine
{
/**
* @var EngineInterface
*/
private $engine;
public function __construct(EngineInterface $engine, array $defaultThemes = array())
@@ -56,28 +56,44 @@ class FormValidator extends ConstraintValidator
// Validate the data against the constraints defined
// in the form
$constraints = $config->getOption('constraints', array());
foreach ($constraints as $constraint) {
// For the "Valid" constraint, validate the data in all groups
if ($constraint instanceof Valid) {
$validator->atPath('data')->validate($form->getData(), $constraint, $groups);
continue;
}
if ($groups instanceof GroupSequence) {
$validator->atPath('data')->validate($form->getData(), $constraints, $groups);
// Otherwise validate a constraint only once for the first
// matching group
foreach ($groups as $group) {
if (in_array($group, $constraint->groups)) {
$validator->atPath('data')->validate($form->getData(), $constraint, $group);
if (count($this->context->getViolations()) > 0) {
break;
}
}
}
} else {
foreach ($constraints as $constraint) {
// For the "Valid" constraint, validate the data in all groups
if ($constraint instanceof Valid) {
$validator->atPath('data')->validate($form->getData(), $constraint, $groups);
// Prevent duplicate validation
continue 2;
continue;
}
// Otherwise validate a constraint only once for the first
// matching group
foreach ($groups as $group) {
if (in_array($group, $constraint->groups)) {
$validator->atPath('data')->validate($form->getData(), $constraint, $group);
// Prevent duplicate validation
continue 2;
}
}
}
}
} else {
$childrenSynchronized = true;
/** @var FormInterface $child */
foreach ($form as $child) {
if (!$child->isSynchronized()) {
$childrenSynchronized = false;
@@ -119,8 +135,6 @@ class FormValidator extends ConstraintValidator
/**
* Returns the validation groups of the given form.
*
* @param FormInterface $form The form
*
* @return array The validation groups
*/
private static function getValidationGroups(FormInterface $form)
@@ -23,14 +23,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
*/
class FormTypeValidatorExtension extends BaseValidatorExtension
{
/**
* @var ValidatorInterface
*/
private $validator;
/**
* @var ViolationMapper
*/
private $violationMapper;
public function __construct(ValidatorInterface $validator)
@@ -73,8 +73,6 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
/**
* Guesses a field class name for a given constraint.
*
* @param Constraint $constraint The constraint to guess for
*
* @return TypeGuess|null The guessed field class and options
*/
public function guessTypeForConstraint(Constraint $constraint)
@@ -151,8 +149,6 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
case 'Symfony\Component\Validator\Constraints\Count':
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\CollectionType', array(), Guess::LOW_CONFIDENCE);
case 'Symfony\Component\Validator\Constraints\True':
case 'Symfony\Component\Validator\Constraints\False':
case 'Symfony\Component\Validator\Constraints\IsTrue':
case 'Symfony\Component\Validator\Constraints\IsFalse':
return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\CheckboxType', array(), Guess::MEDIUM_CONFIDENCE);
@@ -162,8 +158,6 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
/**
* Guesses whether a field is required based on the given constraint.
*
* @param Constraint $constraint The constraint to guess for
*
* @return ValueGuess|null The guess whether the field is required
*/
public function guessRequiredForConstraint(Constraint $constraint)
@@ -171,7 +165,6 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
switch (get_class($constraint)) {
case 'Symfony\Component\Validator\Constraints\NotNull':
case 'Symfony\Component\Validator\Constraints\NotBlank':
case 'Symfony\Component\Validator\Constraints\True':
case 'Symfony\Component\Validator\Constraints\IsTrue':
return new ValueGuess(true, Guess::HIGH_CONFIDENCE);
}
@@ -180,8 +173,6 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
/**
* Guesses a field's maximum length based on the given constraint.
*
* @param Constraint $constraint The constraint to guess for
*
* @return ValueGuess|null The guess for the maximum length
*/
public function guessMaxLengthForConstraint(Constraint $constraint)
@@ -210,8 +201,6 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
/**
* Guesses a field's pattern based on the given constraint.
*
* @param Constraint $constraint The constraint to guess for
*
* @return ValueGuess|null The guess for the pattern
*/
public function guessPatternForConstraint(Constraint $constraint)
@@ -254,7 +243,7 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
* @param \Closure $closure The closure that returns a guess
* for a given constraint
* @param mixed $defaultValue The default value assumed if no other value
* can be guessed.
* can be guessed
*
* @return Guess|null The guessed value with the highest confidence
*/
@@ -19,21 +19,15 @@ use Symfony\Component\Form\Exception\ErrorMappingException;
*/
class MappingRule
{
/**
* @var FormInterface
*/
private $origin;
/**
* @var string
*/
private $propertyPath;
/**
* @var string
*/
private $targetPath;
/**
* @param FormInterface $origin
* @param string $propertyPath
* @param string $targetPath
*/
public function __construct(FormInterface $origin, $propertyPath, $targetPath)
{
$this->origin = $origin;
@@ -19,9 +19,6 @@ use Symfony\Component\PropertyAccess\PropertyPath;
*/
class RelativePath extends PropertyPath
{
/**
* @var FormInterface
*/
private $root;
/**
@@ -269,8 +269,6 @@ class ViolationMapper implements ViolationMapperInterface
}
/**
* @param FormInterface $form
*
* @return bool
*/
private function acceptsErrors(FormInterface $form)
@@ -24,10 +24,8 @@ interface ViolationMapperInterface
* the given form.
*
* @param ConstraintViolation $violation The violation to map
* @param FormInterface $form The root form of the tree
* to map it to.
* @param bool $allowNonSynchronized Whether to allow
* mapping to non-synchronized forms.
* @param FormInterface $form The root form of the tree to map it to
* @param bool $allowNonSynchronized Whether to allow mapping to non-synchronized forms
*/
public function mapViolation(ConstraintViolation $violation, FormInterface $form, $allowNonSynchronized = false);
}
@@ -48,8 +48,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
/**
* Creates a new violation path from a string.
*
* @param string $violationPath The property path of a {@link \Symfony\Component\Validator\ConstraintViolation}
* object.
* @param string $violationPath The property path of a {@link \Symfony\Component\Validator\ConstraintViolation} object
*/
public function __construct($violationPath)
{
@@ -210,7 +209,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
*
* @return bool Whether the element maps to a form
*
* @throws OutOfBoundsException If the offset is invalid.
* @throws OutOfBoundsException if the offset is invalid
*/
public function mapsForm($index)
{