Currency.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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\Constraints;
  11. use Symfony\Component\Intl\Currencies;
  12. use Symfony\Component\Validator\Constraint;
  13. use Symfony\Component\Validator\Exception\LogicException;
  14. /**
  15. * @Annotation
  16. * @Target({"PROPERTY", "METHOD", "ANNOTATION"})
  17. *
  18. * @author Miha Vrhovnik <miha.vrhovnik@pagein.si>
  19. * @author Bernhard Schussek <bschussek@gmail.com>
  20. */
  21. #[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
  22. class Currency extends Constraint
  23. {
  24. public const NO_SUCH_CURRENCY_ERROR = '69945ac1-2db4-405f-bec7-d2772f73df52';
  25. protected static $errorNames = [
  26. self::NO_SUCH_CURRENCY_ERROR => 'NO_SUCH_CURRENCY_ERROR',
  27. ];
  28. public $message = 'This value is not a valid currency.';
  29. public function __construct(array $options = null, string $message = null, array $groups = null, $payload = null)
  30. {
  31. if (!class_exists(Currencies::class)) {
  32. throw new LogicException('The Intl component is required to use the Currency constraint. Try running "composer require symfony/intl".');
  33. }
  34. parent::__construct($options, $groups, $payload);
  35. $this->message = $message ?? $this->message;
  36. }
  37. }