. */ declare(strict_types=1); namespace App\Repository; use App\Entity\Base\AbstractStructuralDBElement; use App\Entity\PriceInformations\Currency; use Symfony\Component\Intl\Currencies; /** * @extends StructuralDBElementRepository */ class CurrencyRepository extends StructuralDBElementRepository { /** * Finds or create a currency with the given ISO code. * @param string $iso_code * @return Currency */ public function findOrCreateByISOCode(string $iso_code): Currency { //Normalize ISO code $iso_code = strtoupper($iso_code); //Try to find currency $currency = $this->findOneBy(['iso_code' => $iso_code]); if ($currency !== null) { return $currency; } //Create currency if it does not exist $name = Currencies::getName($iso_code); $currency = $this->findOrCreateForInfoProvider($name); $currency->setIsoCode($iso_code); return $currency; } }