client->request('GET', $url); if (200 !== $response->getStatusCode()) { throw new \Exception('Could not download CSV: '.$response->getStatusCode()); } $file = tmpfile(); foreach ($this->client->stream($response) as $chunk) { fwrite($file, $chunk->getContent()); } fseek($file, 0); $csv = Reader::createFromStream($file); $csv->setDelimiter(','); $stmt = Statement::create() ->process($csv, [ 'refId', 'streetNumber', 'street', 'postcode', 'city', '_o', 'lat', 'lon', ]); foreach ($stmt as $record) { $this->baseImporter->importAddress( $record['refId'], substr($record['refId'], 0, 5), // extract insee from reference $record['postcode'], $record['street'], $record['streetNumber'], 'BANO.'.$departementNo, (float) $record['lat'], (float) $record['lon'], 4326 ); } $this->baseImporter->finalize(); $this->addressToReferenceMatcher->checkAddressesMatchingReferences(); fclose($file); } }