-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
CollectionNode.php
66 lines (61 loc) · 2.39 KB
/
CollectionNode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Validator\Node;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
use Symfony\Component\Validator\Mapping\TraversalStrategy;
/**
* Represents a traversable value in the validation graph.
*
* @since 2.5
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class CollectionNode extends Node
{
/**
* Creates a new collection node.
*
* @param array|\Traversable $collection The validated collection
* @param string $propertyPath The property path leading
* to this node
* @param string[] $groups The groups in which this
* node should be validated
* @param string[]|null $cascadedGroups The groups in which
* cascaded objects should be
* validated
* @param integer $traversalStrategy The strategy used for
* traversing the collection
*
* @throws ConstraintDefinitionException If $collection is not an array or a
* \Traversable
*
* @see \Symfony\Component\Validator\Mapping\TraversalStrategy
*/
public function __construct($collection, $propertyPath, array $groups, $cascadedGroups = null, $traversalStrategy = TraversalStrategy::TRAVERSE)
{
if (!is_array($collection) && !$collection 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".',
get_class($collection)
));
}
parent::__construct(
$collection,
null,
null,
$propertyPath,
$groups,
$cascadedGroups,
$traversalStrategy
);
}
}