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\Validator;
14 use Symfony\Component\Validator\Constraint;
15 use Symfony\Component\Validator\Constraints\GroupSequence;
16 use Symfony\Component\Validator\ConstraintViolationListInterface;
17 use Symfony\Component\Validator\Context\ExecutionContextInterface;
18 use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
21 * Validates PHP values against constraints.
23 * @author Bernhard Schussek <bschussek@gmail.com>
25 interface ValidatorInterface extends MetadataFactoryInterface
28 * Validates a value against a constraint or a list of constraints.
30 * If no constraint is passed, the constraint
31 * {@link \Symfony\Component\Validator\Constraints\Valid} is assumed.
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
37 * @return ConstraintViolationListInterface A list of constraint violations
38 * If the list is empty, validation
41 public function validate($value, $constraints = null, $groups = null);
44 * Validates a property of an object against the constraints specified
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
51 * @return ConstraintViolationListInterface A list of constraint violations
52 * If the list is empty, validation
55 public function validateProperty($object, $propertyName, $groups = null);
58 * Validates a value against the constraints specified for an object's
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
66 * @return ConstraintViolationListInterface A list of constraint violations
67 * If the list is empty, validation
70 public function validatePropertyValue($objectOrClass, $propertyName, $value, $groups = null);
73 * Starts a new validation context and returns a validator for that context.
75 * The returned validator collects all violations generated within its
76 * context. You can access these violations with the
77 * {@link ContextualValidatorInterface::getViolations()} method.
79 * @return ContextualValidatorInterface The validator for the new context
81 public function startContext();
84 * Returns a validator in the given execution context.
86 * The returned validator adds all generated violations to the given
89 * @return ContextualValidatorInterface The validator for that context
91 public function inContext(ExecutionContextInterface $context);