ValidatorInterface.php 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Validator\Validator;
  11. use Symfony\Component\Validator\Constraint;
  12. use Symfony\Component\Validator\Constraints\GroupSequence;
  13. use Symfony\Component\Validator\ConstraintViolationListInterface;
  14. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  15. use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
  16. /**
  17. * Validates PHP values against constraints.
  18. *
  19. * @author Bernhard Schussek <bschussek@gmail.com>
  20. */
  21. interface ValidatorInterface extends MetadataFactoryInterface
  22. {
  23. /**
  24. * Validates a value against a constraint or a list of constraints.
  25. *
  26. * If no constraint is passed, the constraint
  27. * {@link \Symfony\Component\Validator\Constraints\Valid} is assumed.
  28. *
  29. * @param mixed $value The value to validate
  30. * @param Constraint|Constraint[] $constraints The constraint(s) to validate against
  31. * @param string|GroupSequence|(string|GroupSequence)[]|null $groups The validation groups to validate. If none is given, "Default" is assumed
  32. *
  33. * @return ConstraintViolationListInterface A list of constraint violations
  34. * If the list is empty, validation
  35. * succeeded
  36. */
  37. public function validate($value, $constraints = null, $groups = null);
  38. /**
  39. * Validates a property of an object against the constraints specified
  40. * for this property.
  41. *
  42. * @param object $object The object
  43. * @param string $propertyName The name of the validated property
  44. * @param string|GroupSequence|(string|GroupSequence)[]|null $groups The validation groups to validate. If none is given, "Default" is assumed
  45. *
  46. * @return ConstraintViolationListInterface A list of constraint violations
  47. * If the list is empty, validation
  48. * succeeded
  49. */
  50. public function validateProperty($object, string $propertyName, $groups = null);
  51. /**
  52. * Validates a value against the constraints specified for an object's
  53. * property.
  54. *
  55. * @param object|string $objectOrClass The object or its class name
  56. * @param string $propertyName The name of the property
  57. * @param mixed $value The value to validate against the property's constraints
  58. * @param string|GroupSequence|(string|GroupSequence)[]|null $groups The validation groups to validate. If none is given, "Default" is assumed
  59. *
  60. * @return ConstraintViolationListInterface A list of constraint violations
  61. * If the list is empty, validation
  62. * succeeded
  63. */
  64. public function validatePropertyValue($objectOrClass, string $propertyName, $value, $groups = null);
  65. /**
  66. * Starts a new validation context and returns a validator for that context.
  67. *
  68. * The returned validator collects all violations generated within its
  69. * context. You can access these violations with the
  70. * {@link ContextualValidatorInterface::getViolations()} method.
  71. *
  72. * @return ContextualValidatorInterface The validator for the new context
  73. */
  74. public function startContext();
  75. /**
  76. * Returns a validator in the given execution context.
  77. *
  78. * The returned validator adds all generated violations to the given
  79. * context.
  80. *
  81. * @return ContextualValidatorInterface The validator for that context
  82. */
  83. public function inContext(ExecutionContextInterface $context);
  84. }