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\Constraints\GroupSequence;
16use Symfony\Component\Validator\ConstraintViolationListInterface;
17use Symfony\Component\Validator\Context\ExecutionContextInterface;
18use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
19
20/**
21 * Validates PHP values against constraints.
22 *
23 * @author Bernhard Schussek <bschussek@gmail.com>
24 */
25interface ValidatorInterface extends MetadataFactoryInterface
26{
27    /**
28     * Validates a value against a constraint or a list of constraints.
29     *
30     * If no constraint is passed, the constraint
31     * {@link \Symfony\Component\Validator\Constraints\Valid} is assumed.
32     *
33     * @param mixed                                              $value       The value to validate
34     * @param Constraint|Constraint[]                            $constraints The constraint(s) to validate against
35     * @param string|GroupSequence|(string|GroupSequence)[]|null $groups      The validation groups to validate. If none is given, "Default" is assumed
36     *
37     * @return ConstraintViolationListInterface A list of constraint violations
38     *                                          If the list is empty, validation
39     *                                          succeeded
40     */
41    public function validate($value, $constraints = null, $groups = null);
42
43    /**
44     * Validates a property of an object against the constraints specified
45     * for this property.
46     *
47     * @param object                                             $object       The object
48     * @param string                                             $propertyName The name of the validated property
49     * @param string|GroupSequence|(string|GroupSequence)[]|null $groups       The validation groups to validate. If none is given, "Default" is assumed
50     *
51     * @return ConstraintViolationListInterface A list of constraint violations
52     *                                          If the list is empty, validation
53     *                                          succeeded
54     */
55    public function validateProperty($object, $propertyName, $groups = null);
56
57    /**
58     * Validates a value against the constraints specified for an object's
59     * property.
60     *
61     * @param object|string                                      $objectOrClass The object or its class name
62     * @param string                                             $propertyName  The name of the property
63     * @param mixed                                              $value         The value to validate against the property's constraints
64     * @param string|GroupSequence|(string|GroupSequence)[]|null $groups        The validation groups to validate. If none is given, "Default" is assumed
65     *
66     * @return ConstraintViolationListInterface A list of constraint violations
67     *                                          If the list is empty, validation
68     *                                          succeeded
69     */
70    public function validatePropertyValue($objectOrClass, $propertyName, $value, $groups = null);
71
72    /**
73     * Starts a new validation context and returns a validator for that context.
74     *
75     * The returned validator collects all violations generated within its
76     * context. You can access these violations with the
77     * {@link ContextualValidatorInterface::getViolations()} method.
78     *
79     * @return ContextualValidatorInterface The validator for the new context
80     */
81    public function startContext();
82
83    /**
84     * Returns a validator in the given execution context.
85     *
86     * The returned validator adds all generated violations to the given
87     * context.
88     *
89     * @return ContextualValidatorInterface The validator for that context
90     */
91    public function inContext(ExecutionContextInterface $context);
92}
93