Mercurial > hg > isophonics-drupal-site
diff vendor/symfony/validator/Validator/RecursiveContextualValidator.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children | af1871eacc83 |
line wrap: on
line diff
--- a/vendor/symfony/validator/Validator/RecursiveContextualValidator.php Tue Jul 10 15:07:59 2018 +0100 +++ b/vendor/symfony/validator/Validator/RecursiveContextualValidator.php Thu Feb 28 13:21:36 2019 +0000 @@ -12,6 +12,7 @@ namespace Symfony\Component\Validator\Validator; use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\Constraints\Composite; use Symfony\Component\Validator\Constraints\GroupSequence; use Symfony\Component\Validator\ConstraintValidatorFactoryInterface; use Symfony\Component\Validator\Context\ExecutionContext; @@ -23,11 +24,11 @@ use Symfony\Component\Validator\Exception\ValidatorException; use Symfony\Component\Validator\Mapping\CascadingStrategy; use Symfony\Component\Validator\Mapping\ClassMetadataInterface; +use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; use Symfony\Component\Validator\Mapping\GenericMetadata; use Symfony\Component\Validator\Mapping\MetadataInterface; use Symfony\Component\Validator\Mapping\PropertyMetadataInterface; use Symfony\Component\Validator\Mapping\TraversalStrategy; -use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; use Symfony\Component\Validator\ObjectInitializerInterface; use Symfony\Component\Validator\Util\PropertyPath; @@ -56,11 +57,11 @@ * constraint validators * @param ObjectInitializerInterface[] $objectInitializers The object initializers */ - public function __construct(ExecutionContextInterface $context, MetadataFactoryInterface $metadataFactory, ConstraintValidatorFactoryInterface $validatorFactory, array $objectInitializers = array()) + public function __construct(ExecutionContextInterface $context, MetadataFactoryInterface $metadataFactory, ConstraintValidatorFactoryInterface $validatorFactory, array $objectInitializers = []) { $this->context = $context; $this->defaultPropertyPath = $context->getPropertyPath(); - $this->defaultGroups = array($context->getGroup() ?: Constraint::DEFAULT_GROUP); + $this->defaultGroups = [$context->getGroup() ?: Constraint::DEFAULT_GROUP]; $this->metadataFactory = $metadataFactory; $this->validatorFactory = $validatorFactory; $this->objectInitializers = $objectInitializers; @@ -99,8 +100,8 @@ if (null !== $constraints) { // You can pass a single constraint or an array of constraints // Make sure to deal with an array in the rest of the code - if (!is_array($constraints)) { - $constraints = array($constraints); + if (!\is_array($constraints)) { + $constraints = [$constraints]; } $metadata = new GenericMetadata(); @@ -109,7 +110,7 @@ $this->validateGenericNode( $value, $previousObject, - is_object($value) ? spl_object_hash($value) : null, + \is_object($value) ? spl_object_hash($value) : null, $metadata, $this->defaultPropertyPath, $groups, @@ -130,7 +131,7 @@ // If an object is passed without explicit constraints, validate that // object against the constraints defined for the object's class - if (is_object($value)) { + if (\is_object($value)) { $this->validateObject( $value, $this->defaultPropertyPath, @@ -147,7 +148,7 @@ // If an array is passed without explicit constraints, validate each // object in the array - if (is_array($value)) { + if (\is_array($value)) { $this->validateEachObjectIn( $value, $this->defaultPropertyPath, @@ -161,11 +162,7 @@ return $this; } - throw new RuntimeException(sprintf( - 'Cannot validate values of type "%s" automatically. Please '. - 'provide a constraint.', - gettype($value) - )); + throw new RuntimeException(sprintf('Cannot validate values of type "%s" automatically. Please provide a constraint.', \gettype($value))); } /** @@ -176,12 +173,7 @@ $classMetadata = $this->metadataFactory->getMetadataFor($object); if (!$classMetadata instanceof ClassMetadataInterface) { - throw new ValidatorException(sprintf( - 'The metadata factory should return instances of '. - '"\Symfony\Component\Validator\Mapping\ClassMetadataInterface", '. - 'got: "%s".', - is_object($classMetadata) ? get_class($classMetadata) : gettype($classMetadata) - )); + throw new ValidatorException(sprintf('The metadata factory should return instances of "\Symfony\Component\Validator\Mapping\ClassMetadataInterface", got: "%s".', \is_object($classMetadata) ? \get_class($classMetadata) : \gettype($classMetadata))); } $propertyMetadatas = $classMetadata->getPropertyMetadata($propertyName); @@ -201,7 +193,7 @@ $this->validateGenericNode( $propertyValue, $object, - $cacheKey.':'.get_class($object).':'.$propertyName, + $cacheKey.':'.\get_class($object).':'.$propertyName, $propertyMetadata, $propertyPath, $groups, @@ -225,20 +217,15 @@ $classMetadata = $this->metadataFactory->getMetadataFor($objectOrClass); if (!$classMetadata instanceof ClassMetadataInterface) { - throw new ValidatorException(sprintf( - 'The metadata factory should return instances of '. - '"\Symfony\Component\Validator\Mapping\ClassMetadataInterface", '. - 'got: "%s".', - is_object($classMetadata) ? get_class($classMetadata) : gettype($classMetadata) - )); + throw new ValidatorException(sprintf('The metadata factory should return instances of "\Symfony\Component\Validator\Mapping\ClassMetadataInterface", got: "%s".', \is_object($classMetadata) ? \get_class($classMetadata) : \gettype($classMetadata))); } $propertyMetadatas = $classMetadata->getPropertyMetadata($propertyName); $groups = $groups ? $this->normalizeGroups($groups) : $this->defaultGroups; - if (is_object($objectOrClass)) { + if (\is_object($objectOrClass)) { $object = $objectOrClass; - $class = get_class($object); + $class = \get_class($object); $cacheKey = spl_object_hash($objectOrClass); $propertyPath = PropertyPath::append($this->defaultPropertyPath, $propertyName); } else { @@ -286,17 +273,17 @@ /** * Normalizes the given group or list of groups to an array. * - * @param mixed $groups The groups to normalize + * @param string|GroupSequence|(string|GroupSequence)[] $groups The groups to normalize * - * @return array A group array + * @return (string|GroupSequence)[] A group array */ protected function normalizeGroups($groups) { - if (is_array($groups)) { + if (\is_array($groups)) { return $groups; } - return array($groups); + return [$groups]; } /** @@ -309,7 +296,7 @@ * * @param object $object The object to cascade * @param string $propertyPath The current property path - * @param string[] $groups The validated groups + * @param (string|GroupSequence)[] $groups The validated groups * @param int $traversalStrategy The strategy for traversing the * cascaded object * @param ExecutionContextInterface $context The current execution context @@ -328,12 +315,7 @@ $classMetadata = $this->metadataFactory->getMetadataFor($object); if (!$classMetadata instanceof ClassMetadataInterface) { - throw new UnsupportedMetadataException(sprintf( - 'The metadata factory should return instances of '. - '"Symfony\Component\Validator\Mapping\ClassMetadataInterface", '. - 'got: "%s".', - is_object($classMetadata) ? get_class($classMetadata) : gettype($classMetadata) - )); + throw new UnsupportedMetadataException(sprintf('The metadata factory should return instances of "Symfony\Component\Validator\Mapping\ClassMetadataInterface", got: "%s".', \is_object($classMetadata) ? \get_class($classMetadata) : \gettype($classMetadata))); } $this->validateClassNode( @@ -376,7 +358,7 @@ * * @param iterable $collection The collection * @param string $propertyPath The current property path - * @param string[] $groups The validated groups + * @param (string|GroupSequence)[] $groups The validated groups * @param ExecutionContextInterface $context The current execution context * * @see ClassNode @@ -385,7 +367,7 @@ private function validateEachObjectIn($collection, $propertyPath, array $groups, ExecutionContextInterface $context) { foreach ($collection as $key => $value) { - if (is_array($value)) { + if (\is_array($value)) { // Arrays are always cascaded, independent of the specified // traversal strategy $this->validateEachObjectIn( @@ -399,7 +381,7 @@ } // Scalar and null values in the collection are ignored - if (is_object($value)) { + if (\is_object($value)) { $this->validateObject( $value, $propertyPath.'['.$key.']', @@ -443,7 +425,7 @@ * the object * @param string $propertyPath The property path leading * to the object - * @param string[] $groups The groups in which the + * @param (string|GroupSequence)[] $groups The groups in which the * object should be validated * @param string[]|null $cascadedGroups The groups in which * cascaded objects should @@ -479,7 +461,7 @@ $defaultOverridden = false; // Use the object hash for group sequences - $groupHash = is_object($group) ? spl_object_hash($group) : $group; + $groupHash = \is_object($group) ? spl_object_hash($group) : $group; if ($context->isGroupValidated($cacheKey, $groupHash)) { // Skip this group when validating the properties and when @@ -544,7 +526,7 @@ // If no more groups should be validated for the property nodes, // we can safely quit - if (0 === count($groups)) { + if (0 === \count($groups)) { return; } @@ -555,12 +537,7 @@ // returns two metadata objects, not just one foreach ($metadata->getPropertyMetadata($propertyName) as $propertyMetadata) { if (!$propertyMetadata instanceof PropertyMetadataInterface) { - throw new UnsupportedMetadataException(sprintf( - 'The property metadata instances should implement '. - '"Symfony\Component\Validator\Mapping\PropertyMetadataInterface", '. - 'got: "%s".', - is_object($propertyMetadata) ? get_class($propertyMetadata) : gettype($propertyMetadata) - )); + throw new UnsupportedMetadataException(sprintf('The property metadata instances should implement "Symfony\Component\Validator\Mapping\PropertyMetadataInterface", got: "%s".', \is_object($propertyMetadata) ? \get_class($propertyMetadata) : \gettype($propertyMetadata))); } $propertyValue = $propertyMetadata->getPropertyValue($object); @@ -568,7 +545,7 @@ $this->validateGenericNode( $propertyValue, $object, - $cacheKey.':'.get_class($object).':'.$propertyName, + $cacheKey.':'.\get_class($object).':'.$propertyName, $propertyMetadata, PropertyPath::append($propertyPath, $propertyName), $groups, @@ -597,11 +574,7 @@ // If TRAVERSE, fail if we have no Traversable if (!$object instanceof \Traversable) { - throw new ConstraintDefinitionException(sprintf( - 'Traversal was enabled for "%s", but this class '. - 'does not implement "\Traversable".', - get_class($object) - )); + throw new ConstraintDefinitionException(sprintf('Traversal was enabled for "%s", but this class does not implement "\Traversable".', \get_class($object))); } $this->validateEachObjectIn( @@ -636,7 +609,7 @@ * value * @param string $propertyPath The property path leading * to the value - * @param string[] $groups The groups in which the + * @param (string|GroupSequence)[] $groups The groups in which the * value should be validated * @param string[]|null $cascadedGroups The groups in which * cascaded objects should @@ -675,7 +648,7 @@ $this->validateInGroup($value, $cacheKey, $metadata, $group, $context); } - if (0 === count($groups)) { + if (0 === \count($groups)) { return; } @@ -686,7 +659,7 @@ $cascadingStrategy = $metadata->getCascadingStrategy(); // Quit unless we have an array or a cascaded object - if (!is_array($value) && !($cascadingStrategy & CascadingStrategy::CASCADE)) { + if (!\is_array($value) && !($cascadingStrategy & CascadingStrategy::CASCADE)) { return; } @@ -699,9 +672,9 @@ // The $cascadedGroups property is set, if the "Default" group is // overridden by a group sequence // See validateClassNode() - $cascadedGroups = null !== $cascadedGroups && count($cascadedGroups) > 0 ? $cascadedGroups : $groups; + $cascadedGroups = null !== $cascadedGroups && \count($cascadedGroups) > 0 ? $cascadedGroups : $groups; - if (is_array($value)) { + if (\is_array($value)) { // Arrays are always traversed, independent of the specified // traversal strategy $this->validateEachObjectIn( @@ -757,8 +730,8 @@ */ private function stepThroughGroupSequence($value, $object, $cacheKey, MetadataInterface $metadata = null, $propertyPath, $traversalStrategy, GroupSequence $groupSequence, $cascadedGroup, ExecutionContextInterface $context) { - $violationCount = count($context->getViolations()); - $cascadedGroups = $cascadedGroup ? array($cascadedGroup) : null; + $violationCount = \count($context->getViolations()); + $cascadedGroups = $cascadedGroup ? [$cascadedGroup] : null; foreach ($groupSequence->groups as $groupInSequence) { $groups = (array) $groupInSequence; @@ -789,7 +762,7 @@ } // Abort sequence validation if a violation was generated - if (count($context->getViolations()) > $violationCount) { + if (\count($context->getViolations()) > $violationCount) { break; } } @@ -815,6 +788,10 @@ if (null !== $cacheKey) { $constraintHash = spl_object_hash($constraint); + if ($constraint instanceof Composite) { + $constraintHash .= $group; + } + if ($context->isConstraintValidated($cacheKey, $constraintHash)) { continue; }