bootiq / service-layer
B!Q 公共服务层
01.02.00
2021-03-21 01:45 UTC
Requires
- php: ^7.0 || ^8.0
- ext-hash: >=1
- ext-json: >=1.3.7
- guzzlehttp/guzzle: ~6.0|~7.0
- psr/log: ~1.0
- psr/simple-cache: ^1.0
Requires (Dev)
- php-parallel-lint/php-console-color: ^0.2.0
- php-parallel-lint/php-console-highlighter: ^0.4.0
- php-parallel-lint/php-parallel-lint: ^1.2
- phpmd/phpmd: ^2.8
- phpstan/phpstan: ^0.8.5
- phpunit/phpunit: ^6.3
- sebastian/phpcpd: ^3.0
- slevomat/coding-standard: ^4.0
- squizlabs/php_codesniffer: ^3.1
This package is not auto-updated.
Last update: 2024-09-25 18:56:44 UTC
README
服务层供应商,用于SOA通信(REST/SOAP)。
安装
要安装Boot!Q服务层,请使用composer
composer require bootiq/service-layer
适配器
BootIq\ServiceLayer\Adapter\GuzzleAdapter
默认适配器是GuzzleAdapter,主要用于REST通信。
配置
- 依赖项
- client - GuzzleHttp\ClientInterface - 调用请求的客户端。
- responseFactory - BootIq\ServiceLayer\Response\ResponseFactoryInterface - 创建特定响应的响应工厂。
- urn - API的URN(例如:https://api.bootiq.io)。
- timeout - 由setTimeout方法提供的请求超时(默认:10秒)。
- cache - 如果您想缓存响应,请提供您的缓存服务(PSR-16)。
- logger - 如果您想在适配器中记录发生的情况,请提供您的日志服务(PSR-3)。
自定义适配器
要创建自己的适配器,您必须实现BootIq\ServiceLayer\Adapter\AdapterInterface。
枚举
库提供枚举
- BootIq\ServiceLayer\Enum\HttpCode - 根据http://www.restapitutorial.com/httpstatuscodes.html列出所有HTTP状态码。
- BootIq\ServiceLayer\Enum\HttpMethod - 根据http://www.restapitutorial.com/lessons/httpmethods.html列出所有可用的HTTP方法。
异常
我们提供用于与我们的服务层一起工作的基本异常(BootIq\ServiceLayer\Exception\ServiceLayerException)。
请求
每个可以由适配器调用的请求必须实现BootIq\ServiceLayer\Request\RequestInterface。
在BootIq\ServiceLayer\Request命名空间中有各种HTTP方法的抽象类,以便与我们的服务层更简单地集成。
例如
<?php namespace BootIq\CmsApiVendor\Request\Page; use BootIq\ServiceLayer\Request\GetMethod; class GetPageRequest extends GetMethod { /** * @var int */ private $pageId; /** * GetPageRequest constructor. * @param int $pageId */ public function __construct(int $pageId) { $this->pageId = $pageId; } /** * @return string */ public function getEndpoint(): string { return 'page/' . $this->pageId; } }
响应
每个由适配器返回的响应必须实现BootIq\ServiceLayer\Response\ResponseInterface。
我们提供默认响应对象BootIq\ServiceLayer\Response\Response和默认响应工厂BootIq\ServiceLayer\Response\ResponseFactory,以实现快速实现。