nessworthy/amphp-http-httplug

一个小巧的适配器包,用于通过 amphp/http-client 支持php-http/async-client-implementation。

1.0.1 2021-04-27 07:39 UTC

This package is auto-updated.

Last update: 2024-08-27 15:03:43 UTC


README

未经 AMPHP 认可或支持。也不会说它有多好。

如果你有一个需要 php-http/client-implementation 的包,但正在运行 AMP,那么这就是解决方案!

要求

  • PHP >= 7.2
  • 实现 psr/http-factory-implementationpsr/http-message-implementation。我推荐 laminas/laminas-diactoros,因为它有一个100%不可能记住的名字,而且是一个非常好的包。
  • AMPHP(当然)。

使用

// Implementations of request/response factory interfaces. Are not bundled with this package!
use Laminas\Diactoros\RequestFactory;
use Laminas\Diactoros\ResponseFactory;

use Amp\Http\Client\Psr7\PsrAdapter;
use Nessworthy\AmpHttpPlug\AmpHttpClientAdapter;

use Amp\Http\Client\HttpClientBuilder;

$httpClient = HttpClientBuilder::buildDefault();
$psrAdapter = new PsrAdapter(
    new RequestFactory,
    new ResponseFactory
);

// Implements async and non-async interfaces.
$adapter = new AmpHttpClientAdapter(
    $httpClient,
    $psrAdapter
);