php-extended / php-insee-ban-bulk-api
该包已被废弃,不再维护。作者建议使用php-extended/php-api-fr-insee-ban-object包。
一个用于将国家地址数据库(BAN)源数据作为PHP对象提供的PHP API包装器
3.2.3
2020-11-22 16:16 UTC
Requires
- php: >=7.1
- ext-zip: *
- php-extended/php-enumerable: ^3
- php-extended/polyfill-php80-stringable: ^1
- psr/http-client: ^1
- psr/http-factory: ^1
- psr/log: ^1
Requires (Dev)
README
一个用于将国家地址数据库(BAN)源数据作为PHP对象提供的PHP API包装器。源数据可在以下URL获取:https://adresse.data.gouv.fr/data/ban/export-api-gestion/。
安装
此库的安装通过composer进行。从其网站下载composer.phar
。然后在您的composer.json中添加
"require": {
...
"php-extended/php-insee-ban-bulk-api": "^3"
...
}
然后运行php composer.phar update
以安装此库。此库中所有类的自动加载是通过composer的自动加载器实现的。
基本用法
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
}