Drupal investigation

ConstraintViolationInterface.php 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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;
  11. /**
  12. * A violation of a constraint that happened during validation.
  13. *
  14. * For each constraint that fails during validation one or more violations are
  15. * created. The violations store the violation message, the path to the failing
  16. * element in the validation graph and the root element that was originally
  17. * passed to the validator. For example, take the following graph:
  18. *
  19. * <pre>
  20. * (Person)---(firstName: string)
  21. * \
  22. * (address: Address)---(street: string)
  23. * </pre>
  24. *
  25. * If the <tt>Person</tt> object is validated and validation fails for the
  26. * "firstName" property, the generated violation has the <tt>Person</tt>
  27. * instance as root and the property path "firstName". If validation fails
  28. * for the "street" property of the related <tt>Address</tt> instance, the root
  29. * element is still the person, but the property path is "address.street".
  30. *
  31. * @author Bernhard Schussek <bschussek@gmail.com>
  32. */
  33. interface ConstraintViolationInterface
  34. {
  35. /**
  36. * Returns the violation message.
  37. *
  38. * @return string The violation message
  39. */
  40. public function getMessage();
  41. /**
  42. * Returns the raw violation message.
  43. *
  44. * The raw violation message contains placeholders for the parameters
  45. * returned by {@link getMessageParameters}. Typically you'll pass the
  46. * message template and parameters to a translation engine.
  47. *
  48. * @return string The raw violation message
  49. */
  50. public function getMessageTemplate();
  51. /**
  52. * Returns the parameters to be inserted into the raw violation message.
  53. *
  54. * @return array A possibly empty list of parameters indexed by the names
  55. * that appear in the message template.
  56. *
  57. * @see getMessageTemplate()
  58. * @deprecated since version 2.7, to be replaced by getParameters() in 3.0.
  59. */
  60. public function getMessageParameters();
  61. /**
  62. * Returns a number for pluralizing the violation message.
  63. *
  64. * For example, the message template could have different translation based
  65. * on a parameter "choices":
  66. *
  67. * <ul>
  68. * <li>Please select exactly one entry. (choices=1)</li>
  69. * <li>Please select two entries. (choices=2)</li>
  70. * </ul>
  71. *
  72. * This method returns the value of the parameter for choosing the right
  73. * pluralization form (in this case "choices").
  74. *
  75. * @return int|null The number to use to pluralize of the message
  76. *
  77. * @deprecated since version 2.7, to be replaced by getPlural() in 3.0.
  78. */
  79. public function getMessagePluralization();
  80. /**
  81. * Returns the root element of the validation.
  82. *
  83. * @return mixed The value that was passed originally to the validator when
  84. * the validation was started. Because the validator traverses
  85. * the object graph, the value at which the violation occurs
  86. * is not necessarily the value that was originally validated.
  87. */
  88. public function getRoot();
  89. /**
  90. * Returns the property path from the root element to the violation.
  91. *
  92. * @return string The property path indicates how the validator reached
  93. * the invalid value from the root element. If the root
  94. * element is a <tt>Person</tt> instance with a property
  95. * "address" that contains an <tt>Address</tt> instance
  96. * with an invalid property "street", the generated property
  97. * path is "address.street". Property access is denoted by
  98. * dots, while array access is denoted by square brackets,
  99. * for example "addresses[1].street".
  100. */
  101. public function getPropertyPath();
  102. /**
  103. * Returns the value that caused the violation.
  104. *
  105. * @return mixed The invalid value that caused the validated constraint to
  106. * fail.
  107. */
  108. public function getInvalidValue();
  109. /**
  110. * Returns a machine-digestible error code for the violation.
  111. *
  112. * @return string|null The error code
  113. */
  114. public function getCode();
  115. }