ConstraintViolation.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace Symfony\Component\Validator;
  3. class ConstraintViolation
  4. {
  5. protected $messageTemplate;
  6. protected $messageParameters;
  7. protected $root;
  8. protected $propertyPath;
  9. protected $invalidValue;
  10. public function __construct($messageTemplate, array $messageParameters, $root, $propertyPath, $invalidValue)
  11. {
  12. $this->messageTemplate = $messageTemplate;
  13. $this->messageParameters = $messageParameters;
  14. $this->root = $root;
  15. $this->propertyPath = $propertyPath;
  16. $this->invalidValue = $invalidValue;
  17. }
  18. public function getMessageTemplate()
  19. {
  20. return $this->messageTemplate;
  21. }
  22. public function getMessageParameters()
  23. {
  24. return $this->messageParameters;
  25. }
  26. public function getMessage()
  27. {
  28. $sources = array();
  29. $targets = array();
  30. foreach ($this->messageParameters as $key => $value) {
  31. $sources[] = '%'.$key.'%';
  32. $targets[] = (string) $value;
  33. }
  34. return str_replace($sources, $targets, $this->messageTemplate);
  35. }
  36. public function getRoot()
  37. {
  38. return $this->root;
  39. }
  40. public function getPropertyPath()
  41. {
  42. return $this->propertyPath;
  43. }
  44. public function getInvalidValue()
  45. {
  46. return $this->invalidValue;
  47. }
  48. }