use Symfony\Component\Validator\Mapping\MetadataInterface;
use Symfony\Component\Validator\Mapping\PropertyMetadataInterface;
use Symfony\Component\Validator\Mapping\TraversalStrategy;
-use Symfony\Component\Validator\MetadataFactoryInterface;
+use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
use Symfony\Component\Validator\ObjectInitializerInterface;
use Symfony\Component\Validator\Util\PropertyPath;
$value,
$this->defaultPropertyPath,
$groups,
- true,
$this->context
);
$classMetadata = $this->metadataFactory->getMetadataFor($object);
if (!$classMetadata instanceof ClassMetadataInterface) {
- // Cannot be UnsupportedMetadataException because of BC with
- // Symfony < 2.5
throw new ValidatorException(sprintf(
'The metadata factory should return instances of '.
'"\Symfony\Component\Validator\Mapping\ClassMetadataInterface", '.
$this->validateGenericNode(
$propertyValue,
$object,
- $cacheKey.':'.$propertyName,
+ $cacheKey.':'.get_class($object).':'.$propertyName,
$propertyMetadata,
$propertyPath,
$groups,
$classMetadata = $this->metadataFactory->getMetadataFor($objectOrClass);
if (!$classMetadata instanceof ClassMetadataInterface) {
- // Cannot be UnsupportedMetadataException because of BC with
- // Symfony < 2.5
throw new ValidatorException(sprintf(
'The metadata factory should return instances of '.
'"\Symfony\Component\Validator\Mapping\ClassMetadataInterface", '.
$this->validateGenericNode(
$value,
$object,
- $cacheKey.':'.$propertyName,
+ $cacheKey.':'.get_class($object).':'.$propertyName,
$propertyMetadata,
$propertyPath,
$groups,
$object,
$propertyPath,
$groups,
- $traversalStrategy & TraversalStrategy::STOP_RECURSION,
$context
);
}
* objects are iterated as well. Nested arrays are always iterated,
* regardless of the value of $recursive.
*
- * @param array|\Traversable $collection The collection
- * @param string $propertyPath The current property path
- * @param string[] $groups The validated groups
- * @param bool $stopRecursion Whether to disable
- * recursive iteration. For
- * backwards compatibility
- * with Symfony < 2.5.
- * @param ExecutionContextInterface $context The current execution context
+ * @param array|\Traversable $collection The collection
+ * @param string $propertyPath The current property path
+ * @param string[] $groups The validated groups
+ * @param ExecutionContextInterface $context The current execution context
*
* @see ClassNode
* @see CollectionNode
*/
- private function validateEachObjectIn($collection, $propertyPath, array $groups, $stopRecursion, ExecutionContextInterface $context)
+ private function validateEachObjectIn($collection, $propertyPath, array $groups, ExecutionContextInterface $context)
{
- if ($stopRecursion) {
- $traversalStrategy = TraversalStrategy::NONE;
- } else {
- $traversalStrategy = TraversalStrategy::IMPLICIT;
- }
-
foreach ($collection as $key => $value) {
if (is_array($value)) {
// Arrays are always cascaded, independent of the specified
// traversal strategy
- // (BC with Symfony < 2.5)
$this->validateEachObjectIn(
$value,
$propertyPath.'['.$key.']',
$groups,
- $stopRecursion,
$context
);
}
// Scalar and null values in the collection are ignored
- // (BC with Symfony < 2.5)
if (is_object($value)) {
$this->validateObject(
$value,
$propertyPath.'['.$key.']',
$groups,
- $traversalStrategy,
+ TraversalStrategy::IMPLICIT,
$context
);
}
$this->validateGenericNode(
$propertyValue,
$object,
- $cacheKey.':'.$propertyName,
+ $cacheKey.':'.get_class($object).':'.$propertyName,
$propertyMetadata,
PropertyPath::append($propertyPath, $propertyName),
$groups,
// If no specific traversal strategy was requested when this method
// was called, use the traversal strategy of the class' metadata
if ($traversalStrategy & TraversalStrategy::IMPLICIT) {
- // Keep the STOP_RECURSION flag, if it was set
- $traversalStrategy = $metadata->getTraversalStrategy()
- | ($traversalStrategy & TraversalStrategy::STOP_RECURSION);
+ $traversalStrategy = $metadata->getTraversalStrategy();
}
// Traverse only if IMPLICIT or TRAVERSE
// If TRAVERSE, fail if we have no Traversable
if (!$object instanceof \Traversable) {
- // Must throw a ConstraintDefinitionException for backwards
- // compatibility reasons with Symfony < 2.5
throw new ConstraintDefinitionException(sprintf(
'Traversal was enabled for "%s", but this class '.
'does not implement "\Traversable".',
$object,
$propertyPath,
$groups,
- $traversalStrategy & TraversalStrategy::STOP_RECURSION,
$context
);
}
// If no specific traversal strategy was requested when this method
// was called, use the traversal strategy of the node's metadata
if ($traversalStrategy & TraversalStrategy::IMPLICIT) {
- // Keep the STOP_RECURSION flag, if it was set
- $traversalStrategy = $metadata->getTraversalStrategy()
- | ($traversalStrategy & TraversalStrategy::STOP_RECURSION);
+ $traversalStrategy = $metadata->getTraversalStrategy();
}
// The $cascadedGroups property is set, if the "Default" group is
if (is_array($value)) {
// Arrays are always traversed, independent of the specified
// traversal strategy
- // (BC with Symfony < 2.5)
$this->validateEachObjectIn(
$value,
$propertyPath,
$cascadedGroups,
- $traversalStrategy & TraversalStrategy::STOP_RECURSION,
$context
);
// If the value is a scalar, pass it anyway, because we want
// a NoSuchMetadataException to be thrown in that case
- // (BC with Symfony < 2.5)
$this->validateObject(
$value,
$propertyPath,
$cascadedGroups = $cascadedGroup ? array($cascadedGroup) : null;
foreach ($groupSequence->groups as $groupInSequence) {
- $groups = array($groupInSequence);
+ $groups = (array) $groupInSequence;
if ($metadata instanceof ClassMetadataInterface) {
$this->validateClassNode(