yurcrm / geo-client
地理服务API客户端
v1.1.1
2020-01-03 08:47 UTC
Requires
- php: ^7.2
- ext-curl: *
- ext-json: *
- guzzlehttp/guzzle: ~6.0
Requires (Dev)
- phpunit/phpunit: ^8
This package is auto-updated.
Last update: 2024-09-19 22:27:10 UTC
README
用于与地理微服务交互的类集合。
要求
PHP 7.2+ 扩展:curl, json
安装
composer require yurcrm/geo-client
使用
通过id获取城市信息
$geoClient = new GeoClient(URL_сервиса); $town = $geoClient->getTownById(id_города, params);
结果将是一个GeoServiceClient\models\Town类的对象,如果城市未找到,则抛出GeoServiceClient\exceptions\NotFoundException异常
通过id获取区域信息
$geoClient = new GeoClient(URL_сервиса); $region = $geoClient->getRegionById(id_региона, params);
- params - 请求的额外参数(见下文)
结果将是一个GeoServiceClient\models\Region类的对象,如果区域未找到,则抛出GeoServiceClient\exceptions\NotFoundException异常
获取指定城市附近的城市信息
$geoClient = new GeoClient(URL_сервиса); // $townId - id города, для которого хотим получить соседей $region = $geoClient->getClosestTowns($townId, $radius = 100, $limit = 10);
结果将是一个GeoServiceClient\models\Town类的对象数组
通过id列表获取城市信息
$geoClient = new GeoClient(URL_сервиса); $region = $geoClient->getTownsByIds([1,2,56,777], params);
结果将是一个GeoServiceClient\models\Town类的对象数组
通过搜索条件获取城市信息
$geoClient = new GeoClient(URL_сервиса); $region = $geoClient->getTowns(limit, regionId, countryId, search, params);
所有参数都是可选的
- limit - 选择限制(默认10)
- regionId - 区域id
- countryId - 国家id(默认2 - 俄罗斯)
- search - 按城市名称搜索的字符串
- params - 请求的额外参数(见下文)
结果将是一个GeoServiceClient\models\Town类的对象数组
通过搜索条件获取区域信息
$geoClient = new GeoClient(URL_сервиса); $region = $geoClient->getTowns(limit, countryId, params);
所有参数都是可选的
- limit - 选择限制(默认10)
- countryId - 国家id(默认2 - 俄罗斯)
- params - 请求的额外参数(见下文)
结果将是一个GeoServiceClient\models\Region类的对象数组
获取相关实体
在选择城市和区域时,可以选择同时选择相关实体(区域、国家以及相应的国家)。对于城市,设置参数 $params ['with' => 'region,country'];对于区域,设置参数 ['with' => 'country']。
运行测试
简单运行
vendor/bin/phpunit tests
带有覆盖率分析运行(需要Xdebug)
vendor/bin/phpunit tests --coverage-html tests/output/coverage