php-extended/php-insee-ban

A library that makes insee Base d'Adresse Nationale (BAN) available as objects to populate a database.


README

A library that makes insee Base d'Adresse Nationale (BAN) available as objects to populate a database. This is a repack of the files of the BAN for it to take less place on disk and to be easier to manipulate.The BAN is available at the url : https://adresse.data.gouv.fr.

Last Updated Date : 2020-03-20

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": "^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

This library gives an unique endpoint : \PhpExtended\Insee\InseeBanRepository from which all data can be retrieved.

You can retrieve the groups, the adresses and the positions for a single departement using the following methods :


// the departement code is one of the code departement that
// are available at the php-extended/php-insee-cog library
// for the departements. It is also available in
// $repository->getDepartementCodes();

$departementCode = '<code>';

$repository = new InseeBanRepository();
$iterator = $repository->getGroupIterator($departementCode);
foreach($iterator as $group)
{
	// $group instanceof \PhpExtended\Insee\InseeBanGroup */
}

$iterator = $repository->getAdresseIterator($departementCode);
foreach($iterator as $adresse)
{
	// $adresse instanceof \PhpExtended\Insee\InseeBanAdresse */
}

$iterator = $repository->getPositionIterator($departementCode);
foreach($iterator as $position)
{
	// $position instanceof \PhpExtended\Insee\InseeBanPosition */
}

You may also use the following methods to get the same date but for all the departements at once :


$repository = new InseeBanRepository();
$iterator = $repository->getGroupDepartementIterator();
foreach($iterator as $group)
{
	// $group instanceof \PhpExtended\Insee\InseeBanGroup */
}

$iterator = $repository->getAdresseDepartementIterator();
foreach($iterator as $adresse)
{
	// $adresse instanceof \PhpExtended\Insee\InseeBanAdresse */
}

$iterator = $repository->getPositionDepartementIterator();
foreach($iterator as $position)
{
	// $position instanceof \PhpExtended\Insee\InseeBanPosition */
}

License