loadPostalCodeCSV($manager, self::$postalCodeBelgium, 'BE'); $this->loadPostalCodeCSV($manager, self::$postalCodeFrance, 'FR'); } private function loadPostalCodeCSV(ObjectManager $manager, string $csv, string $countryCode) { $lines = str_getcsv($csv, "\n"); $country = $manager->getRepository(Country::class) ->findOneBy(['countryCode' => $countryCode]); foreach ($lines as $line) { $code = str_getcsv($line); $c = new PostalCode(); $c->setCountry($country) ->setCode($code[0]) ->setName(ucwords(strtolower($code[1]))); if (null !== $code[3]) { $c->setRefPostalCodeId($code[3]); } if (null !== $code[4] & null !== $code[5]) { $c->setCenter(Point::fromLonLat((float) $code[5], (float) $code[4])); } if (null !== $code[6]) { $c->setPostalCodeSource($code[6]); } $manager->persist($c); $ref = 'postal_code_' . $code[0]; if (!$this->hasReference($ref)) { $this->addReference($ref, $c); self::$refs[] = $ref; } } $manager->flush(); } }