|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Shopsys\FrontendApiBundle\Model\Resolver\Settings; |
| 6 | + |
| 7 | +use Shopsys\FrameworkBundle\Component\Country\CountryFlag; |
| 8 | +use Shopsys\FrameworkBundle\Component\Domain\Domain; |
| 9 | +use Shopsys\FrameworkBundle\Model\PhonePrefix\CountryDialCode; |
| 10 | +use Shopsys\FrameworkBundle\Model\PhonePrefix\CountryDialCodeProvider; |
| 11 | +use Shopsys\FrontendApiBundle\Model\Resolver\AbstractQuery; |
| 12 | +use Symfony\Component\Intl\Countries; |
| 13 | + |
| 14 | +class PhonePrefixesQuery extends AbstractQuery |
| 15 | +{ |
| 16 | + public function __construct( |
| 17 | + protected readonly Domain $domain, |
| 18 | + protected readonly CountryDialCodeProvider $countryDialCodeProvider, |
| 19 | + ) { |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * @return array<int, array{code: string, dialCode: string, countryName: string, flagEmoji: string}> |
| 24 | + */ |
| 25 | + public function phonePrefixesQuery(): array |
| 26 | + { |
| 27 | + $locale = $this->domain->getLocale(); |
| 28 | + |
| 29 | + $countryDialCodes = $this->countryDialCodeProvider->getAllEnabledOnDomainWithDefaultFirst($this->domain->getId()); |
| 30 | + |
| 31 | + return array_map( |
| 32 | + static fn (CountryDialCode $countryDialCode): array => [ |
| 33 | + 'code' => $countryDialCode->code, |
| 34 | + 'dialCode' => $countryDialCode->dialCode, |
| 35 | + 'countryName' => Countries::getName($countryDialCode->code, $locale), |
| 36 | + 'flagEmoji' => CountryFlag::getFlagEmoji($countryDialCode->code), |
| 37 | + ], |
| 38 | + $countryDialCodes, |
| 39 | + ); |
| 40 | + } |
| 41 | +} |
0 commit comments