answear / overseas-bundle
海外API的Symfony包。
2.3.0
2024-09-03 08:55 UTC
Requires
- php: >=7.4|^8.0
- ext-json: *
- guzzlehttp/guzzle: ^6.0 || ^7.0
- marc-mabe/php-enum: ^3.0|^4.3
- psr/log: ^1.0
- symfony/http-kernel: 5.4 - 6.4
- symfony/property-access: 5.4 - 6.4
- symfony/property-info: 5.4 - 6.4
- symfony/serializer: 5.4 - 6.4
- webmozart/assert: ^1.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.4
- matthiasnoback/symfony-config-test: ^4.2
- phpro/grumphp: ^1.5.0
- phpstan/phpstan: ^1.4
- phpstan/phpstan-webmozart-assert: ^1.0
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-master
- symfony/phpunit-bridge: 6.4.*
README
Symfony的海外集成。
API文档可在此处找到: https://api.overseas.hr/apiinfo
安装
- 使用Composer安装
composer require git@github.com:answear/overseas-bundle.git
Answear\OverseasBundle\AnswearOverseasBundle::class => ['all' => true],
应该由Symfony Flex自动添加到您的 config/bundles.php
文件中。
配置
- 提供所需的配置数据:
环境
和apiKey
# config/packages/answear_overseas.yaml answear_overseas: environment: test|prod apiKey: yourApiKey logger: yourCustomLoggerService #default: null
Logger服务必须实现 Psr\Log\LoggerInterface
接口。
使用
获取包裹店
@see https://api.overseas.hr/apiinfo#parcelshops
/** @var \Answear\OverseasBundle\Service\ParcelShopsService $parcelShopService **/ $parcelShopService->get();
将返回 \Answear\OverseasBundle\Response\DTO\ParcelShop[]
数组。
获取地点
@see https://api.overseas.hr/apiinfo#places
$zipCode = 12345; $name = 'name'; $approx = true; /** @var \Answear\OverseasBundle\Service\PlacesService $placesService **/ $placesService->get($zipCode, $name, $approx);
将返回 \Answear\OverseasBundle\Response\DTO\Place[]
数组,根据参数缩小范围。或者简单地
$placesService->get();
获取所有地点。
错误处理
Answear\OverseasBundle\Exception\ServiceUnavailableException
用于所有GuzzleException
MalformedResponseException
用于合作伙伴其他错误Answear\OverseasBundle\Exception\BadRequestException
如果验证失败或为错误响应
最后说明
请随意提交具有新功能、改进或错误修复的拉取请求。Answear团队将非常感激任何评论。