4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Validator;
15 * Validates values against constraints defined in {@link MetadataInterface}
18 * This interface is an implementation of the Visitor design pattern. A value
19 * is validated by first passing it to the {@link validate} method. That method
20 * will determine the matching {@link MetadataInterface} for validating the
21 * value. It then calls the {@link MetadataInterface::accept} method of that
22 * metadata. <tt>accept()</tt> does two things:
25 * <li>It calls {@link visit} to validate the value against the constraints of
27 * <li>It calls <tt>accept()</tt> on all nested metadata instances with the
28 * corresponding values extracted from the current value. For example, if the
29 * current metadata represents a class and the current value is an object of
30 * that class, the metadata contains nested instances for each property of that
31 * class. It forwards the call to these nested metadata with the values of the
32 * corresponding properties in the original object.</li>
35 * @author Bernhard Schussek <bschussek@gmail.com>
37 * @deprecated since version 2.5, to be removed in 3.0.
39 interface ValidationVisitorInterface
44 * If the value is an array or a traversable object, you can set the
45 * parameter <tt>$traverse</tt> to <tt>true</tt> in order to run through
46 * the collection and validate each element. If these elements can be
47 * collections again and you want to traverse them recursively, set the
48 * parameter <tt>$deep</tt> to <tt>true</tt> as well.
50 * If you set <tt>$traversable</tt> to <tt>true</tt>, the visitor will
51 * nevertheless try to find metadata for the collection and validate its
52 * constraints. If no such metadata is found, the visitor ignores that and
53 * only iterates the collection.
55 * If you don't set <tt>$traversable</tt> to <tt>true</tt> and the visitor
56 * does not find metadata for the given value, it will fail with an
59 * @param mixed $value The value to validate
60 * @param string $group The validation group to validate
61 * @param string $propertyPath The current property path in the validation graph
62 * @param bool $traverse Whether to traverse the value if it is traversable
63 * @param bool $deep Whether to traverse nested traversable values recursively
65 * @throws Exception\NoSuchMetadataException If no metadata can be found for
68 public function validate($value, $group, $propertyPath, $traverse = false, $deep = false);
71 * Validates a value against the constraints defined in some metadata.
73 * This method implements the Visitor design pattern. See also
74 * {@link ValidationVisitorInterface}.
76 * @param MetadataInterface $metadata The metadata holding the constraints
77 * @param mixed $value The value to validate
78 * @param string $group The validation group to validate
79 * @param string $propertyPath The current property path in the validation graph
81 public function visit(MetadataInterface $metadata, $value, $group, $propertyPath);