ConstraintViolationBuilderInterface.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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\Violation;
  11. /**
  12. * Builds {@link \Symfony\Component\Validator\ConstraintViolationInterface}
  13. * objects.
  14. *
  15. * Use the various methods on this interface to configure the built violation.
  16. * Finally, call {@link addViolation()} to add the violation to the current
  17. * execution context.
  18. *
  19. * @since 2.5
  20. *
  21. * @author Bernhard Schussek <bschussek@gmail.com>
  22. */
  23. interface ConstraintViolationBuilderInterface
  24. {
  25. /**
  26. * Stores the property path at which the violation should be generated.
  27. *
  28. * The passed path will be appended to the current property path of the
  29. * execution context.
  30. *
  31. * @param string $path The property path
  32. *
  33. * @return ConstraintViolationBuilderInterface This builder
  34. */
  35. public function atPath($path);
  36. /**
  37. * Sets a parameter to be inserted into the violation message.
  38. *
  39. * @param string $key The name of the parameter
  40. * @param string $value The value to be inserted in the parameter's place
  41. *
  42. * @return ConstraintViolationBuilderInterface This builder
  43. */
  44. public function setParameter($key, $value);
  45. /**
  46. * Sets all parameters to be inserted into the violation message.
  47. *
  48. * @param array $parameters An array with the parameter names as keys and
  49. * the values to be inserted in their place as
  50. * values
  51. *
  52. * @return ConstraintViolationBuilderInterface This builder
  53. */
  54. public function setParameters(array $parameters);
  55. /**
  56. * Sets the translation domain which should be used for translating the
  57. * violation message.
  58. *
  59. * @param string $translationDomain The translation domain
  60. *
  61. * @return ConstraintViolationBuilderInterface This builder
  62. *
  63. * @see \Symfony\Component\Translation\TranslatorInterface
  64. */
  65. public function setTranslationDomain($translationDomain);
  66. /**
  67. * Sets the invalid value that caused this violation.
  68. *
  69. * @param mixed $invalidValue The invalid value
  70. *
  71. * @return ConstraintViolationBuilderInterface This builder
  72. */
  73. public function setInvalidValue($invalidValue);
  74. /**
  75. * Sets the number which determines how the plural form of the violation
  76. * message is chosen when it is translated.
  77. *
  78. * @param int $number The number for determining the plural form
  79. *
  80. * @return ConstraintViolationBuilderInterface This builder
  81. *
  82. * @see \Symfony\Component\Translation\TranslatorInterface::transChoice()
  83. */
  84. public function setPlural($number);
  85. /**
  86. * Sets the violation code.
  87. *
  88. * @param string|null $code The violation code
  89. *
  90. * @return ConstraintViolationBuilderInterface This builder
  91. */
  92. public function setCode($code);
  93. /**
  94. * Sets the cause of the violation.
  95. *
  96. * @param mixed $cause The cause of the violation
  97. *
  98. * @return ConstraintViolationBuilderInterface This builder
  99. */
  100. public function setCause($cause);
  101. /**
  102. * Adds the violation to the current execution context.
  103. */
  104. public function addViolation();
  105. }