mirror of
http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore.git
synced 2026-01-15 03:45:06 +08:00
26 lines
923 B
Markdown
26 lines
923 B
Markdown
|
|
# Http 请求
|
||
|
|
|
||
|
|
## 1 组成
|
||
|
|
|
||
|
|
* 单例类
|
||
|
|
* \Singularity\HDK\Core\Http\RequestService
|
||
|
|
* 工厂类
|
||
|
|
* \Singularity\HDK\Core\Http\RequestServiceFactory
|
||
|
|
|
||
|
|
## 2 初始化服务
|
||
|
|
|
||
|
|
创建一个请求服务的方法有两种,效果是一致的:
|
||
|
|
|
||
|
|
* 工厂模式
|
||
|
|
* `\Singularity\HDK\Core\Http\RequestServiceFactory::make($options)`
|
||
|
|
* `\Singularity\HDK\Core\Http\RequestServiceFactory::make()->setOptions($options)`
|
||
|
|
* 单例模式
|
||
|
|
* `new \Singularity\HDK\Core\Http\RequestService($options)`
|
||
|
|
* `(new \Singularity\HDK\Core\Http\RequestService())->setOptions($options)`
|
||
|
|
|
||
|
|
这两个方法都回返回一个 `\Singularity\HDK\Core\Http\RequestService` 实例
|
||
|
|
|
||
|
|
## 3 规范
|
||
|
|
|
||
|
|
每个通过本包提供的 Http 请求服务创建的服务,都应该在构建方法中实例化一个 RequestService 服务,
|
||
|
|
之后该服务中使用的所有请求都基于该服务,这样可以避免共用单例模式导致的 options 污染
|