1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Validator\Validator;
13
14use Symfony\Component\Validator\Constraint;
15use Symfony\Component\Validator\ConstraintViolationListInterface;
16
17/**
18 * A validator in a specific execution context.
19 *
20 * @since  2.5
21 * @author Bernhard Schussek <bschussek@gmail.com>
22 */
23interface ContextualValidatorInterface
24{
25    /**
26     * Appends the given path to the property path of the context.
27     *
28     * If called multiple times, the path will always be reset to the context's
29     * original path with the given path appended to it.
30     *
31     * @param string $path The path to append
32     *
33     * @return ContextualValidatorInterface This validator
34     */
35    public function atPath($path);
36
37    /**
38     * Validates a value against a constraint or a list of constraints.
39     *
40     * If no constraint is passed, the constraint
41     * {@link \Symfony\Component\Validator\Constraints\Valid} is assumed.
42     *
43     * @param mixed                   $value       The value to validate
44     * @param Constraint|Constraint[] $constraints The constraint(s) to validate
45     *                                             against
46     * @param array|null              $groups      The validation groups to
47     *                                             validate. If none is given,
48     *                                             "Default" is assumed
49     *
50     * @return ContextualValidatorInterface This validator
51     */
52    public function validate($value, $constraints = null, $groups = null);
53
54    /**
55     * Validates a property of an object against the constraints specified
56     * for this property.
57     *
58     * @param object     $object       The object
59     * @param string     $propertyName The name of the validated property
60     * @param array|null $groups       The validation groups to validate. If
61     *                                 none is given, "Default" is assumed
62     *
63     * @return ContextualValidatorInterface This validator
64     */
65    public function validateProperty($object, $propertyName, $groups = null);
66
67    /**
68     * Validates a value against the constraints specified for an object's
69     * property.
70     *
71     * @param object|string $objectOrClass The object or its class name
72     * @param string        $propertyName  The name of the property
73     * @param mixed         $value         The value to validate against the
74     *                                     property's constraints
75     * @param array|null    $groups        The validation groups to validate. If
76     *                                     none is given, "Default" is assumed
77     *
78     * @return ContextualValidatorInterface This validator
79     */
80    public function validatePropertyValue($objectOrClass, $propertyName, $value, $groups = null);
81
82    /**
83     * Returns the violations that have been generated so far in the context
84     * of the validator.
85     *
86     * @return ConstraintViolationListInterface The constraint violations
87     */
88    public function getViolations();
89}
90