|
12 | 12 | namespace Symfony\Component\Validator\NodeTraverser; |
13 | 13 |
|
14 | 14 | use Symfony\Component\Validator\Context\ExecutionContextInterface; |
| 15 | +use Symfony\Component\Validator\Node\Node; |
15 | 16 | use Symfony\Component\Validator\NodeVisitor\NodeVisitorInterface; |
16 | 17 |
|
17 | 18 | /** |
18 | | - * @since %%NextVersion%% |
| 19 | + * Traverses the nodes of the validation graph. |
| 20 | + * |
| 21 | + * You can attach visitors to the traverser that are invoked during the |
| 22 | + * traversal. Before starting the traversal, the |
| 23 | + * {@link \Symfony\Component\Validator\NodeVisitor\NodeVisitorInterface::beforeTraversal()} |
| 24 | + * method of each visitor is called. For each node in the graph, the |
| 25 | + * {@link \Symfony\Component\Validator\NodeVisitor\NodeVisitorInterface::visit()} |
| 26 | + * of each visitor is called. At the end of the traversal, the traverser invokes |
| 27 | + * {@link \Symfony\Component\Validator\NodeVisitor\NodeVisitorInterface::afterTraversal()} |
| 28 | + * on each visitor. |
| 29 | + * |
| 30 | + * The visitors should be called in the same order in which they are added to |
| 31 | + * the traverser. |
| 32 | + * |
| 33 | + * The validation graph typically contains nodes of the following types: |
| 34 | + * |
| 35 | + * - {@link \Symfony\Component\Validator\Node\ClassNode}: |
| 36 | + * An object with associated class metadata |
| 37 | + * - {@link \Symfony\Component\Validator\Node\PropertyNode}: |
| 38 | + * A property value with associated property metadata |
| 39 | + * - {@link \Symfony\Component\Validator\Node\GenericNode}: |
| 40 | + * A generic value with associated constraints |
| 41 | + * - {@link \Symfony\Component\Validator\Node\CollectionNode}: |
| 42 | + * A traversable collection |
| 43 | + * |
| 44 | + * Generic nodes are mostly useful when you want to validate a value that has |
| 45 | + * neither associated class nor property metadata. Generic nodes usually come |
| 46 | + * with {@link \Symfony\Component\Validator\Mapping\GenericMetadata}, that |
| 47 | + * contains the constraints that the value should be validated against. |
| 48 | + * |
| 49 | + * Whenever a class, property or generic node is validated that contains a |
| 50 | + * traversable value which should be traversed (according to the |
| 51 | + * {@link \Symfony\Component\Validator\Mapping\TraversalStrategy} specified |
| 52 | + * in the node or its metadata), a new |
| 53 | + * {@link \Symfony\Component\Validator\Node\CollectionNode} will be attached |
| 54 | + * to the node graph. |
| 55 | + * |
| 56 | + * For example: |
| 57 | + * |
| 58 | + * (TagList:ClassNode) |
| 59 | + * \ |
| 60 | + * (TagList:CollectionNode) |
| 61 | + * |
| 62 | + * When writing custom visitors, be aware that collection nodes usually contain |
| 63 | + * values that have already been passed to the visitor before through a class |
| 64 | + * node, a property node or a generic node. |
| 65 | + * |
| 66 | + * @since 2.5 |
19 | 67 | * @author Bernhard Schussek <[email protected]> |
20 | 68 | */ |
21 | 69 | interface NodeTraverserInterface |
22 | 70 | { |
| 71 | + /** |
| 72 | + * Adds a new visitor to the traverser. |
| 73 | + * |
| 74 | + * Visitors that have already been added before are ignored. |
| 75 | + * |
| 76 | + * @param NodeVisitorInterface $visitor The visitor to add |
| 77 | + */ |
23 | 78 | public function addVisitor(NodeVisitorInterface $visitor); |
24 | 79 |
|
| 80 | + /** |
| 81 | + * Removes a visitor from the traverser. |
| 82 | + * |
| 83 | + * Non-existing visitors are ignored. |
| 84 | + * |
| 85 | + * @param NodeVisitorInterface $visitor The visitor to remove |
| 86 | + */ |
25 | 87 | public function removeVisitor(NodeVisitorInterface $visitor); |
26 | 88 |
|
| 89 | + /** |
| 90 | + * Traverses the given nodes in the given context. |
| 91 | + * |
| 92 | + * @param Node[] $nodes The nodes to traverse |
| 93 | + * @param ExecutionContextInterface $context The validation context |
| 94 | + */ |
27 | 95 | public function traverse(array $nodes, ExecutionContextInterface $context); |
28 | 96 | } |
0 commit comments