php-extended / php-api-fr-insee-ban-object
实现 php-extended/php-api-fr-insee-ban-interface 库的库
7.0.5
2024-07-31 14:41 UTC
Requires
Requires (Dev)
- dev-master
- 7.0.5
- 7.0.4
- 7.0.3
- 7.0.2
- 7.0.1
- 7.0.0
- 6.2.3
- 6.2.2
- 6.2.1
- 6.2.0
- 6.1.9
- 6.1.8
- 6.1.7
- 6.1.6
- 6.1.5
- 6.1.4
- 6.1.3
- 6.1.2
- 6.1.1
- 6.1.0
- 6.0.0
- 5.0.2
- 5.0.1
- 5.0.0
- 4.0.5
- 4.0.4
- 4.0.3
- 4.0.2
- 4.0.1
- 4.0.0
- 3.4.7
- 3.4.6
- 3.4.5
- 3.4.4
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.0
- 3.2.0
- 3.1.8
- 3.1.7
- 3.1.6
- 3.1.5
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.13
- 3.0.12
- 3.0.11
- 3.0.10
- 3.0.9
- 3.0.8
- 3.0.7
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
This package is auto-updated.
Last update: 2024-08-31 12:48:03 UTC
README
实现 php-extended/php-api-fr-insee-ban-interface 库的库。
该库使ApiFrInsee、Dgfip、OpenStreetMap贡献者、La Poste和Etalab的协作工作成果(称为BAN)作为对象可用于填充数据库。BAN可在以下URL获取:https://adresse.data.gouv.fr/。
安装
此库的安装通过composer进行,并通过其自动加载器自动加载该库的所有类。
- 从他们的网站下载
composer.phar
。 - 然后运行以下命令将此库作为依赖项安装
php composer.phar require php-extended/php-api-fr-insee-ban-object ^7
基本用法
此库提供了一个唯一的端点:\PhpExtended\Insee\InseeCogEndpoint
,可以通过它检索所有数据。
- 对于大多数用法,您可以使用以下代码
use PhpExtended\Insee\InseeBanEndpoint;
use PhpExtended\Endpoint\GzipHttpEndpoint;
use PhpExtended\Endpoint\HttpEndpoint;
/** $client \Psr\Http\Client\ClientInterface */
$endpoint = new ApiFrInseeBanEndpoint(new GzipHttpEndpoint(new HttpEndpoint($client)));
$lastDateTime = $endpoint->getLatestDate();
$departements = $endpoint->getDepartementIds($lastDateTime);
foreach($departements as $departement)
{
$banLineIterator = $endpoint->getBanLinesIterator($lastDateTime, $departement);
foreach($banLineIterator as $banLine)
{
/** @var $banLine \PhpExtended\Insee\InseeBanLine */
// do something with the ban line representing :
// - a commune with CodeInsee and NomCommune
// - a group (street) with Id, NomVoie and NomComplementaire
// - an address with Id, Numero, Suffixe, CodePostal
// - a position with Id, X, Y, Lat, Lon
// - and generic data like type of localisation,
// source and date of last update
}
}
请注意,客户端必须遵循一系列关于通过X-Php-Download-File
请求和响应头处理文件的规则,以便能够解压缩下载的文件而无需使用数GB的内存。它还必须返回一个X-Request-Uri
头以获取完整的URI。
对于所需的最小HTTP客户端示例,请查看InseeBanEndpointTest
类文件并找到使用的客户端。
但是,如果您有足够的内存,您可以绕过GzipHttpEndpoint
以及所有X-Php-Download-File
和X-Request-Uri
的把戏。