LocaleResolver.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Braintree\Model;
  7. use Magento\Framework\Locale\ResolverInterface;
  8. use Magento\Braintree\Gateway\Config\PayPal\Config;
  9. class LocaleResolver implements ResolverInterface
  10. {
  11. /**
  12. * @var ResolverInterface
  13. */
  14. private $resolver;
  15. /**
  16. * @var Config
  17. */
  18. private $config;
  19. /**
  20. * @param ResolverInterface $resolver
  21. * @param Config $config
  22. */
  23. public function __construct(ResolverInterface $resolver, Config $config)
  24. {
  25. $this->resolver = $resolver;
  26. $this->config = $config;
  27. }
  28. /**
  29. * @inheritdoc
  30. */
  31. public function getDefaultLocalePath()
  32. {
  33. return $this->resolver->getDefaultLocalePath();
  34. }
  35. /**
  36. * @inheritdoc
  37. */
  38. public function setDefaultLocale($locale)
  39. {
  40. return $this->resolver->setDefaultLocale($locale);
  41. }
  42. /**
  43. * @inheritdoc
  44. */
  45. public function getDefaultLocale()
  46. {
  47. return $this->resolver->getDefaultLocale();
  48. }
  49. /**
  50. * @inheritdoc
  51. */
  52. public function setLocale($locale = null)
  53. {
  54. return $this->resolver->setLocale($locale);
  55. }
  56. /**
  57. * Gets store's locale or the `en_US` locale if store's locale does not supported by PayPal.
  58. *
  59. * @return string
  60. */
  61. public function getLocale()
  62. {
  63. $locale = $this->resolver->getLocale();
  64. $allowedLocales = $this->config->getValue('supported_locales');
  65. return strpos($allowedLocales, $locale) !== false ? $locale : 'en_US';
  66. }
  67. /**
  68. * @inheritdoc
  69. */
  70. public function emulate($scopeId)
  71. {
  72. return $this->resolver->emulate($scopeId);
  73. }
  74. /**
  75. * @inheritdoc
  76. */
  77. public function revert()
  78. {
  79. return $this->resolver->revert();
  80. }
  81. }