Currency.php 878 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Validator;
  7. use Magento\Framework\Setup\Lists;
  8. /**
  9. * Currency validator model
  10. */
  11. class Currency
  12. {
  13. /**
  14. * @var Lists
  15. */
  16. protected $lists;
  17. /**
  18. * Constructor
  19. *
  20. * @param Lists $lists
  21. */
  22. public function __construct(Lists $lists)
  23. {
  24. $this->lists = $lists;
  25. }
  26. /**
  27. * Validate currency code
  28. *
  29. * @param string $currencyCode
  30. * @return bool
  31. * @api
  32. */
  33. public function isValid($currencyCode)
  34. {
  35. $isValid = true;
  36. $allowedCurrencyCodes = array_keys($this->lists->getCurrencyList());
  37. if (!$currencyCode || !in_array($currencyCode, $allowedCurrencyCodes)) {
  38. $isValid = false;
  39. }
  40. return $isValid;
  41. }
  42. }