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
+21
View File
@@ -1,6 +1,26 @@
CHANGELOG
=========
4.0.0
-----
* Setting the `strict` option of the `Choice` constraint to anything but `true`
is not supported anymore.
* removed the `DateTimeValidator::PATTERN` constant
* removed the `AbstractConstraintValidatorTest` class
* removed support for setting the `checkDNS` option of the `Url` constraint to `true`
3.4.0
-----
* added support for validation groups to the `Valid` constraint
* not setting the `strict` option of the `Choice` constraint to `true` is
deprecated and will throw an exception in Symfony 4.0
* setting the `checkDNS` option of the `Url` constraint to `true` is deprecated in favor of
the `Url::CHECK_DNS_TYPE_*` constants values and will throw an exception in Symfony 4.0
* added min/max amount of pixels check to `Image` constraint via `minPixels` and `maxPixels`
* added a new "propertyPath" option to comparison constraints in order to get the value to compare from an array or object
3.3.0
-----
@@ -12,6 +32,7 @@ CHANGELOG
-----
* deprecated `Tests\Constraints\AbstractContraintValidatorTest` in favor of `Test\ConstraintValidatorTestCase`
* added support for PHP constants in YAML configuration files
3.1.0
-----
+14 -14
View File
@@ -73,7 +73,7 @@ abstract class Constraint
throw new InvalidArgumentException(sprintf(
'The error code "%s" does not exist for constraint of type "%s".',
$errorCode,
get_called_class()
\get_called_class()
));
}
@@ -116,15 +116,15 @@ abstract class Constraint
// The "groups" option is added to the object lazily
$knownOptions['groups'] = true;
if (is_array($options) && count($options) >= 1 && isset($options['value']) && !property_exists($this, 'value')) {
if (\is_array($options) && \count($options) >= 1 && isset($options['value']) && !property_exists($this, 'value')) {
$options[$this->getDefaultOption()] = $options['value'];
unset($options['value']);
}
if (is_array($options)) {
if (\is_array($options)) {
reset($options);
}
if (is_array($options) && count($options) > 0 && is_string(key($options))) {
if (\is_array($options) && \count($options) > 0 && \is_string(key($options))) {
foreach ($options as $option => $value) {
if (array_key_exists($option, $knownOptions)) {
$this->$option = $value;
@@ -133,12 +133,12 @@ abstract class Constraint
$invalidOptions[] = $option;
}
}
} elseif (null !== $options && !(is_array($options) && 0 === count($options))) {
} elseif (null !== $options && !(\is_array($options) && 0 === \count($options))) {
$option = $this->getDefaultOption();
if (null === $option) {
throw new ConstraintDefinitionException(
sprintf('No default option is configured for constraint %s', get_class($this))
sprintf('No default option is configured for constraint %s', \get_class($this))
);
}
@@ -150,16 +150,16 @@ abstract class Constraint
}
}
if (count($invalidOptions) > 0) {
if (\count($invalidOptions) > 0) {
throw new InvalidOptionsException(
sprintf('The options "%s" do not exist in constraint %s', implode('", "', $invalidOptions), get_class($this)),
sprintf('The options "%s" do not exist in constraint %s', implode('", "', $invalidOptions), \get_class($this)),
$invalidOptions
);
}
if (count($missingOptions) > 0) {
if (\count($missingOptions) > 0) {
throw new MissingOptionsException(
sprintf('The options "%s" must be set for constraint %s', implode('", "', array_keys($missingOptions)), get_class($this)),
sprintf('The options "%s" must be set for constraint %s', implode('", "', array_keys($missingOptions)), \get_class($this)),
array_keys($missingOptions)
);
}
@@ -185,7 +185,7 @@ abstract class Constraint
return;
}
throw new InvalidOptionsException(sprintf('The option "%s" does not exist in constraint %s', $option, get_class($this)), array($option));
throw new InvalidOptionsException(sprintf('The option "%s" does not exist in constraint %s', $option, \get_class($this)), array($option));
}
/**
@@ -211,7 +211,7 @@ abstract class Constraint
return $this->groups;
}
throw new InvalidOptionsException(sprintf('The option "%s" does not exist in constraint %s', $option, get_class($this)), array($option));
throw new InvalidOptionsException(sprintf('The option "%s" does not exist in constraint %s', $option, \get_class($this)), array($option));
}
/**
@@ -231,7 +231,7 @@ abstract class Constraint
*/
public function addImplicitGroupName($group)
{
if (in_array(self::DEFAULT_GROUP, $this->groups) && !in_array($group, $this->groups)) {
if (\in_array(self::DEFAULT_GROUP, $this->groups) && !\in_array($group, $this->groups)) {
$this->groups[] = $group;
}
}
@@ -274,7 +274,7 @@ abstract class Constraint
*/
public function validatedBy()
{
return get_class($this).'Validator';
return \get_class($this).'Validator';
}
/**
+5 -5
View File
@@ -58,7 +58,7 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
*/
protected function formatTypeOf($value)
{
return is_object($value) ? get_class($value) : gettype($value);
return \is_object($value) ? \get_class($value) : \gettype($value);
}
/**
@@ -107,7 +107,7 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
return $value->format('Y-m-d H:i:s');
}
if (is_object($value)) {
if (\is_object($value)) {
if (($format & self::OBJECT_TO_STRING) && method_exists($value, '__toString')) {
return $value->__toString();
}
@@ -115,15 +115,15 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
return 'object';
}
if (is_array($value)) {
if (\is_array($value)) {
return 'array';
}
if (is_string($value)) {
if (\is_string($value)) {
return '"'.$value.'"';
}
if (is_resource($value)) {
if (\is_resource($value)) {
return 'resource';
}
+4 -4
View File
@@ -49,7 +49,7 @@ class ConstraintViolation implements ConstraintViolationInterface
* caused the violation
* @param mixed $cause The cause of the violation
*/
public function __construct($message, $messageTemplate, array $parameters, $root, $propertyPath, $invalidValue, $plural = null, $code = null, Constraint $constraint = null, $cause = null)
public function __construct(?string $message, ?string $messageTemplate, array $parameters, $root, ?string $propertyPath, $invalidValue, int $plural = null, $code = null, Constraint $constraint = null, $cause = null)
{
$this->message = $message;
$this->messageTemplate = $messageTemplate;
@@ -70,9 +70,9 @@ class ConstraintViolation implements ConstraintViolationInterface
*/
public function __toString()
{
if (is_object($this->root)) {
$class = 'Object('.get_class($this->root).')';
} elseif (is_array($this->root)) {
if (\is_object($this->root)) {
$class = 'Object('.\get_class($this->root).')';
} elseif (\is_array($this->root)) {
$class = 'Array';
} else {
$class = (string) $this->root;
+2 -2
View File
@@ -120,7 +120,7 @@ class ConstraintViolationList implements \IteratorAggregate, ConstraintViolation
*/
public function count()
{
return count($this->violations);
return \count($this->violations);
}
/**
@@ -171,7 +171,7 @@ class ConstraintViolationList implements \IteratorAggregate, ConstraintViolation
$codes = (array) $codes;
$violations = array();
foreach ($this as $violation) {
if (in_array($violation->getCode(), $codes, true)) {
if (\in_array($violation->getCode(), $codes, true)) {
$violations[] = $violation;
}
}
@@ -26,7 +26,7 @@ interface ConstraintViolationListInterface extends \Traversable, \Countable, \Ar
/**
* Merges an existing violation list into this list.
*/
public function addAll(ConstraintViolationListInterface $otherList);
public function addAll(self $otherList);
/**
* Returns the violation at a given offset.
+14 -5
View File
@@ -11,6 +11,7 @@
namespace Symfony\Component\Validator\Constraints;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
@@ -24,6 +25,7 @@ abstract class AbstractComparison extends Constraint
{
public $message;
public $value;
public $propertyPath;
/**
* {@inheritdoc}
@@ -34,11 +36,18 @@ abstract class AbstractComparison extends Constraint
$options = array();
}
if (is_array($options) && !isset($options['value'])) {
throw new ConstraintDefinitionException(sprintf(
'The %s constraint requires the "value" option to be set.',
get_class($this)
));
if (\is_array($options)) {
if (!isset($options['value']) && !isset($options['propertyPath'])) {
throw new ConstraintDefinitionException(sprintf('The "%s" constraint requires either the "value" or "propertyPath" option to be set.', \get_class($this)));
}
if (isset($options['value']) && isset($options['propertyPath'])) {
throw new ConstraintDefinitionException(sprintf('The "%s" constraint requires only one of the "value" or "propertyPath" options to be set, not both.', \get_class($this)));
}
if (isset($options['propertyPath']) && !class_exists(PropertyAccess::class)) {
throw new ConstraintDefinitionException(sprintf('The "%s" constraint requires the Symfony PropertyAccess component to use the "propertyPath" option.', \get_class($this)));
}
}
parent::__construct($options);
@@ -11,8 +11,12 @@
namespace Symfony\Component\Validator\Constraints;
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessor;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
/**
@@ -23,6 +27,13 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException;
*/
abstract class AbstractComparisonValidator extends ConstraintValidator
{
private $propertyAccessor;
public function __construct(PropertyAccessor $propertyAccessor = null)
{
$this->propertyAccessor = $propertyAccessor;
}
/**
* {@inheritdoc}
*/
@@ -36,13 +47,25 @@ abstract class AbstractComparisonValidator extends ConstraintValidator
return;
}
$comparedValue = $constraint->value;
if ($path = $constraint->propertyPath) {
if (null === $object = $this->context->getObject()) {
return;
}
try {
$comparedValue = $this->getPropertyAccessor()->getValue($object, $path);
} catch (NoSuchPropertyException $e) {
throw new ConstraintDefinitionException(sprintf('Invalid property path "%s" provided to "%s" constraint: %s', $path, \get_class($constraint), $e->getMessage()), 0, $e);
}
} else {
$comparedValue = $constraint->value;
}
// Convert strings to DateTimes if comparing another DateTime
// This allows to compare with any date/time value supported by
// the DateTime constructor:
// http://php.net/manual/en/datetime.formats.php
if (is_string($comparedValue)) {
if (\is_string($comparedValue)) {
if ($value instanceof \DateTimeImmutable) {
// If $value is immutable, convert the compared value to a
// DateTimeImmutable too
@@ -63,6 +86,15 @@ abstract class AbstractComparisonValidator extends ConstraintValidator
}
}
private function getPropertyAccessor()
{
if (null === $this->propertyAccessor) {
$this->propertyAccessor = PropertyAccess::createPropertyAccessor();
}
return $this->propertyAccessor;
}
/**
* Compares the two given values to find if their relationship is valid.
*
+1 -1
View File
@@ -33,7 +33,7 @@ class AllValidator extends ConstraintValidator
return;
}
if (!is_array($value) && !$value instanceof \Traversable) {
if (!\is_array($value) && !$value instanceof \Traversable) {
throw new UnexpectedTypeException($value, 'array or Traversable');
}
+1 -1
View File
@@ -33,7 +33,7 @@ class BicValidator extends ConstraintValidator
$canonicalize = str_replace(' ', '', $value);
// the bic must be either 8 or 11 characters long
if (!in_array(strlen($canonicalize), array(8, 11))) {
if (!\in_array(\strlen($canonicalize), array(8, 11))) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Bic::INVALID_LENGTH_ERROR)
+2 -2
View File
@@ -32,11 +32,11 @@ class Callback extends Constraint
public function __construct($options = null)
{
// Invocation through annotations with an array parameter only
if (is_array($options) && 1 === count($options) && isset($options['value'])) {
if (\is_array($options) && 1 === \count($options) && isset($options['value'])) {
$options = $options['value'];
}
if (is_array($options) && !isset($options['callback']) && !isset($options['groups']) && !isset($options['payload'])) {
if (\is_array($options) && !isset($options['callback']) && !isset($options['groups']) && !isset($options['payload'])) {
$options = array('callback' => $options);
}
+6 -6
View File
@@ -35,18 +35,18 @@ class CallbackValidator extends ConstraintValidator
$method = $constraint->callback;
if ($method instanceof \Closure) {
$method($object, $this->context, $constraint->payload);
} elseif (is_array($method)) {
if (!is_callable($method)) {
if (isset($method[0]) && is_object($method[0])) {
$method[0] = get_class($method[0]);
} elseif (\is_array($method)) {
if (!\is_callable($method)) {
if (isset($method[0]) && \is_object($method[0])) {
$method[0] = \get_class($method[0]);
}
throw new ConstraintDefinitionException(sprintf('%s targeted by Callback constraint is not a valid callable', json_encode($method)));
}
call_user_func($method, $object, $this->context, $constraint->payload);
\call_user_func($method, $object, $this->context, $constraint->payload);
} elseif (null !== $object) {
if (!method_exists($object, $method)) {
throw new ConstraintDefinitionException(sprintf('Method "%s" targeted by Callback constraint does not exist in class %s', $method, get_class($object)));
throw new ConstraintDefinitionException(sprintf('Method "%s" targeted by Callback constraint does not exist in class %s', $method, \get_class($object)));
}
$reflMethod = new \ReflectionMethod($object, $method);
+1 -1
View File
@@ -34,7 +34,7 @@ class Choice extends Constraint
public $choices;
public $callback;
public $multiple = false;
public $strict = false;
public $strict = true;
public $min;
public $max;
public $message = 'The value you selected is not a valid choice.';
+11 -11
View File
@@ -34,7 +34,7 @@ class ChoiceValidator extends ConstraintValidator
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Choice');
}
if (!is_array($constraint->choices) && !$constraint->callback) {
if (!\is_array($constraint->choices) && !$constraint->callback) {
throw new ConstraintDefinitionException('Either "choices" or "callback" must be specified on constraint Choice');
}
@@ -42,29 +42,29 @@ class ChoiceValidator extends ConstraintValidator
return;
}
if ($constraint->multiple && !is_array($value)) {
if ($constraint->multiple && !\is_array($value)) {
throw new UnexpectedTypeException($value, 'array');
}
if ($constraint->callback) {
if (!is_callable($choices = array($this->context->getObject(), $constraint->callback))
&& !is_callable($choices = array($this->context->getClassName(), $constraint->callback))
&& !is_callable($choices = $constraint->callback)
if (!\is_callable($choices = array($this->context->getObject(), $constraint->callback))
&& !\is_callable($choices = array($this->context->getClassName(), $constraint->callback))
&& !\is_callable($choices = $constraint->callback)
) {
throw new ConstraintDefinitionException('The Choice constraint expects a valid callback');
}
$choices = call_user_func($choices);
$choices = \call_user_func($choices);
} else {
$choices = $constraint->choices;
}
if (false === $constraint->strict) {
@trigger_error('Setting the strict option of the Choice constraint to false is deprecated since Symfony 3.2 and will be removed in 4.0.', E_USER_DEPRECATED);
if (true !== $constraint->strict) {
throw new \RuntimeException('The "strict" option of the Choice constraint should not be used.');
}
if ($constraint->multiple) {
foreach ($value as $_value) {
if (!in_array($_value, $choices, $constraint->strict)) {
if (!\in_array($_value, $choices, true)) {
$this->context->buildViolation($constraint->multipleMessage)
->setParameter('{{ value }}', $this->formatValue($_value))
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
@@ -75,7 +75,7 @@ class ChoiceValidator extends ConstraintValidator
}
}
$count = count($value);
$count = \count($value);
if (null !== $constraint->min && $count < $constraint->min) {
$this->context->buildViolation($constraint->minMessage)
@@ -96,7 +96,7 @@ class ChoiceValidator extends ConstraintValidator
return;
}
} elseif (!in_array($value, $choices, $constraint->strict)) {
} elseif (!\in_array($value, $choices, true)) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
+3 -3
View File
@@ -41,7 +41,7 @@ class Collection extends Composite
public function __construct($options = null)
{
// no known options set? $options is the fields array
if (is_array($options)
if (\is_array($options)
&& !array_intersect(array_keys($options), array('groups', 'fields', 'allowExtraFields', 'allowMissingFields', 'extraFieldsMessage', 'missingFieldsMessage'))) {
$options = array('fields' => $options);
}
@@ -56,14 +56,14 @@ class Collection extends Composite
{
parent::initializeNestedConstraints();
if (!is_array($this->fields)) {
if (!\is_array($this->fields)) {
throw new ConstraintDefinitionException(sprintf('The option "fields" is expected to be an array in constraint %s', __CLASS__));
}
foreach ($this->fields as $fieldName => $field) {
// the XmlFileLoader and YamlFileLoader pass the field Optional
// and Required constraint as an array with exactly one element
if (is_array($field) && 1 == count($field)) {
if (\is_array($field) && 1 == \count($field)) {
$this->fields[$fieldName] = $field = $field[0];
}
@@ -33,7 +33,7 @@ class CollectionValidator extends ConstraintValidator
return;
}
if (!is_array($value) && !($value instanceof \Traversable && $value instanceof \ArrayAccess)) {
if (!\is_array($value) && !($value instanceof \Traversable && $value instanceof \ArrayAccess)) {
throw new UnexpectedTypeException($value, 'array or Traversable and ArrayAccess');
}
@@ -50,11 +50,11 @@ class CollectionValidator extends ConstraintValidator
foreach ($constraint->fields as $field => $fieldConstraint) {
// bug fix issue #2779
$existsInArray = is_array($value) && array_key_exists($field, $value);
$existsInArray = \is_array($value) && array_key_exists($field, $value);
$existsInArrayAccess = $value instanceof \ArrayAccess && $value->offsetExists($field);
if ($existsInArray || $existsInArrayAccess) {
if (count($fieldConstraint->constraints) > 0) {
if (\count($fieldConstraint->constraints) > 0) {
$context->getValidator()
->inContext($context)
->atPath('['.$field.']')
+8 -8
View File
@@ -61,21 +61,21 @@ abstract class Composite extends Constraint
$compositeOption = $this->getCompositeOption();
$nestedConstraints = $this->$compositeOption;
if (!is_array($nestedConstraints)) {
if (!\is_array($nestedConstraints)) {
$nestedConstraints = array($nestedConstraints);
}
foreach ($nestedConstraints as $constraint) {
if (!$constraint instanceof Constraint) {
if (is_object($constraint)) {
$constraint = get_class($constraint);
if (\is_object($constraint)) {
$constraint = \get_class($constraint);
}
throw new ConstraintDefinitionException(sprintf('The value %s is not an instance of Constraint in constraint %s', $constraint, get_class($this)));
throw new ConstraintDefinitionException(sprintf('The value %s is not an instance of Constraint in constraint %s', $constraint, \get_class($this)));
}
if ($constraint instanceof Valid) {
throw new ConstraintDefinitionException(sprintf('The constraint Valid cannot be nested inside constraint %s. You can only declare the Valid constraint directly on a field or method.', get_class($this)));
throw new ConstraintDefinitionException(sprintf('The constraint Valid cannot be nested inside constraint %s. You can only declare the Valid constraint directly on a field or method.', \get_class($this)));
}
}
@@ -98,13 +98,13 @@ abstract class Composite extends Constraint
if (property_exists($constraint, 'groups')) {
$excessGroups = array_diff($constraint->groups, $this->groups);
if (count($excessGroups) > 0) {
if (\count($excessGroups) > 0) {
throw new ConstraintDefinitionException(sprintf(
'The group(s) "%s" passed to the constraint %s '.
'should also be passed to its containing constraint %s',
implode('", "', $excessGroups),
get_class($constraint),
get_class($this)
\get_class($constraint),
\get_class($this)
));
}
} else {
+1 -1
View File
@@ -38,7 +38,7 @@ class Count extends Constraint
public function __construct($options = null)
{
if (null !== $options && !is_array($options)) {
if (null !== $options && !\is_array($options)) {
$options = array(
'min' => $options,
'max' => $options,
+2 -2
View File
@@ -29,11 +29,11 @@ class CountValidator extends ConstraintValidator
return;
}
if (!is_array($value) && !$value instanceof \Countable) {
if (!\is_array($value) && !$value instanceof \Countable) {
throw new UnexpectedTypeException($value, 'array or \Countable');
}
$count = count($value);
$count = \count($value);
if (null !== $constraint->max && $count > $constraint->max) {
$this->context->buildViolation($constraint->min == $constraint->max ? $constraint->exactMessage : $constraint->maxMessage)
+1 -1
View File
@@ -36,7 +36,7 @@ class CountryValidator extends ConstraintValidator
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
+1 -1
View File
@@ -37,7 +37,7 @@ class CurrencyValidator extends ConstraintValidator
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
+1 -6
View File
@@ -20,11 +20,6 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException;
*/
class DateTimeValidator extends DateValidator
{
/**
* @deprecated since version 3.1, to be removed in 4.0.
*/
const PATTERN = '/^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/';
/**
* {@inheritdoc}
*/
@@ -38,7 +33,7 @@ class DateTimeValidator extends DateValidator
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
+1 -1
View File
@@ -51,7 +51,7 @@ class DateValidator extends ConstraintValidator
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
+4 -15
View File
@@ -25,10 +25,7 @@ class EmailValidator extends ConstraintValidator
{
private $isStrict;
/**
* @param bool $strict
*/
public function __construct($strict = false)
public function __construct(bool $strict = false)
{
$this->isStrict = $strict;
}
@@ -46,7 +43,7 @@ class EmailValidator extends ConstraintValidator
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
@@ -111,24 +108,16 @@ class EmailValidator extends ConstraintValidator
/**
* Check DNS Records for MX type.
*
* @param string $host Host
*
* @return bool
*/
private function checkMX($host)
private function checkMX(string $host): bool
{
return '' !== $host && checkdnsrr($host, 'MX');
}
/**
* Check if one of MX, A or AAAA DNS RR exists.
*
* @param string $host Host
*
* @return bool
*/
private function checkHost($host)
private function checkHost(string $host): bool
{
return '' !== $host && ($this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA')));
}
+4 -1
View File
@@ -59,6 +59,9 @@ class File extends Constraint
protected $maxSize;
/**
* {@inheritdoc}
*/
public function __construct($options = null)
{
parent::__construct($options);
@@ -110,7 +113,7 @@ class File extends Constraint
$this->binaryFormat = null === $this->binaryFormat ? false : $this->binaryFormat;
} elseif (preg_match('/^(\d++)('.implode('|', array_keys($factors)).')$/i', $maxSize, $matches)) {
$this->maxSize = $matches[1] * $factors[$unit = strtolower($matches[2])];
$this->binaryFormat = null === $this->binaryFormat ? 2 === strlen($unit) : $this->binaryFormat;
$this->binaryFormat = null === $this->binaryFormat ? 2 === \strlen($unit) : $this->binaryFormat;
} else {
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum size', $this->maxSize));
}
+2 -2
View File
@@ -113,7 +113,7 @@ class FileValidator extends ConstraintValidator
}
}
if (!is_scalar($value) && !$value instanceof FileObject && !(is_object($value) && method_exists($value, '__toString'))) {
if (!is_scalar($value) && !$value instanceof FileObject && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
@@ -196,7 +196,7 @@ class FileValidator extends ConstraintValidator
private static function moreDecimalsThan($double, $numberOfDecimals)
{
return strlen((string) $double) > strlen(round($double, $numberOfDecimals));
return \strlen((string) $double) > \strlen(round($double, $numberOfDecimals));
}
/**
+2 -2
View File
@@ -148,7 +148,7 @@ class IbanValidator extends ConstraintValidator
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
@@ -231,7 +231,7 @@ class IbanValidator extends ConstraintValidator
foreach ($chars as $char) {
// Convert uppercase characters to ordinals, starting with 10 for "A"
if (ctype_upper($char)) {
$bigInt .= (ord($char) - 55);
$bigInt .= (\ord($char) - 55);
continue;
}
+8
View File
@@ -25,6 +25,8 @@ class Image extends File
const TOO_NARROW_ERROR = '9afbd561-4f90-4a27-be62-1780fc43604a';
const TOO_HIGH_ERROR = '7efae81c-4877-47ba-aa65-d01ccb0d4645';
const TOO_LOW_ERROR = 'aef0cb6a-c07f-4894-bc08-1781420d7b4c';
const TOO_FEW_PIXEL_ERROR = '1b06b97d-ae48-474e-978f-038a74854c43';
const TOO_MANY_PIXEL_ERROR = 'ee0804e8-44db-4eac-9775-be91aaf72ce1';
const RATIO_TOO_BIG_ERROR = '70cafca6-168f-41c9-8c8c-4e47a52be643';
const RATIO_TOO_SMALL_ERROR = '59b8c6ef-bcf2-4ceb-afff-4642ed92f12e';
const SQUARE_NOT_ALLOWED_ERROR = '5d41425b-facb-47f7-a55a-de9fbe45cb46';
@@ -45,6 +47,8 @@ class Image extends File
self::TOO_NARROW_ERROR => 'TOO_NARROW_ERROR',
self::TOO_HIGH_ERROR => 'TOO_HIGH_ERROR',
self::TOO_LOW_ERROR => 'TOO_LOW_ERROR',
self::TOO_FEW_PIXEL_ERROR => 'TOO_FEW_PIXEL_ERROR',
self::TOO_MANY_PIXEL_ERROR => 'TOO_MANY_PIXEL_ERROR',
self::RATIO_TOO_BIG_ERROR => 'RATIO_TOO_BIG_ERROR',
self::RATIO_TOO_SMALL_ERROR => 'RATIO_TOO_SMALL_ERROR',
self::SQUARE_NOT_ALLOWED_ERROR => 'SQUARE_NOT_ALLOWED_ERROR',
@@ -60,6 +64,8 @@ class Image extends File
public $minHeight;
public $maxRatio;
public $minRatio;
public $minPixels;
public $maxPixels;
public $allowSquare = true;
public $allowLandscape = true;
public $allowPortrait = true;
@@ -72,6 +78,8 @@ class Image extends File
public $minWidthMessage = 'The image width is too small ({{ width }}px). Minimum width expected is {{ min_width }}px.';
public $maxHeightMessage = 'The image height is too big ({{ height }}px). Allowed maximum height is {{ max_height }}px.';
public $minHeightMessage = 'The image height is too small ({{ height }}px). Minimum height expected is {{ min_height }}px.';
public $minPixelsMessage = 'The image has too few pixels ({{ pixels }} pixels). Minimum amount expected is {{ min_pixels }} pixels.';
public $maxPixelsMessage = 'The image has too many pixels ({{ pixels }} pixels). Maximum amount expected is {{ max_pixels }} pixels.';
public $maxRatioMessage = 'The image ratio is too big ({{ ratio }}). Allowed maximum ratio is {{ max_ratio }}.';
public $minRatioMessage = 'The image ratio is too small ({{ ratio }}). Minimum ratio expected is {{ min_ratio }}.';
public $allowSquareMessage = 'The image is square ({{ width }}x{{ height }}px). Square images are not allowed.';
+40 -5
View File
@@ -34,11 +34,11 @@ class ImageValidator extends FileValidator
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Image');
}
$violations = count($this->context->getViolations());
$violations = \count($this->context->getViolations());
parent::validate($value, $constraint);
$failed = count($this->context->getViolations()) !== $violations;
$failed = \count($this->context->getViolations()) !== $violations;
if ($failed || null === $value || '' === $value) {
return;
@@ -46,6 +46,7 @@ class ImageValidator extends FileValidator
if (null === $constraint->minWidth && null === $constraint->maxWidth
&& null === $constraint->minHeight && null === $constraint->maxHeight
&& null === $constraint->minPixels && null === $constraint->maxPixels
&& null === $constraint->minRatio && null === $constraint->maxRatio
&& $constraint->allowSquare && $constraint->allowLandscape && $constraint->allowPortrait
&& !$constraint->detectCorrupted) {
@@ -67,7 +68,7 @@ class ImageValidator extends FileValidator
if ($constraint->minWidth) {
if (!ctype_digit((string) $constraint->minWidth)) {
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid minimum width', $constraint->minWidth));
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid minimum width.', $constraint->minWidth));
}
if ($width < $constraint->minWidth) {
@@ -83,7 +84,7 @@ class ImageValidator extends FileValidator
if ($constraint->maxWidth) {
if (!ctype_digit((string) $constraint->maxWidth)) {
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum width', $constraint->maxWidth));
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum width.', $constraint->maxWidth));
}
if ($width > $constraint->maxWidth) {
@@ -127,6 +128,40 @@ class ImageValidator extends FileValidator
}
}
$pixels = $width * $height;
if (null !== $constraint->minPixels) {
if (!ctype_digit((string) $constraint->minPixels)) {
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid minimum amount of pixels', $constraint->minPixels));
}
if ($pixels < $constraint->minPixels) {
$this->context->buildViolation($constraint->minPixelsMessage)
->setParameter('{{ pixels }}', $pixels)
->setParameter('{{ min_pixels }}', $constraint->minPixels)
->setParameter('{{ height }}', $height)
->setParameter('{{ width }}', $width)
->setCode(Image::TOO_FEW_PIXEL_ERROR)
->addViolation();
}
}
if (null !== $constraint->maxPixels) {
if (!ctype_digit((string) $constraint->maxPixels)) {
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum amount of pixels', $constraint->maxPixels));
}
if ($pixels > $constraint->maxPixels) {
$this->context->buildViolation($constraint->maxPixelsMessage)
->setParameter('{{ pixels }}', $pixels)
->setParameter('{{ max_pixels }}', $constraint->maxPixels)
->setParameter('{{ height }}', $height)
->setParameter('{{ width }}', $width)
->setCode(Image::TOO_MANY_PIXEL_ERROR)
->addViolation();
}
}
$ratio = round($width / $height, 2);
if (null !== $constraint->minRatio) {
@@ -182,7 +217,7 @@ class ImageValidator extends FileValidator
}
if ($constraint->detectCorrupted) {
if (!function_exists('imagecreatefromstring')) {
if (!\function_exists('imagecreatefromstring')) {
throw new RuntimeException('Corrupted images detection requires installed and enabled GD extension');
}
+1 -1
View File
@@ -79,7 +79,7 @@ class Ip extends Constraint
{
parent::__construct($options);
if (!in_array($this->version, self::$versions)) {
if (!\in_array($this->version, self::$versions)) {
throw new ConstraintDefinitionException(sprintf('The option "version" must be one of "%s"', implode('", "', self::$versions)));
}
}
+1 -1
View File
@@ -36,7 +36,7 @@ class IpValidator extends ConstraintValidator
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
+2 -2
View File
@@ -39,7 +39,7 @@ class IsbnValidator extends ConstraintValidator
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
@@ -145,7 +145,7 @@ class IsbnValidator extends ConstraintValidator
return Isbn::INVALID_CHARACTERS_ERROR;
}
$length = strlen($isbn);
$length = \strlen($isbn);
if ($length < 13) {
return Isbn::TOO_SHORT_ERROR;
+2 -2
View File
@@ -38,7 +38,7 @@ class IssnValidator extends ConstraintValidator
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
@@ -59,7 +59,7 @@ class IssnValidator extends ConstraintValidator
return;
}
$length = strlen($canonical);
$length = \strlen($canonical);
if ($length < 8) {
$this->context->buildViolation($constraint->message)
+1 -1
View File
@@ -36,7 +36,7 @@ class LanguageValidator extends ConstraintValidator
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
+1 -1
View File
@@ -42,7 +42,7 @@ class Length extends Constraint
public function __construct($options = null)
{
if (null !== $options && !is_array($options)) {
if (null !== $options && !\is_array($options)) {
$options = array(
'min' => $options,
'max' => $options,
+1 -1
View File
@@ -33,7 +33,7 @@ class LengthValidator extends ConstraintValidator
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
+2 -2
View File
@@ -36,7 +36,7 @@ class LocaleValidator extends ConstraintValidator
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
@@ -44,7 +44,7 @@ class LocaleValidator extends ConstraintValidator
$locales = Intl::getLocaleBundle()->getLocaleNames();
$aliases = Intl::getLocaleBundle()->getAliases();
if (!isset($locales[$value]) && !in_array($value, $aliases)) {
if (!isset($locales[$value]) && !\in_array($value, $aliases)) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Locale::NO_SUCH_LOCALE_ERROR)
+2 -2
View File
@@ -49,7 +49,7 @@ class LuhnValidator extends ConstraintValidator
// Work with strings only, because long numbers are represented as floats
// internally and don't work with strlen()
if (!is_string($value) && !(is_object($value) && method_exists($value, '__toString'))) {
if (!\is_string($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
@@ -65,7 +65,7 @@ class LuhnValidator extends ConstraintValidator
}
$checkSum = 0;
$length = strlen($value);
$length = \strlen($value);
// Starting with the last digit and walking left, add every second
// digit to the check sum
+2 -2
View File
@@ -50,11 +50,11 @@ class RangeValidator extends ConstraintValidator
// the DateTime constructor:
// http://php.net/manual/en/datetime.formats.php
if ($value instanceof \DateTimeInterface) {
if (is_string($min)) {
if (\is_string($min)) {
$min = new \DateTime($min);
}
if (is_string($max)) {
if (\is_string($max)) {
$max = new \DateTime($max);
}
}
+2 -2
View File
@@ -70,7 +70,7 @@ class Regex extends Constraint
}
// Quit if delimiters not at very beginning/end (e.g. when options are passed)
if ($this->pattern[0] !== $this->pattern[strlen($this->pattern) - 1]) {
if ($this->pattern[0] !== $this->pattern[\strlen($this->pattern) - 1]) {
return;
}
@@ -95,7 +95,7 @@ class Regex extends Constraint
$pattern = '^' === $pattern[0] ? substr($pattern, 1) : '.*'.$pattern;
// Trim trailing $, otherwise append .*
$pattern = '$' === $pattern[strlen($pattern) - 1] ? substr($pattern, 0, -1) : $pattern.'.*';
$pattern = '$' === $pattern[\strlen($pattern) - 1] ? substr($pattern, 0, -1) : $pattern.'.*';
return $pattern;
}
+1 -1
View File
@@ -36,7 +36,7 @@ class RegexValidator extends ConstraintValidator
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
+1 -1
View File
@@ -51,7 +51,7 @@ class TimeValidator extends ConstraintValidator
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
+1 -1
View File
@@ -25,7 +25,7 @@ class Traverse extends Constraint
public function __construct($options = null)
{
if (is_array($options) && array_key_exists('groups', $options)) {
if (\is_array($options) && array_key_exists('groups', $options)) {
throw new ConstraintDefinitionException(sprintf(
'The option "groups" is not supported by the constraint %s',
__CLASS__
+2 -2
View File
@@ -38,9 +38,9 @@ class TypeValidator extends ConstraintValidator
$isFunction = 'is_'.$type;
$ctypeFunction = 'ctype_'.$type;
if (function_exists($isFunction) && $isFunction($value)) {
if (\function_exists($isFunction) && $isFunction($value)) {
return;
} elseif (function_exists($ctypeFunction) && $ctypeFunction($value)) {
} elseif (\function_exists($ctypeFunction) && $ctypeFunction($value)) {
return;
} elseif ($value instanceof $constraint->type) {
return;
+15 -1
View File
@@ -21,6 +21,20 @@ use Symfony\Component\Validator\Constraint;
*/
class Url extends Constraint
{
const CHECK_DNS_TYPE_ANY = 'ANY';
const CHECK_DNS_TYPE_NONE = false;
const CHECK_DNS_TYPE_A = 'A';
const CHECK_DNS_TYPE_A6 = 'A6';
const CHECK_DNS_TYPE_AAAA = 'AAAA';
const CHECK_DNS_TYPE_CNAME = 'CNAME';
const CHECK_DNS_TYPE_MX = 'MX';
const CHECK_DNS_TYPE_NAPTR = 'NAPTR';
const CHECK_DNS_TYPE_NS = 'NS';
const CHECK_DNS_TYPE_PTR = 'PTR';
const CHECK_DNS_TYPE_SOA = 'SOA';
const CHECK_DNS_TYPE_SRV = 'SRV';
const CHECK_DNS_TYPE_TXT = 'TXT';
const INVALID_URL_ERROR = '57c2f299-1154-4870-89bb-ef3b1f5ad229';
protected static $errorNames = array(
@@ -30,5 +44,5 @@ class Url extends Constraint
public $message = 'This value is not a valid URL.';
public $dnsMessage = 'The host could not be resolved.';
public $protocols = array('http', 'https');
public $checkDNS = false;
public $checkDNS = self::CHECK_DNS_TYPE_NONE;
}
+20 -2
View File
@@ -13,6 +13,7 @@ namespace Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\InvalidOptionsException;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
/**
@@ -51,7 +52,7 @@ class UrlValidator extends ConstraintValidator
return;
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
@@ -72,9 +73,26 @@ class UrlValidator extends ConstraintValidator
}
if ($constraint->checkDNS) {
if (!\in_array($constraint->checkDNS, array(
Url::CHECK_DNS_TYPE_ANY,
Url::CHECK_DNS_TYPE_A,
Url::CHECK_DNS_TYPE_A6,
Url::CHECK_DNS_TYPE_AAAA,
Url::CHECK_DNS_TYPE_CNAME,
Url::CHECK_DNS_TYPE_MX,
Url::CHECK_DNS_TYPE_NAPTR,
Url::CHECK_DNS_TYPE_NS,
Url::CHECK_DNS_TYPE_PTR,
Url::CHECK_DNS_TYPE_SOA,
Url::CHECK_DNS_TYPE_SRV,
Url::CHECK_DNS_TYPE_TXT,
), true)) {
throw new InvalidOptionsException(sprintf('Invalid value for option "checkDNS" in constraint %s', \get_class($constraint)), array('checkDNS'));
}
$host = parse_url($value, PHP_URL_HOST);
if (!is_string($host) || !checkdnsrr($host, 'ANY')) {
if (!\is_string($host) || !checkdnsrr($host, $constraint->checkDNS)) {
$this->context->buildViolation($constraint->dnsMessage)
->setParameter('{{ value }}', $this->formatValue($host))
->setCode(Url::INVALID_URL_ERROR)
+2 -2
View File
@@ -74,7 +74,7 @@ class UuidValidator extends ConstraintValidator
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Uuid');
}
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
}
@@ -235,7 +235,7 @@ class UuidValidator extends ConstraintValidator
}
// Check version
if (!in_array($value[self::STRICT_VERSION_POSITION], $constraint->versions)) {
if (!\in_array($value[self::STRICT_VERSION_POSITION], $constraint->versions)) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setCode(Uuid::INVALID_VERSION_ERROR)
+15 -8
View File
@@ -12,7 +12,6 @@
namespace Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
/**
* @Annotation
@@ -24,15 +23,23 @@ class Valid extends Constraint
{
public $traverse = true;
public function __construct($options = null)
public function __get($option)
{
if (is_array($options) && array_key_exists('groups', $options)) {
throw new ConstraintDefinitionException(sprintf(
'The option "groups" is not supported by the constraint %s',
__CLASS__
));
if ('groups' === $option) {
// when this is reached, no groups have been configured
return null;
}
parent::__construct($options);
return parent::__get($option);
}
/**
* {@inheritdoc}
*/
public function addImplicitGroupName($group)
{
if (null !== $this->groups) {
parent::addImplicitGroupName($group);
}
}
}
@@ -46,7 +46,7 @@ class ContainerConstraintValidatorFactory implements ConstraintValidatorFactoryI
$this->validators[$name] = $this->container->get($name);
} else {
if (!class_exists($name)) {
throw new ValidatorException(sprintf('Constraint validator "%s" does not exist or it is not enabled. Check the "validatedBy" method in your constraint class "%s".', $name, get_class($constraint)));
throw new ValidatorException(sprintf('Constraint validator "%s" does not exist or it is not enabled. Check the "validatedBy" method in your constraint class "%s".', $name, \get_class($constraint)));
}
$this->validators[$name] = new $name();
+3 -4
View File
@@ -16,8 +16,8 @@ use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\Mapping\ClassMetadataInterface;
use Symfony\Component\Validator\Mapping\MetadataInterface;
use Symfony\Component\Validator\Mapping\MemberMetadata;
use Symfony\Component\Validator\Mapping\MetadataInterface;
use Symfony\Component\Validator\Mapping\PropertyMetadataInterface;
use Symfony\Component\Validator\Util\PropertyPath;
use Symfony\Component\Validator\Validator\ValidatorInterface;
@@ -30,8 +30,7 @@ use Symfony\Component\Validator\Violation\ConstraintViolationBuilder;
*
* @see ExecutionContextInterface
*
* @internal You should not instantiate or use this class. Code against
* {@link ExecutionContextInterface} instead.
* @internal since version 2.5. Code against ExecutionContextInterface instead.
*/
class ExecutionContext implements ExecutionContextInterface
{
@@ -141,7 +140,7 @@ class ExecutionContext implements ExecutionContextInterface
* @internal Called by {@link ExecutionContextFactory}. Should not be used
* in user code.
*/
public function __construct(ValidatorInterface $validator, $root, TranslatorInterface $translator, $translationDomain = null)
public function __construct(ValidatorInterface $validator, $root, TranslatorInterface $translator, string $translationDomain = null)
{
$this->validator = $validator;
$this->root = $root;
@@ -19,8 +19,7 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @internal You should not instantiate or use this class. Code against
* {@link ExecutionContextFactoryInterface} instead.
* @internal version 2.5. Code against ExecutionContextFactoryInterface instead.
*/
class ExecutionContextFactory implements ExecutionContextFactoryInterface
{
@@ -35,7 +34,7 @@ class ExecutionContextFactory implements ExecutionContextFactoryInterface
* use for translating
* violation messages
*/
public function __construct(TranslatorInterface $translator, $translationDomain = null)
public function __construct(TranslatorInterface $translator, string $translationDomain = null)
{
$this->translator = $translator;
$this->translationDomain = $translationDomain;
@@ -12,11 +12,11 @@
namespace Symfony\Component\Validator\Context;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintViolationListInterface;
use Symfony\Component\Validator\Mapping;
use Symfony\Component\Validator\Mapping\MetadataInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface;
use Symfony\Component\Validator\ConstraintViolationListInterface;
/**
* The context of a validation run.
@@ -11,9 +11,9 @@
namespace Symfony\Component\Validator\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
/**
@@ -25,7 +25,7 @@ class AddConstraintValidatorsPass implements CompilerPassInterface
private $validatorFactoryServiceId;
private $constraintValidatorTag;
public function __construct($validatorFactoryServiceId = 'validator.validator_factory', $constraintValidatorTag = 'validator.constraint_validator')
public function __construct(string $validatorFactoryServiceId = 'validator.validator_factory', string $constraintValidatorTag = 'validator.constraint_validator')
{
$this->validatorFactoryServiceId = $validatorFactoryServiceId;
$this->constraintValidatorTag = $constraintValidatorTag;
@@ -11,9 +11,9 @@
namespace Symfony\Component\Validator\DependencyInjection;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
/**
* @author Fabien Potencier <fabien@symfony.com>
@@ -24,7 +24,7 @@ class AddValidatorInitializersPass implements CompilerPassInterface
private $builderService;
private $initializerTag;
public function __construct($builderService = 'validator.builder', $initializerTag = 'validator.initializer')
public function __construct(string $builderService = 'validator.builder', string $initializerTag = 'validator.initializer')
{
$this->builderService = $builderService;
$this->initializerTag = $initializerTag;
@@ -15,7 +15,7 @@ class InvalidOptionsException extends ValidatorException
{
private $options;
public function __construct($message, array $options)
public function __construct(string $message, array $options)
{
parent::__construct($message);
@@ -15,7 +15,7 @@ class MissingOptionsException extends ValidatorException
{
private $options;
public function __construct($message, array $options)
public function __construct(string $message, array $options)
{
parent::__construct($message);
@@ -13,8 +13,8 @@ namespace Symfony\Component\Validator\Exception;
class UnexpectedTypeException extends ValidatorException
{
public function __construct($value, $expectedType)
public function __construct($value, string $expectedType)
{
parent::__construct(sprintf('Expected argument of type "%s", "%s" given', $expectedType, is_object($value) ? get_class($value) : gettype($value)));
parent::__construct(sprintf('Expected argument of type "%s", "%s" given', $expectedType, \is_object($value) ? \get_class($value) : \gettype($value)));
}
}
+1 -5
View File
@@ -63,12 +63,8 @@ class Psr6Cache implements CacheInterface
/**
* Replaces backslashes by dots in a class name.
*
* @param string $class
*
* @return string
*/
private function escapeClassName($class)
private function escapeClassName(string $class): string
{
return str_replace('\\', '.', $class);
}
+11 -16
View File
@@ -47,7 +47,7 @@ class ClassMetadata extends GenericMetadata implements ClassMetadataInterface
public $defaultGroup;
/**
* @var MemberMetadata[]
* @var MemberMetadata[][]
*
* @internal This property is public in order to reduce the size of the
* class' serialized representation. Do not access it. Use
@@ -109,12 +109,7 @@ class ClassMetadata extends GenericMetadata implements ClassMetadataInterface
*/
private $reflClass;
/**
* Constructs a metadata for the given class.
*
* @param string $class
*/
public function __construct($class)
public function __construct(string $class)
{
$this->name = $class;
// class name without namespace
@@ -179,17 +174,17 @@ class ClassMetadata extends GenericMetadata implements ClassMetadataInterface
*/
public function addConstraint(Constraint $constraint)
{
if (!in_array(Constraint::CLASS_CONSTRAINT, (array) $constraint->getTargets())) {
if (!\in_array(Constraint::CLASS_CONSTRAINT, (array) $constraint->getTargets())) {
throw new ConstraintDefinitionException(sprintf(
'The constraint "%s" cannot be put on classes.',
get_class($constraint)
\get_class($constraint)
));
}
if ($constraint instanceof Valid) {
throw new ConstraintDefinitionException(sprintf(
'The constraint "%s" cannot be put on classes.',
get_class($constraint)
\get_class($constraint)
));
}
@@ -335,7 +330,7 @@ class ClassMetadata extends GenericMetadata implements ClassMetadataInterface
/**
* Merges the constraints of the given metadata into this object.
*/
public function mergeConstraints(ClassMetadata $source)
public function mergeConstraints(self $source)
{
if ($source->isGroupSequenceProvider()) {
$this->setGroupSequenceProvider(true);
@@ -350,7 +345,7 @@ class ClassMetadata extends GenericMetadata implements ClassMetadataInterface
$member = clone $member;
foreach ($member->getConstraints() as $constraint) {
if (in_array($constraint::DEFAULT_GROUP, $constraint->groups, true)) {
if (\in_array($constraint::DEFAULT_GROUP, $constraint->groups, true)) {
$member->constraintsByGroup[$this->getDefaultGroup()][] = $constraint;
}
@@ -415,15 +410,15 @@ class ClassMetadata extends GenericMetadata implements ClassMetadataInterface
throw new GroupDefinitionException('Defining a static group sequence is not allowed with a group sequence provider');
}
if (is_array($groupSequence)) {
if (\is_array($groupSequence)) {
$groupSequence = new GroupSequence($groupSequence);
}
if (in_array(Constraint::DEFAULT_GROUP, $groupSequence->groups, true)) {
if (\in_array(Constraint::DEFAULT_GROUP, $groupSequence->groups, true)) {
throw new GroupDefinitionException(sprintf('The group "%s" is not allowed in group sequences', Constraint::DEFAULT_GROUP));
}
if (!in_array($this->getDefaultGroup(), $groupSequence->groups, true)) {
if (!\in_array($this->getDefaultGroup(), $groupSequence->groups, true)) {
throw new GroupDefinitionException(sprintf('The group "%s" is missing in the group sequence', $this->getDefaultGroup()));
}
@@ -437,7 +432,7 @@ class ClassMetadata extends GenericMetadata implements ClassMetadataInterface
*/
public function hasGroupSequence()
{
return $this->groupSequence && count($this->groupSequence->groups) > 0;
return $this->groupSequence && \count($this->groupSequence->groups) > 0;
}
/**
@@ -78,16 +78,20 @@ class LazyLoadingMetadataFactory implements MetadataFactoryInterface
*/
public function getMetadataFor($value)
{
if (!is_object($value) && !is_string($value)) {
throw new NoSuchMetadataException(sprintf('Cannot create metadata for non-objects. Got: %s', gettype($value)));
if (!\is_object($value) && !\is_string($value)) {
throw new NoSuchMetadataException(sprintf('Cannot create metadata for non-objects. Got: %s', \gettype($value)));
}
$class = ltrim(is_object($value) ? get_class($value) : $value, '\\');
$class = ltrim(\is_object($value) ? \get_class($value) : $value, '\\');
if (isset($this->loadedClasses[$class])) {
return $this->loadedClasses[$class];
}
if (!class_exists($class) && !interface_exists($class, false)) {
throw new NoSuchMetadataException(sprintf('The class or interface "%s" does not exist.', $class));
}
if (null !== $this->cache && false !== ($metadata = $this->cache->read($class))) {
// Include constraints from the parent class
$this->mergeConstraints($metadata);
@@ -95,10 +99,6 @@ class LazyLoadingMetadataFactory implements MetadataFactoryInterface
return $this->loadedClasses[$class] = $metadata;
}
if (!class_exists($class) && !interface_exists($class)) {
throw new NoSuchMetadataException(sprintf('The class or interface "%s" does not exist.', $class));
}
$metadata = new ClassMetadata($class);
if (null !== $this->loader) {
@@ -154,16 +154,12 @@ class LazyLoadingMetadataFactory implements MetadataFactoryInterface
*/
public function hasMetadataFor($value)
{
if (!is_object($value) && !is_string($value)) {
if (!\is_object($value) && !\is_string($value)) {
return false;
}
$class = ltrim(is_object($value) ? get_class($value) : $value, '\\');
$class = ltrim(\is_object($value) ? \get_class($value) : $value, '\\');
if (class_exists($class) || interface_exists($class)) {
return true;
}
return false;
return class_exists($class) || interface_exists($class, false);
}
}
+3 -3
View File
@@ -125,11 +125,11 @@ class GenericMetadata implements MetadataInterface
throw new ConstraintDefinitionException(sprintf(
'The constraint "%s" can only be put on classes. Please use '.
'"Symfony\Component\Validator\Constraints\Valid" instead.',
get_class($constraint)
\get_class($constraint)
));
}
if ($constraint instanceof Valid) {
if ($constraint instanceof Valid && null === $constraint->groups) {
$this->cascadingStrategy = CascadingStrategy::CASCADE;
if ($constraint->traverse) {
@@ -181,7 +181,7 @@ class GenericMetadata implements MetadataInterface
*/
public function hasConstraints()
{
return count($this->constraints) > 0;
return \count($this->constraints) > 0;
}
/**
+1 -1
View File
@@ -39,7 +39,7 @@ class GetterMetadata extends MemberMetadata
*
* @throws ValidatorException
*/
public function __construct($class, $property, $method = null)
public function __construct(string $class, string $property, string $method = null)
{
if (null === $method) {
$getMethod = 'get'.ucfirst($property);
+1 -1
View File
@@ -32,7 +32,7 @@ abstract class FileLoader extends AbstractLoader
*
* @throws MappingException If the file does not exist or is not readable
*/
public function __construct($file)
public function __construct(string $file)
{
if (!is_file($file)) {
throw new MappingException(sprintf('The mapping file "%s" does not exist', $file));
+1 -1
View File
@@ -36,7 +36,7 @@ class LoaderChain implements LoaderInterface
{
foreach ($loaders as $loader) {
if (!$loader instanceof LoaderInterface) {
throw new MappingException(sprintf('Class %s is expected to implement LoaderInterface', get_class($loader)));
throw new MappingException(sprintf('Class %s is expected to implement LoaderInterface', \get_class($loader)));
}
}
@@ -28,7 +28,7 @@ class StaticMethodLoader implements LoaderInterface
*
* @param string $methodName The name of the static method to call
*/
public function __construct($methodName = 'loadValidatorMetadata')
public function __construct(string $methodName = 'loadValidatorMetadata')
{
$this->methodName = $methodName;
}
+14 -14
View File
@@ -75,17 +75,17 @@ class XmlFileLoader extends FileLoader
$constraints = array();
foreach ($nodes as $node) {
if (count($node) > 0) {
if (count($node->value) > 0) {
if (\count($node) > 0) {
if (\count($node->value) > 0) {
$options = $this->parseValues($node->value);
} elseif (count($node->constraint) > 0) {
} elseif (\count($node->constraint) > 0) {
$options = $this->parseConstraints($node->constraint);
} elseif (count($node->option) > 0) {
} elseif (\count($node->option) > 0) {
$options = $this->parseOptions($node->option);
} else {
$options = array();
}
} elseif (strlen((string) $node) > 0) {
} elseif (\strlen((string) $node) > 0) {
$options = XmlUtils::phpize(trim($node));
} else {
$options = null;
@@ -109,10 +109,10 @@ class XmlFileLoader extends FileLoader
$values = array();
foreach ($nodes as $node) {
if (count($node) > 0) {
if (count($node->value) > 0) {
if (\count($node) > 0) {
if (\count($node->value) > 0) {
$value = $this->parseValues($node->value);
} elseif (count($node->constraint) > 0) {
} elseif (\count($node->constraint) > 0) {
$value = $this->parseConstraints($node->constraint);
} else {
$value = array();
@@ -143,17 +143,17 @@ class XmlFileLoader extends FileLoader
$options = array();
foreach ($nodes as $node) {
if (count($node) > 0) {
if (count($node->value) > 0) {
if (\count($node) > 0) {
if (\count($node->value) > 0) {
$value = $this->parseValues($node->value);
} elseif (count($node->constraint) > 0) {
} elseif (\count($node->constraint) > 0) {
$value = $this->parseConstraints($node->constraint);
} else {
$value = array();
}
} else {
$value = XmlUtils::phpize($node);
if (is_string($value)) {
if (\is_string($value)) {
$value = trim($value);
}
}
@@ -203,12 +203,12 @@ class XmlFileLoader extends FileLoader
private function loadClassMetadataFromXml(ClassMetadata $metadata, \SimpleXMLElement $classDescription)
{
if (count($classDescription->{'group-sequence-provider'}) > 0) {
if (\count($classDescription->{'group-sequence-provider'}) > 0) {
$metadata->setGroupSequenceProvider(true);
}
foreach ($classDescription->{'group-sequence'} as $groupSequence) {
if (count($groupSequence->value) > 0) {
if (\count($groupSequence->value) > 0) {
$metadata->setGroupSequence($this->parseValues($groupSequence[0]->value));
}
}
+8 -16
View File
@@ -83,16 +83,16 @@ class YamlFileLoader extends FileLoader
$values = array();
foreach ($nodes as $name => $childNodes) {
if (is_numeric($name) && is_array($childNodes) && 1 === count($childNodes)) {
if (is_numeric($name) && \is_array($childNodes) && 1 === \count($childNodes)) {
$options = current($childNodes);
if (is_array($options)) {
if (\is_array($options)) {
$options = $this->parseNodes($options);
}
$values[] = $this->newConstraint(key($childNodes), $options);
} else {
if (is_array($childNodes)) {
if (\is_array($childNodes)) {
$childNodes = $this->parseNodes($childNodes);
}
@@ -115,18 +115,10 @@ class YamlFileLoader extends FileLoader
*/
private function parseFile($path)
{
$prevErrorHandler = set_error_handler(function ($level, $message, $script, $line) use ($path, &$prevErrorHandler) {
$message = E_USER_DEPRECATED === $level ? preg_replace('/ on line \d+/', ' in "'.$path.'"$0', $message) : $message;
return $prevErrorHandler ? $prevErrorHandler($level, $message, $script, $line) : false;
});
try {
$classes = $this->yamlParser->parse(file_get_contents($path), Yaml::PARSE_KEYS_AS_STRINGS);
$classes = $this->yamlParser->parseFile($path, Yaml::PARSE_CONSTANT);
} catch (ParseException $e) {
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $path), 0, $e);
} finally {
restore_error_handler();
}
// empty file
@@ -135,7 +127,7 @@ class YamlFileLoader extends FileLoader
}
// not an array
if (!is_array($classes)) {
if (!\is_array($classes)) {
throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $this->file));
}
@@ -171,13 +163,13 @@ class YamlFileLoader extends FileLoader
$metadata->setGroupSequence($classDescription['group_sequence']);
}
if (isset($classDescription['constraints']) && is_array($classDescription['constraints'])) {
if (isset($classDescription['constraints']) && \is_array($classDescription['constraints'])) {
foreach ($this->parseNodes($classDescription['constraints']) as $constraint) {
$metadata->addConstraint($constraint);
}
}
if (isset($classDescription['properties']) && is_array($classDescription['properties'])) {
if (isset($classDescription['properties']) && \is_array($classDescription['properties'])) {
foreach ($classDescription['properties'] as $property => $constraints) {
if (null !== $constraints) {
foreach ($this->parseNodes($constraints) as $constraint) {
@@ -187,7 +179,7 @@ class YamlFileLoader extends FileLoader
}
}
if (isset($classDescription['getters']) && is_array($classDescription['getters'])) {
if (isset($classDescription['getters']) && \is_array($classDescription['getters'])) {
foreach ($classDescription['getters'] as $getter => $constraints) {
if (null !== $constraints) {
foreach ($this->parseNodes($constraints) as $constraint) {
+4 -4
View File
@@ -59,7 +59,7 @@ abstract class MemberMetadata extends GenericMetadata implements PropertyMetadat
* @param string $name The name of the member
* @param string $property The property the member belongs to
*/
public function __construct($class, $name, $property)
public function __construct(string $class, string $name, string $property)
{
$this->class = $class;
$this->name = $name;
@@ -71,10 +71,10 @@ abstract class MemberMetadata extends GenericMetadata implements PropertyMetadat
*/
public function addConstraint(Constraint $constraint)
{
if (!in_array(Constraint::PROPERTY_CONSTRAINT, (array) $constraint->getTargets())) {
if (!\in_array(Constraint::PROPERTY_CONSTRAINT, (array) $constraint->getTargets())) {
throw new ConstraintDefinitionException(sprintf(
'The constraint %s cannot be put on properties or getters',
get_class($constraint)
\get_class($constraint)
));
}
@@ -166,7 +166,7 @@ abstract class MemberMetadata extends GenericMetadata implements PropertyMetadat
*/
public function getReflectionMember($objectOrClassName)
{
$className = is_string($objectOrClassName) ? $objectOrClassName : get_class($objectOrClassName);
$className = \is_string($objectOrClassName) ? $objectOrClassName : \get_class($objectOrClassName);
if (!isset($this->reflMember[$className])) {
$this->reflMember[$className] = $this->newReflectionMember($objectOrClassName);
}
+2 -2
View File
@@ -34,7 +34,7 @@ class PropertyMetadata extends MemberMetadata
*
* @throws ValidatorException
*/
public function __construct($class, $name)
public function __construct(string $class, string $name)
{
if (!property_exists($class, $name)) {
throw new ValidatorException(sprintf('Property "%s" does not exist in class "%s"', $name, $class));
@@ -56,7 +56,7 @@ class PropertyMetadata extends MemberMetadata
*/
protected function newReflectionMember($objectOrClassName)
{
$originalClass = is_string($objectOrClassName) ? $objectOrClassName : get_class($objectOrClassName);
$originalClass = \is_string($objectOrClassName) ? $objectOrClassName : \get_class($objectOrClassName);
while (!property_exists($objectOrClassName, $this->getName())) {
$objectOrClassName = get_parent_class($objectOrClassName);
+1 -1
View File
@@ -14,7 +14,7 @@ namespace Symfony\Component\Validator;
/**
* Prepares an object for validation.
*
* Concrete implementations of this interface are used by {@link ValidationVisitorInterface}
* Concrete implementations of this interface are used by {@link Validator\ContextualValidatorInterface}
* to initialize objects just before validating them.
*
* @author Fabien Potencier <fabien@symfony.com>
@@ -314,6 +314,10 @@
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>Невалиден бизнес идентификационен код (BIC).</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Грешка</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -302,6 +302,10 @@
<source>An empty file is not allowed.</source>
<target>No està permès un fixter buit.</target>
</trans-unit>
<trans-unit id="83">
<source>This is not a valid UUID.</source>
<target>Aquest valor no és un UUID vàlid.</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -314,6 +314,10 @@
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>Tato hodnota není platný identifikační kód podniku (BIC).</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Chyba</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -20,19 +20,19 @@
</trans-unit>
<trans-unit id="5">
<source>The value you selected is not a valid choice.</source>
<target>Værdien skal være en af de givne muligheder.</target>
<target>Den valgte værdi er ikke gyldig.</target>
</trans-unit>
<trans-unit id="6">
<source>You must select at least {{ limit }} choice.|You must select at least {{ limit }} choices.</source>
<target>Du skal vælge mindst {{ limit }} muligheder.</target>
<target>Du skal vælge mindst én mulighed.|Du skal vælge mindst {{ limit }} muligheder.</target>
</trans-unit>
<trans-unit id="7">
<source>You must select at most {{ limit }} choice.|You must select at most {{ limit }} choices.</source>
<target>Du kan højest vælge {{ limit }} muligheder.</target>
<target>Du kan højst vælge én mulighed.|Du kan højst vælge {{ limit }} muligheder.</target>
</trans-unit>
<trans-unit id="8">
<source>One or more of the given values is invalid.</source>
<target>En eller flere af de oplyste værdier er ugyldige.</target>
<target>En eller flere af de angivne værdier er ugyldige.</target>
</trans-unit>
<trans-unit id="9">
<source>This field was not expected.</source>
@@ -40,7 +40,7 @@
</trans-unit>
<trans-unit id="10">
<source>This field is missing.</source>
<target>Dette felt er mangler.</target>
<target>Dette felt mangler.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>
@@ -48,11 +48,11 @@
</trans-unit>
<trans-unit id="12">
<source>This value is not a valid datetime.</source>
<target>Værdien er ikke en gyldig dato og tid.</target>
<target>Værdien er ikke et gyldigt tidspunkt.</target>
</trans-unit>
<trans-unit id="13">
<source>This value is not a valid email address.</source>
<target>Værdien er ikke en gyldig e-mail adresse.</target>
<target>Værdien er ikke en gyldig e-mailadresse.</target>
</trans-unit>
<trans-unit id="14">
<source>The file could not be found.</source>
@@ -64,11 +64,11 @@
</trans-unit>
<trans-unit id="16">
<source>The file is too large ({{ size }} {{ suffix }}). Allowed maximum size is {{ limit }} {{ suffix }}.</source>
<target>Filen er for stor ({{ size }} {{ suffix }}). Tilladte maksimale størrelse {{ limit }} {{ suffix }}.</target>
<target>Filen er for stor ({{ size }} {{ suffix }}). Maksimale tilladte størrelse er {{ limit }} {{ suffix }}.</target>
</trans-unit>
<trans-unit id="17">
<source>The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}.</source>
<target>Mimetypen af filen er ugyldig ({{ type }}). Tilladte mimetyper er {{ types }}.</target>
<target>Filens MIME-type er ugyldig ({{ type }}). Tilladte MIME-typer er {{ types }}.</target>
</trans-unit>
<trans-unit id="18">
<source>This value should be {{ limit }} or less.</source>
@@ -76,7 +76,7 @@
</trans-unit>
<trans-unit id="19">
<source>This value is too long. It should have {{ limit }} character or less.|This value is too long. It should have {{ limit }} characters or less.</source>
<target>Værdien er for lang. Den skal have {{ limit }} bogstaver eller mindre.</target>
<target>Værdien er for lang. Den må højst indeholde {{ limit }} tegn.</target>
</trans-unit>
<trans-unit id="20">
<source>This value should be {{ limit }} or more.</source>
@@ -84,7 +84,7 @@
</trans-unit>
<trans-unit id="21">
<source>This value is too short. It should have {{ limit }} character or more.|This value is too short. It should have {{ limit }} characters or more.</source>
<target>Værdien er for kort. Den skal have {{ limit }} tegn eller flere.</target>
<target>Værdien er for kort. Den skal indeholde mindst {{ limit }} tegn.</target>
</trans-unit>
<trans-unit id="22">
<source>This value should not be blank.</source>
@@ -104,7 +104,7 @@
</trans-unit>
<trans-unit id="26">
<source>This value is not a valid time.</source>
<target>Værdien er ikke en gyldig tid.</target>
<target>Værdien er ikke et gyldigt klokkeslæt.</target>
</trans-unit>
<trans-unit id="27">
<source>This value is not a valid URL.</source>
@@ -136,7 +136,7 @@
</trans-unit>
<trans-unit id="37">
<source>This is not a valid IP address.</source>
<target>Dette er ikke en gyldig IP adresse.</target>
<target>Dette er ikke en gyldig IP-adresse.</target>
</trans-unit>
<trans-unit id="38">
<source>This value is not a valid language.</source>
@@ -160,31 +160,31 @@
</trans-unit>
<trans-unit id="43">
<source>The image width is too big ({{ width }}px). Allowed maximum width is {{ max_width }}px.</source>
<target>Billedbredden er for stor ({{ width }}px). Tilladt maksimumsbredde er {{ max_width }}px.</target>
<target>Billedet er for bredt ({{ width }}px). Største tilladte bredde er {{ max_width }}px.</target>
</trans-unit>
<trans-unit id="44">
<source>The image width is too small ({{ width }}px). Minimum width expected is {{ min_width }}px.</source>
<target>Billedebredden er for lille ({{ width }}px). Forventet minimumshøjde er {{ min_width }}px.</target>
<target>Billedet er for smalt ({{ width }}px). Mindste forventede bredde er {{ min_width }}px.</target>
</trans-unit>
<trans-unit id="45">
<source>The image height is too big ({{ height }}px). Allowed maximum height is {{ max_height }}px.</source>
<target>Billedhøjden er for stor ({{ height }}px). Tilladt maksimumshøjde er {{ max_height }}px.</target>
<target>Billedet er for højt ({{ height }}px). Største tilladte højde er {{ max_height }}px.</target>
</trans-unit>
<trans-unit id="46">
<source>The image height is too small ({{ height }}px). Minimum height expected is {{ min_height }}px.</source>
<target>Billedhøjden er for lille ({{ height }}px). Forventet minimumshøjde er {{ min_height }}px.</target>
<target>Billedet er for lavt ({{ height }}px). Mindste forventede højde er {{ min_height }}px.</target>
</trans-unit>
<trans-unit id="47">
<source>This value should be the user's current password.</source>
<target>Værdien skal være brugerens nuværende password.</target>
<target>Værdien skal være brugerens nuværende adgangskode.</target>
</trans-unit>
<trans-unit id="48">
<source>This value should have exactly {{ limit }} character.|This value should have exactly {{ limit }} characters.</source>
<target>Værdien skal have præcis {{ limit }} tegn.</target>
<target>Værdien skal være på præcis {{ limit }} tegn.</target>
</trans-unit>
<trans-unit id="49">
<source>The file was only partially uploaded.</source>
<target>Filen var kun delvis uploadet.</target>
<target>Filen blev kun delvist uploadet.</target>
</trans-unit>
<trans-unit id="50">
<source>No file was uploaded.</source>
@@ -200,19 +200,19 @@
</trans-unit>
<trans-unit id="53">
<source>A PHP extension caused the upload to fail.</source>
<target>En PHP udvidelse forårsagede fejl i upload.</target>
<target>En PHP-udvidelse forårsagede fejl i upload.</target>
</trans-unit>
<trans-unit id="54">
<source>This collection should contain {{ limit }} element or more.|This collection should contain {{ limit }} elements or more.</source>
<target>Denne samling skal indeholde {{ limit }} element eller flere.|Denne samling skal indeholde {{ limit }} elementer eller flere.</target>
<target>Denne samling skal indeholde mindst ét element.|Denne samling skal indeholde mindst {{ limit }} elementer.</target>
</trans-unit>
<trans-unit id="55">
<source>This collection should contain {{ limit }} element or less.|This collection should contain {{ limit }} elements or less.</source>
<target>Denne samling skal indeholde {{ limit }} element eller mindre.|Denne samling skal indeholde {{ limit }} elementer eller mindre.</target>
<target>Denne samling skal indeholde højst ét element.|Denne samling skal indeholde højst {{ limit }} elementer.</target>
</trans-unit>
<trans-unit id="56">
<source>This collection should contain exactly {{ limit }} element.|This collection should contain exactly {{ limit }} elements.</source>
<target>Denne samling skal indeholde præcis {{ limit }} element.|Denne samling skal indeholde præcis {{ limit }} elementer.</target>
<target>Denne samling skal indeholde præcis ét element.|Denne samling skal indeholde præcis {{ limit }} elementer.</target>
</trans-unit>
<trans-unit id="57">
<source>Invalid card number.</source>
@@ -224,7 +224,7 @@
</trans-unit>
<trans-unit id="59">
<source>This is not a valid International Bank Account Number (IBAN).</source>
<target>Det er ikke en gyldig International Bank Account Number (IBAN).</target>
<target>Det er ikke et gyldigt International Bank Account Number (IBAN).</target>
</trans-unit>
<trans-unit id="60">
<source>This value is not a valid ISBN-10.</source>
@@ -242,6 +242,10 @@
<source>This value is not a valid ISSN.</source>
<target>Værdien er ikke en gyldig ISSN.</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Fejl</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -314,6 +314,14 @@
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>Dieser Wert ist kein gültiger BIC.</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Fehler</target>
</trans-unit>
<trans-unit id="83">
<source>This is not a valid UUID.</source>
<target>Dies ist keine gültige UUID.</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -314,6 +314,14 @@
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>This is not a valid Business Identifier Code (BIC).</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Error</target>
</trans-unit>
<trans-unit id="83">
<source>This is not a valid UUID.</source>
<target>This is not a valid UUID.</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -314,6 +314,14 @@
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>No es un Código de Identificación Bancaria (BIC) válido.</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Error</target>
</trans-unit>
<trans-unit id="83">
<source>This is not a valid UUID.</source>
<target>Este valor no es un UUID válido.</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -278,6 +278,14 @@
<source>This value should not be identical to {{ compared_value_type }} {{ compared_value }}.</source>
<target>Balio hau ez litzateke {{ compared_value_type }} {{ compared_value }}-(r)en berbera izan behar.</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Errore</target>
</trans-unit>
<trans-unit id="83">
<source>This is not a valid UUID.</source>
<target>Balio hau ez da onartutako UUID bat.</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -222,6 +222,10 @@
<source>Unsupported card type or invalid card number.</source>
<target>Tätä korttityyppiä ei tueta tai korttinumero on virheellinen.</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Virhe</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -314,6 +314,14 @@
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>Ce n'est pas un code universel d'identification des banques (BIC) valide.</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Erreur</target>
</trans-unit>
<trans-unit id="83">
<source>This is not a valid UUID.</source>
<target>Ceci n'est pas un UUID valide.</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -314,6 +314,10 @@
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>Ovo nije validan poslovni identifikacijski broj (BIC).</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Greška</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -314,6 +314,14 @@
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>Érvénytelen nemzetközi bankazonosító kód (BIC/SWIFT).</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Hiba</target>
</trans-unit>
<trans-unit id="83">
<source>This is not a valid UUID.</source>
<target>Érvénytelen egyedi azonosító (UUID).</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -314,6 +314,10 @@
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>Ini bukan Business Identifier Code (BIC) yang sah.</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Galat</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -314,6 +314,14 @@
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>Questo valore non è un codice BIC valido.</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Errore</target>
</trans-unit>
<trans-unit id="83">
<source>This is not a valid UUID.</source>
<target>Questo non è un UUID valido.</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -314,6 +314,10 @@
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>有効なSWIFTコードではありません。</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>エラー</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -314,6 +314,10 @@
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>Dëst ass kee gëltege "Business Identifier Code" (BIC).</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Feeler</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
@@ -302,6 +302,10 @@
<source>An empty file is not allowed.</source>
<target>Failas negali būti tuščias.</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Klaida</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
@@ -310,6 +310,14 @@
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>Dit is geen geldige bedrijfsidentificatiecode (BIC/SWIFT).</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Fout</target>
</trans-unit>
<trans-unit id="83">
<source>This is not a valid UUID.</source>
<target>Deze waarde is geen geldige UUID waarde.</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -314,6 +314,10 @@
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>Ta wartość nie jest poprawnym kodem BIC (Business Identifier Code).</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Błąd</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -302,6 +302,10 @@
<source>An empty file is not allowed.</source>
<target>Ficheiro vazio não é permitido.</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Erro</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -278,6 +278,10 @@
<source>This value should not be identical to {{ compared_value_type }} {{ compared_value }}.</source>
<target>Această valoare nu trebuie să fie identică cu {{ compared_value_type }} {{ compared_value }}.</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Eroare</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
@@ -310,6 +310,10 @@
<source>This value does not match the expected {{ charset }} charset.</source>
<target>Значение не совпадает с ожидаемой {{ charset }} кодировкой.</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Ошибка</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -314,6 +314,10 @@
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>To ni veljavna identifikacijska koda podjetja (BIC).</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Napaka</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -314,6 +314,10 @@
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>Detta är inte en giltig BIC-kod.</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Fel</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -222,6 +222,10 @@
<source>Unsupported card type or invalid card number.</source>
<target>Desteklenmeyen kart tipi veya geçersiz kart numarası.</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Hata</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
@@ -278,6 +278,46 @@
<source>This value should not be identical to {{ compared_value_type }} {{ compared_value }}.</source>
<target>Значення не повинно бути ідентичним {{ compared_value_type }} {{ compared_value }}.</target>
</trans-unit>
<trans-unit id="73">
<source>The image ratio is too big ({{ ratio }}). Allowed maximum ratio is {{ max_ratio }}.</source>
<target>Співвідношення сторін зображення занадто велике ({{ ratio }}). Максимальне співвідношення сторін {{ max_ratio }}.</target>
</trans-unit>
<trans-unit id="74">
<source>The image ratio is too small ({{ ratio }}). Minimum ratio expected is {{ min_ratio }}.</source>
<target>Співвідношення сторін зображення занадто мало ({{ ratio }}). Мінімальне співвідношення сторін {{ min_ratio }}.</target>
</trans-unit>
<trans-unit id="75">
<source>The image is square ({{ width }}x{{ height }}px). Square images are not allowed.</source>
<target>Зображення квадратне ({{ width }}x{{ height }}px). Квадратні зображення не дозволені.</target>
</trans-unit>
<trans-unit id="76">
<source>The image is landscape oriented ({{ width }}x{{ height }}px). Landscape oriented images are not allowed.</source>
<target>Зображення альбомної орієнтації ({{ width }}x{{ height }}px). Зображення альбомної орієнтації не дозволені.</target>
</trans-unit>
<trans-unit id="77">
<source>The image is portrait oriented ({{ width }}x{{ height }}px). Portrait oriented images are not allowed.</source>
<target>Зображення в портретній орієнтації ({{ width }}x{{ height }}px). Зображення в портретної орієнтації не дозволені.</target>
</trans-unit>
<trans-unit id="78">
<source>An empty file is not allowed.</source>
<target>Порожні файли не дозволені.</target>
</trans-unit>
<trans-unit id="79">
<source>The host could not be resolved.</source>
<target>Ім'я хоста не знайдено.</target>
</trans-unit>
<trans-unit id="80">
<source>This value does not match the expected {{ charset }} charset.</source>
<target>Значення не збігається з очікуваним {{ charset }} кодуванням.</target>
</trans-unit>
<trans-unit id="81">
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>Це не дійсний банківський код (BIC).</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>Помилка</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -310,6 +310,10 @@
<source>This value does not match the expected {{ charset }} charset.</source>
<target>该值不符合 {{ charset }} 编码。</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
<target>错误</target>
</trans-unit>
</body>
</file>
</xliff>
@@ -121,8 +121,8 @@ abstract class ConstraintValidatorTestCase extends TestCase
protected function setObject($object)
{
$this->object = $object;
$this->metadata = is_object($object)
? new ClassMetadata(get_class($object))
$this->metadata = \is_object($object)
? new ClassMetadata(\get_class($object))
: null;
$this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);
@@ -131,8 +131,8 @@ abstract class ConstraintValidatorTestCase extends TestCase
protected function setProperty($object, $property)
{
$this->object = $object;
$this->metadata = is_object($object)
? new PropertyMetadata(get_class($object), $property)
$this->metadata = \is_object($object)
? new PropertyMetadata(\get_class($object), $property)
: null;
$this->context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);
@@ -192,7 +192,7 @@ abstract class ConstraintValidatorTestCase extends TestCase
protected function assertNoViolation()
{
$this->assertSame(0, $violationsCount = count($this->context->getViolations()), sprintf('0 violation expected. Got %u.', $violationsCount));
$this->assertSame(0, $violationsCount = \count($this->context->getViolations()), sprintf('0 violation expected. Got %u.', $violationsCount));
}
/**
@@ -314,7 +314,7 @@ class ConstraintViolationAssertion
$violations = iterator_to_array($this->context->getViolations());
Assert::assertSame($expectedCount = count($expected), $violationsCount = count($violations), sprintf('%u violation(s) expected. Got %u.', $expectedCount, $violationsCount));
Assert::assertSame($expectedCount = \count($expected), $violationsCount = \count($violations), sprintf('%u violation(s) expected. Got %u.', $expectedCount, $violationsCount));
reset($violations);
@@ -13,6 +13,7 @@ namespace Symfony\Component\Validator\Tests\Constraints;
use Symfony\Component\Intl\Util\IntlTestHelper;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
class ComparisonTest_Class
@@ -28,6 +29,11 @@ class ComparisonTest_Class
{
return (string) $this->value;
}
public function getValue()
{
return $this->value;
}
}
/**
@@ -76,12 +82,25 @@ abstract class AbstractComparisonValidatorTestCase extends ConstraintValidatorTe
/**
* @dataProvider provideInvalidConstraintOptions
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
* @expectedExceptionMessage requires either the "value" or "propertyPath" option to be set.
*/
public function testThrowsConstraintExceptionIfNoValueOrProperty($options)
public function testThrowsConstraintExceptionIfNoValueOrPropertyPath($options)
{
$this->createConstraint($options);
}
/**
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
* @expectedExceptionMessage requires only one of the "value" or "propertyPath" options to be set, not both.
*/
public function testThrowsConstraintExceptionIfBothValueAndPropertyPath()
{
$this->createConstraint((array(
'value' => 'value',
'propertyPath' => 'propertyPath',
)));
}
/**
* @dataProvider provideAllValidComparisons
*
@@ -113,11 +132,75 @@ abstract class AbstractComparisonValidatorTestCase extends ConstraintValidatorTe
return $comparisons;
}
/**
* @dataProvider provideValidComparisonsToPropertyPath
*/
public function testValidComparisonToPropertyPath($comparedValue)
{
$constraint = $this->createConstraint(array('propertyPath' => 'value'));
$object = new ComparisonTest_Class(5);
$this->setObject($object);
$this->validator->validate($comparedValue, $constraint);
$this->assertNoViolation();
}
/**
* @dataProvider provideValidComparisonsToPropertyPath
*/
public function testValidComparisonToPropertyPathOnArray($comparedValue)
{
$constraint = $this->createConstraint(array('propertyPath' => '[root][value]'));
$this->setObject(array('root' => array('value' => 5)));
$this->validator->validate($comparedValue, $constraint);
$this->assertNoViolation();
}
public function testNoViolationOnNullObjectWithPropertyPath()
{
$constraint = $this->createConstraint(array('propertyPath' => 'propertyPath'));
$this->setObject(null);
$this->validator->validate('some data', $constraint);
$this->assertNoViolation();
}
public function testInvalidValuePath()
{
$constraint = $this->createConstraint(array('propertyPath' => 'foo'));
if (method_exists($this, 'expectException')) {
$this->expectException(ConstraintDefinitionException::class);
$this->expectExceptionMessage(sprintf('Invalid property path "foo" provided to "%s" constraint', \get_class($constraint)));
} else {
$this->setExpectedException(ConstraintDefinitionException::class, sprintf('Invalid property path "foo" provided to "%s" constraint', \get_class($constraint)));
}
$object = new ComparisonTest_Class(5);
$this->setObject($object);
$this->validator->validate(5, $constraint);
}
/**
* @return array
*/
abstract public function provideValidComparisons();
/**
* @return array
*/
abstract public function provideValidComparisonsToPropertyPath();
/**
* @dataProvider provideAllInvalidComparisons
*

Some files were not shown because too many files have changed in this diff Show More