ValidatorInterface.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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, $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, $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. }