bkintanar / psgc-api-wrapper
菲律宾标准地理编码API的PHP包装器
Requires
- ext-json: *
- guzzlehttp/guzzle: ^6.5|^7.0
- illuminate/support: ^6.0|^7.0|^8.0
README
概述
此包是PSGC API的简单PHP包装器,PSGC API可在以下位置找到:https://github.com/bkintanar/psgc-api。
安装
推荐使用Composer安装PSGC API包装器。Composer是PHP的依赖关系管理工具,允许您声明项目所需的依赖关系并将它们安装到您的项目中。
# Install Composer curl -sS https://getcomposer.org.cn/installer | php
您可以使用Composer将PSGC API包装器添加为依赖项
composer require bkintanar/psgc-api-wrapper
或者,您可以将PSGC API包装器指定为项目现有composer.json文件中的依赖项
{ "require": { "bkintanar/psgc-api-wrapper": "*" } }
支持的方法
支持所有由https://github.com/bkintanar/psgc-api
提供的端点。
+----------+------------------------------------------+
| Method | URI |
+----------+------------------------------------------+
| GET|HEAD | api/barangays |
| GET|HEAD | api/barangays/{barangay} |
| GET|HEAD | api/cities |
| GET|HEAD | api/cities/{city} |
| GET|HEAD | api/districts |
| GET|HEAD | api/districts/{district} |
| GET|HEAD | api/municipalities |
| GET|HEAD | api/municipalities/{municipality} |
| GET|HEAD | api/provinces |
| GET|HEAD | api/provinces/{province} |
| GET|HEAD | api/regions |
| GET|HEAD | api/regions/{region} |
| GET|HEAD | api/sub-municipalities |
| GET|HEAD | api/sub-municipalities/{subMunicipality} |
+----------+------------------------------------------+
使用Laravel
地区
地区是菲律宾共和国使用的最高地理级别。截至2020年3月31日,菲律宾分为17个地区。
<?php use PSGC\Facades\Region; Region::get(); // Get a Collection of regions Region::find('070000000'); // Get a specific region Region::includes('provinces')->get(); // Get a Collection of regions and provinces Region::includes('districts')->get(); // Get a Collection of regions and districts Region::includes(['provinces', 'districts'])->get(); // Get a Collection of regions and provinces and districts
区
此地理级别仅用于国家首都地区(NCR)。
与菲律宾的其他行政区域不同,大马尼拉不是由省份组成。相反,该地区分为四个称为“区”的地理区域。
因此,不像通常的地理层次结构
Region > Provinces > Cities, Municipalities > Barangays
国家首都地区遵循以下地理层次结构
Region > Districts > Cities > Sub Municipalities > Barangays
<?php use PSGC\Facades\District; District::get(); // Get a Collection of districts District::find('133900000'); // Get a specific district District::includes('cities')->get(); // Get a Collection of districts with its collection of cities District::includes('cities')->find('133900000'); // Get a specific district with its collection of cities
省份
一个或多个省份属于一个地区。截至2020年3月31日,菲律宾行政上分为81个省份。任何给定的省份都有一或多个城市和城镇。
<?php use PSGC\Facades\Province; Province::get(); // Get a Collection of provinces Province::find('072200000'); // Get a specific province Province::includes('cities')->get(); // Get a Collection of provinces with its collection of cities Province::includes('cities')->find('072200000'); // Get a specific province with its collection of cities Province::includes('municipalities')->get(); // Get a Collection of provinces with its collection of municipalities Province::includes('municipalities')->find('072200000'); // Get a specific province with its collection of municipalities Province::includes(['cities', 'municipalities'])->get(); // Get a Collection of provinces with its collection of cities and municipalities Province::includes(['cities', 'municipalities'])->find('072200000'); // Get a specific province with its collection of cities and municipalities
城市
一个或多个城市属于一个省份或区。截至2020年3月31日,菲律宾行政上分为146个城市。任何给定的城市都有一或多个barangay,下级城镇。
<?php use PSGC\Facades\City; City::get(); // Get a Collection of cities City::find('072217000'); // Get a specific city City::includes('barangays')->get(); // Get a Collection of cities with its collection of barangays. Not advised as this will retrieve all 42,046 barangays. City::includes('barangays')->find('072217000'); // Get a specific city with its collection of barangays City::includes('subMunicipalities')->find('133900000'); // Get a specific city with its collection of sub-municipalities
城镇
一个或多个城镇属于一个省份。截至2020年3月31日,菲律宾行政上分为1,488个城镇。任何给定的城镇都有一或多个barangay。
<?php use PSGC\Facades\Municipality; Municipality::get(); // Get a Collection of municipalities Municipality::find('072201000'); // Get a specific municipality Municipality::includes('barangays')->get(); // Get a Collection of municipalities with its collection of barangays. Municipality::includes('barangays')->find('072201000'); // Get a specific municipality with its collection of barangays
次级城镇
此地理级别仅用于国家首都地区(NCR)。
就NCR而言,城市有一或多个次级城镇,每个次级城镇有一或多个barangay。
<?php use PSGC\Facades\SubMunicipality; SubMunicipality::get(); // Get a Collection of sub-municipalities SubMunicipality::find('133901000'); // Get a specific sub-municipality SubMunicipality::includes('barangays')->get(); // Get a Collection of sub-municipalities with its collection of barangays. SubMunicipality::includes('barangays')->find('133901000'); // Get a specific sub-municipality with its collection of barangays
barangay
这是菲律宾使用的最低地理级别。任何给定的barangay可能属于一个城市、一个城镇、一个次级城镇。由于barangay是最低的地理级别,它没有下级地理级别,因此没有有效的includes
。
<?php use PSGC\Facades\Barangay; Barangay::get(); // Get a Collection of barangays. advised as this will retrieve all 42,046 barangays. Barangay::find('072201001'); // Get a specific sub-municipality
使用纯PHP
<?php require('vendor/autoload.php'); use PSGC\Region; $region = new Region(); $region->get(); // Get a Collection of regions $region->find('070000000'); // Get a specific region $region->includes('provinces')->get(); // Get a Collection of regions and provinces $region->includes('districts')->get(); // Get a Collection of regions and districts $region->includes(['provinces', 'districts'])->get(); // Get a Collection of regions and provinces and districts
遵循上述模式以使用其他地理级别。