ConstraintViolation.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Symfony\Component\Validator;
  3. /*
  4. * This file is part of the Symfony framework.
  5. *
  6. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. /**
  12. * Represents a single violation of a constraint.
  13. */
  14. class ConstraintViolation
  15. {
  16. protected $messageTemplate;
  17. protected $messageParameters;
  18. protected $root;
  19. protected $propertyPath;
  20. protected $invalidValue;
  21. public function __construct($messageTemplate, array $messageParameters, $root, $propertyPath, $invalidValue)
  22. {
  23. $this->messageTemplate = $messageTemplate;
  24. $this->messageParameters = $messageParameters;
  25. $this->root = $root;
  26. $this->propertyPath = $propertyPath;
  27. $this->invalidValue = $invalidValue;
  28. }
  29. /**
  30. * @return string
  31. */
  32. public function getMessageTemplate()
  33. {
  34. return $this->messageTemplate;
  35. }
  36. /**
  37. * @return array
  38. */
  39. public function getMessageParameters()
  40. {
  41. return $this->messageParameters;
  42. }
  43. /**
  44. * Returns the violation message.
  45. *
  46. * @return string
  47. */
  48. public function getMessage()
  49. {
  50. return str_replace(array_keys($this->messageParameters), array_values($this->messageParameters), $this->messageTemplate);
  51. }
  52. public function getRoot()
  53. {
  54. return $this->root;
  55. }
  56. public function getPropertyPath()
  57. {
  58. return $this->propertyPath;
  59. }
  60. public function getInvalidValue()
  61. {
  62. return $this->invalidValue;
  63. }
  64. }