Locale.php 911 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. * Locale validator model
  10. */
  11. class Locale
  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 locale code. Code must be in the list of allowed locales.
  28. *
  29. * @param string $localeCode
  30. * @return bool
  31. *
  32. * @api
  33. */
  34. public function isValid($localeCode)
  35. {
  36. $isValid = true;
  37. $allowedLocaleCodes = array_keys($this->lists->getLocaleList());
  38. if (!$localeCode || !in_array($localeCode, $allowedLocaleCodes)) {
  39. $isValid = false;
  40. }
  41. return $isValid;
  42. }
  43. }