php-extended/php-insee-ban-bulk-api

This package is abandoned and no longer maintained. The author suggests using the php-extended/php-api-fr-insee-ban-object package instead.

A php API wrapper to the Base d'Adresse Nationale (BAN) source to make the data available as php objects

This package is auto-updated.

Last update: 2020-12-02 20:17:20 UTC


README

A php API wrapper to the Base d'Adresse Nationale (BAN) source to make the data available as php objects. The source data is available to the url https://adresse.data.gouv.fr/data/ban/export-api-gestion/.

coverage build status

Installation

The installation of this library is made via composer. Download composer.phar from their website. Then add to your composer.json :

	"require": {
		...
		"php-extended/php-insee-ban-bulk-api": "^3"
		...
	}

Then run php composer.phar update to install this library. The autoloading of all classes of this library is made through composer's autoloader.

Basic Usage


use PhpExtended\Insee\InseeBanBulkEndpoint;

/* @var $client         \Psr\Http\Client\ClientInterface */
/* @var $uriFactory     \Psr\Http\Message\UriFactoryInterface */
/* @var $requestFactory \Psr\Http\Message\RequestFactoryInterface */
/* @var $tempPath       string */

$endpoint = new InseeBanBulkEndpoint($client, $uriFactory, $requestFactory, $tempPath);

// first, get the latest date
$latest = $endpoint->getLatestDate();
// second, get the departements for this date
$departements = $endpoint->getDepartementIds($latest);
// third, get the data
foreach($departements as $departementId)
{
	foreach($endpoint->getBanLinesIterator($latest, $departementId) as $inseeBanLine)
	{
		// $inseeBanLine instanceof \PhpExtended\Insee\InseeBanBulkLine
	}
	
	// do not forget to remove the downloaded file afterwise,
	// (the whole database files is worth 10-12Gb)
	$endpoint->cleanupTempBanLinesFile($latest, $departementId);
	// if the $tempPath is a directory specific for this task
	// it may be easy to cleanup it otherwise
}

License