ContextualValidatorInterface.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. /**
  15. * A validator in a specific execution context.
  16. *
  17. * @author Bernhard Schussek <bschussek@gmail.com>
  18. */
  19. interface ContextualValidatorInterface
  20. {
  21. /**
  22. * Appends the given path to the property path of the context.
  23. *
  24. * If called multiple times, the path will always be reset to the context's
  25. * original path with the given path appended to it.
  26. *
  27. * @param string $path The path to append
  28. *
  29. * @return $this
  30. */
  31. public function atPath($path);
  32. /**
  33. * Validates a value against a constraint or a list of constraints.
  34. *
  35. * If no constraint is passed, the constraint
  36. * {@link \Symfony\Component\Validator\Constraints\Valid} is assumed.
  37. *
  38. * @param mixed $value The value to validate
  39. * @param Constraint|Constraint[] $constraints The constraint(s) to validate against
  40. * @param string|GroupSequence|(string|GroupSequence)[]|null $groups The validation groups to validate. If none is given, "Default" is assumed
  41. *
  42. * @return $this
  43. */
  44. public function validate($value, $constraints = null, $groups = null);
  45. /**
  46. * Validates a property of an object against the constraints specified
  47. * for this property.
  48. *
  49. * @param object $object The object
  50. * @param string $propertyName The name of the validated property
  51. * @param string|GroupSequence|(string|GroupSequence)[]|null $groups The validation groups to validate. If none is given, "Default" is assumed
  52. *
  53. * @return $this
  54. */
  55. public function validateProperty($object, $propertyName, $groups = null);
  56. /**
  57. * Validates a value against the constraints specified for an object's
  58. * property.
  59. *
  60. * @param object|string $objectOrClass The object or its class name
  61. * @param string $propertyName The name of the property
  62. * @param mixed $value The value to validate against the property's constraints
  63. * @param string|GroupSequence|(string|GroupSequence)[]|null $groups The validation groups to validate. If none is given, "Default" is assumed
  64. *
  65. * @return $this
  66. */
  67. public function validatePropertyValue($objectOrClass, $propertyName, $value, $groups = null);
  68. /**
  69. * Returns the violations that have been generated so far in the context
  70. * of the validator.
  71. *
  72. * @return ConstraintViolationListInterface The constraint violations
  73. */
  74. public function getViolations();
  75. }