TransformationFailedException.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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\Form\Exception;
  11. /**
  12. * Indicates a value transformation error.
  13. *
  14. * @author Bernhard Schussek <bschussek@gmail.com>
  15. */
  16. class TransformationFailedException extends RuntimeException
  17. {
  18. private $invalidMessage;
  19. private $invalidMessageParameters;
  20. public function __construct(string $message = '', int $code = 0, \Throwable $previous = null, string $invalidMessage = null, array $invalidMessageParameters = [])
  21. {
  22. parent::__construct($message, $code, $previous);
  23. $this->setInvalidMessage($invalidMessage, $invalidMessageParameters);
  24. }
  25. /**
  26. * Sets the message that will be shown to the user.
  27. *
  28. * @param string|null $invalidMessage The message or message key
  29. * @param array $invalidMessageParameters Data to be passed into the translator
  30. */
  31. public function setInvalidMessage(string $invalidMessage = null, array $invalidMessageParameters = []): void
  32. {
  33. $this->invalidMessage = $invalidMessage;
  34. $this->invalidMessageParameters = $invalidMessageParameters;
  35. }
  36. public function getInvalidMessage(): ?string
  37. {
  38. return $this->invalidMessage;
  39. }
  40. public function getInvalidMessageParameters(): array
  41. {
  42. return $this->invalidMessageParameters;
  43. }
  44. }