* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ namespace PrestaShop\PrestaShop\Core\Form\ChoiceProvider; use PrestaShop\PrestaShop\Adapter\Country\CountryDataProvider; use PrestaShop\PrestaShop\Core\Form\FormChoiceProviderInterface; /** * Class CountryChoiceProvider is responsible for providing both enabled/disabled country choices with ISO code values. */ final class CountryByIsoCodeChoiceProvider implements FormChoiceProviderInterface { /** * @var CountryDataProvider */ private $countryDataProvider; /** * @var int */ private $langId; /** * @param int $langId * @param CountryDataProvider $countryDataProvider */ public function __construct( $langId, CountryDataProvider $countryDataProvider ) { $this->countryDataProvider = $countryDataProvider; $this->langId = $langId; } /** * Get country choices. * * @return array */ public function getChoices() { $choices = []; $countries = $this->countryDataProvider->getCountries($this->langId); foreach ($countries as $country) { $choices[$country['name']] = $country['iso_code']; } return $choices; } }