uzdevid/conflux-http
最新稳定版本:1.2.0
Composer 安装命令:
composer require uzdevid/conflux-http
包简介
Conflux HTTP — This is a flexible architecture for integration with external HTTP services, built on the basis of the PSR-18 and Guzzle. Each request is made out as a separate class that implements the necessary interfaces, providing readability, testability and expansion.
关键字:
README 文档
README
Conflux HTTP
Conflux HTTP — This is a flexible architecture for integration with external HTTP services, built on the basis of the PSR-18 and Guzzle. Each request is made out as a separate class that implements the necessary interfaces, providing readability, testability and expansion.
Requirements
- PHP 8.3 or higher.
Installation
The package could be installed with Composer:
composer require uzdevid/conflux-http
Quick start
1. Configuration
class GithubConfig implements UzDevid\Conflux\Http\ConfigInterface { public function getClient(): ClientInterface { return new GuzzleHttp\Client; } public function getBaseUri(): string { return 'https://api.github.com'; } public function getDefaultHeaders(): array { return ['Accept' => 'application/json']; } }
2. Create request class
use UzDevid\Conflux\Http\Request\RequestInterface; use UzDevid\Conflux\Http\Request\RequestQueryInterface; use UzDevid\Conflux\Http\Request\RequestBodyInterface; use UzDevid\Conflux\Http\Request\ConvertableBodyInterface; use UzDevid\Conflux\Http\Request\Method; use UzDevid\Conflux\Http\Parser\JsonParser; class GetUser implements RequestInterface, RequestQueryInterface, ConvertableBodyInterface { use JsonParser; public function getMethod(): Method { return Method::GET; } public function getUrl(): string { return '/users/{id}'; } public function getQueryParams(): array { return []; } public function getQueryPath(): array { return ['{id}' => 123]; } public function convert(array $response): UserDto { return new UserDto($response); } }
3. Send request
use UzDevid\Conflux\Http\ConfluxHttp; use \Yiisoft\EventDispatcher\Dispatcher\Dispatcher; $config = new GithubConfig(); $conflux = new ConfluxHttp($config, new RequestHandler(), new Dispatcher(); $response = $conflux->withRequest(new GetUser())->send(); // UserDto
Implemented request interfaces
RequestInterface
Mandatory interface, sets the method, path and parser answer:
interface RequestInterface { public function getMethod(): Method|string; public function getUrl(): string; public function parse(string $content): array; }
You can use trait
Uzdevid\Conflux\Http\Parser\JsonParserto pars the answers in JSON format
RequestQueryInterface
If you need to send the query parameters or specify them to the URL:
interface RequestQueryInterface { public function getQueryParams(): array; public function getQueryPath(): array; }
RequestBodyInterface
If you need send body (POST, PUT etc.):
interface RequestBodyInterface { public function getOption(): Option; // Например, 'json', 'form_params' public function getBody(): array|string; }
RequestHeadersInterface
Custom headers:
interface RequestHeadersInterface { public function getHeaders(): array; }
ConvertableBodyInterface
If after parsing the body needs to be converted into an object:
interface ConvertableBodyInterface { public function convert(array $response): mixed; }
Example with POST request and body:
class CreateUser implements RequestInterface, RequestBodyInterface { use JsonParser; public function getMethod(): Method { return Method::POST; } public function getUrl(): string { return '/users'; } public function getOption(): Option|string { return 'json'; } public function getBody(): array|string { return ['name' => 'John', 'email' => 'john@example.com']; } }
URL replacement
If the getUrl() contains the placeholders {}, they will be automatically replaced by values from getQueryPath().
getUrl(): '/users/{id}'
getQueryPath(): ['{id}' => 5]
Result: GET /users/5
Handle events
You can subscribe to the events of BeforeRequest, AfterRequest and OnThrow using the EventDispatcherInterface from the package yiisoft/event-dispatcher
If you have suggestions or features, open it issue or write Pull Request ✨
uzdevid/conflux-http 适用场景与选型建议
uzdevid/conflux-http 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 39 次下载、GitHub Stars 达 3, 最近一次更新时间为 2025 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「http client」 「http api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 uzdevid/conflux-http 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 uzdevid/conflux-http 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 uzdevid/conflux-http 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
http客户端
Easily add Excepct-CT header to your project
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
统计信息
- 总下载量: 39
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-07