phprise/http 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

phprise/http

最新稳定版本:v2.0.0

Composer 安装命令:

composer require phprise/http

包简介

The HTTP Client component applying the OTAKU philosophy and following the PSR-12, PSR-7, PSR-15, PSR-18 e PSR-14.

README 文档

README

The Assembly Repository is a meta-package that orchestration the union of Atoms. It does not contain logic itself.

Installation

Install the package via composer:

composer require phprise/http

Usage

Quick Start (Native Implementation)

PHPRise HTTP comes with a NativeClient based on PHP's cURL extension, allowing you to send requests without external weight (like Guzzle).

Synchronous Requests

use Phprise\Http\Connector\Connector;
use Phprise\Http\Client\NativeClient;
use Phprise\Http\Request\ListRequest;
use Phprise\Http\ValueObject\Uri;

$connector = new Connector(new NativeClient());

$request = new ListRequest(new Uri('https://jsonplaceholder.typicode.com/posts'));
$response = $connector->send($request);

echo $response->getStatusCode(); // 200

Asynchronous Requests

use Phprise\Http\Connector\AsyncConnector;
use Phprise\Http\Client\NativeClient;

$async = new AsyncConnector(new NativeClient());
$promise = $async->send($request);

$promise->then(function ($response) {
    echo $response->getStatusCode();
});

$promise->wait();

Advanced Usage

1. The Connector

The Connector wraps any PSR-18 Client.

use Phprise\Http\Connector\Connector;

$connector = new Connector($anyPsr18Client);

2. Semantic Requests

Requests are semantic-first and implement Psr\Http\Message\RequestInterface directly.

Request Type Method Purpose
ListRequest GET List resources with query params.
ShowRequest GET Fetch a single resource.
StoreRequest POST Create a new resource with a DTO.
UpdateRequest PATCH Partial update with a DTO.
ReplaceRequest PUT Complete replacement with a DTO.
DestroyRequest DELETE Remove a resource.

3. Data Transfer Objects (DTO)

Stateful requests (Store, Update, Replace) require a payload implementing Phprise\DataTransferObject\TransferObjectInterface.

use Phprise\Http\Request\StoreRequest;
use Phprise\Http\ValueObject\Uri;

$request = new StoreRequest(new Uri($url), $myDto);

4. Intercepting Responses (Events)

Use EventedConnector for PSR-14 event dispatching.

use Phprise\Http\Connector\EventedConnector;

$connector = new EventedConnector($baseConnector, $eventDispatcher);

Philosophy

We follow The OTAKU Manifesto: Fluid Structure Design.

  1. O - Own your Discipline (Be strict with yourself)
  2. T - Tools for Composition (Compose like Unix)
  3. A - Armor the Core (Protect the heart of the business)
  4. K - Keep Infrastructure Silent (Infrastructure is just a detail)
  5. U - Universal Language & Contracts (Speak the user's language via clear contracts)

Please read more about it in PHILOSOPHY.md.

License

MIT License

Free to use, modify, and distribute.

Contributing

See how to contribute in CONTRIBUTING.md.

Code of Conduct

See our code of conduct in CODE_OF_CONDUCT.md.

Security

See our security policy in SECURITY.md.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-08