Country.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Braintree\Helper;
  7. use Magento\Directory\Model\ResourceModel\Country\CollectionFactory;
  8. use Magento\Braintree\Model\Adminhtml\System\Config\Country as CountryConfig;
  9. /**
  10. * Class Country
  11. */
  12. class Country
  13. {
  14. /**
  15. * @var CollectionFactory
  16. */
  17. private $collectionFactory;
  18. /**
  19. * @var CountryConfig
  20. */
  21. private $countryConfig;
  22. /**
  23. * @var array
  24. */
  25. private $countries;
  26. /**
  27. * @param CollectionFactory $factory
  28. * @param CountryConfig $countryConfig
  29. */
  30. public function __construct(CollectionFactory $factory, CountryConfig $countryConfig)
  31. {
  32. $this->collectionFactory = $factory;
  33. $this->countryConfig = $countryConfig;
  34. }
  35. /**
  36. * Returns countries array
  37. *
  38. * @return array
  39. */
  40. public function getCountries()
  41. {
  42. if (!$this->countries) {
  43. $this->countries = $this->collectionFactory->create()
  44. ->addFieldToFilter('country_id', ['nin' => $this->countryConfig->getExcludedCountries()])
  45. ->loadData()
  46. ->toOptionArray(false);
  47. }
  48. return $this->countries;
  49. }
  50. }