[ 
https://issues.apache.org/jira/browse/THRIFT-6010?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Volodymyr Panivko updated THRIFT-6010:
--------------------------------------
    Description: 
Add a new HTTP client transport for the PHP library: 
{{Thrift\Transport\TPsrHttpClient}}.

*Design*
* Constructor: {{(string $url, ?ClientInterface $client = null, 
?RequestFactoryInterface $requestFactory = null, ?StreamFactoryInterface 
$streamFactory = null)}}.
* The transport delegates all network I/O to a PSR-18 {{ClientInterface}}; 
PSR-7 messages and PSR-17 factories handle request/URL construction. URL 
parsing, port-suppression and percent-encoding are no longer hand-rolled.
* When client / factories are omitted, {{php-http/discovery}} resolves them. 
Discovery failures are wrapped as {{TTransportException::NOT_OPEN}} with an 
actionable "Install one of: guzzlehttp/guzzle, symfony/http-client, 
php-http/curl-client" message instead of an autoloader-level fatal.
* PSR-7 {{\InvalidArgumentException}} and {{\RuntimeException}} from 
{{createStream}}/{{createRequest}}/{{withHeader}} are wrapped as 
{{TTransportException::NOT_OPEN}}. PSR-18 {{NetworkExceptionInterface}} maps to 
{{NOT_OPEN}}, other {{ClientExceptionInterface}} subtypes and non-200 responses 
map to {{UNKNOWN}}.

*Composer*
* {{require}}: {{psr/http-client}}, {{psr/http-factory}}, {{psr/http-message}}, 
{{php-http/discovery}}.
* {{suggest}}: {{guzzlehttp/guzzle}}, {{symfony/http-client}}, 
{{php-http/curl-client}}.
* {{require-dev}}: {{nyholm/psr7}} for the unit-test suite.
* {{config.allow-plugins}}: {{php-http/discovery}} explicitly allow-listed 
(Composer 2.2+ requirement).

*Deprecations*
* {{TCurlClient}} marked {{@deprecated}}; will be removed in the next version. 
Behaviour unchanged.
* {{THttpClient}} (stream wrapper via {{fopen}}) is left as a dependency-free 
alternative — not deprecated.

*Tests*
New {{TPsrHttpClientTest}} (15 cases) uses an injected fake {{ClientInterface}} 
and real {{nyholm/psr7}} factories — no {{phpmock}} required. Covers headers, 
URL pass-through, exception mapping (network, client, invalid URL), empty body, 
buffer lifecycle, status codes.

*Migration*
See {{lib/php/UPGRADING.md}} for Guzzle/Symfony/curl-client install examples 
and the new constructor signature.

  was:
Introduce a new HTTP transport `Thrift\Transport\TPsrHttpClient` backed by any 
PSR-18 `Psr\Http\Client\ClientInterface`. The constructor optionally accepts an 
injected client + PSR-7 factories; when omitted, dependencies are 
auto-discovered via `php-http/discovery`.

Concrete HTTP client implementations (Guzzle, Symfony HttpClient, 
php-http/curl-client) are listed under Composer `suggest` so the library 
remains backend-agnostic.

`Thrift\Transport\TCurlClient` (procedural ext-curl) is marked `@deprecated` in 
favor of the new class and will be removed in the next version. `THttpClient` 
(stream wrappers via fopen) remains as a dependency-free alternative.

Includes new unit tests using an injected fake `ClientInterface` (no `phpmock` 
mocking of `curl_*`/`fopen` required) and a new `lib/php/UPGRADING.md` 
migration guide.


> Add PSR-18 HTTP transport (TPsrHttpClient) and deprecate TCurlClient in PHP 
> library
> -----------------------------------------------------------------------------------
>
>                 Key: THRIFT-6010
>                 URL: https://issues.apache.org/jira/browse/THRIFT-6010
>             Project: Thrift
>          Issue Type: Improvement
>          Components: PHP - Library
>    Affects Versions: 0.24.0
>            Reporter: Volodymyr Panivko
>            Assignee: Volodymyr Panivko
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> Add a new HTTP client transport for the PHP library: 
> {{Thrift\Transport\TPsrHttpClient}}.
> *Design*
> * Constructor: {{(string $url, ?ClientInterface $client = null, 
> ?RequestFactoryInterface $requestFactory = null, ?StreamFactoryInterface 
> $streamFactory = null)}}.
> * The transport delegates all network I/O to a PSR-18 {{ClientInterface}}; 
> PSR-7 messages and PSR-17 factories handle request/URL construction. URL 
> parsing, port-suppression and percent-encoding are no longer hand-rolled.
> * When client / factories are omitted, {{php-http/discovery}} resolves them. 
> Discovery failures are wrapped as {{TTransportException::NOT_OPEN}} with an 
> actionable "Install one of: guzzlehttp/guzzle, symfony/http-client, 
> php-http/curl-client" message instead of an autoloader-level fatal.
> * PSR-7 {{\InvalidArgumentException}} and {{\RuntimeException}} from 
> {{createStream}}/{{createRequest}}/{{withHeader}} are wrapped as 
> {{TTransportException::NOT_OPEN}}. PSR-18 {{NetworkExceptionInterface}} maps 
> to {{NOT_OPEN}}, other {{ClientExceptionInterface}} subtypes and non-200 
> responses map to {{UNKNOWN}}.
> *Composer*
> * {{require}}: {{psr/http-client}}, {{psr/http-factory}}, 
> {{psr/http-message}}, {{php-http/discovery}}.
> * {{suggest}}: {{guzzlehttp/guzzle}}, {{symfony/http-client}}, 
> {{php-http/curl-client}}.
> * {{require-dev}}: {{nyholm/psr7}} for the unit-test suite.
> * {{config.allow-plugins}}: {{php-http/discovery}} explicitly allow-listed 
> (Composer 2.2+ requirement).
> *Deprecations*
> * {{TCurlClient}} marked {{@deprecated}}; will be removed in the next 
> version. Behaviour unchanged.
> * {{THttpClient}} (stream wrapper via {{fopen}}) is left as a dependency-free 
> alternative — not deprecated.
> *Tests*
> New {{TPsrHttpClientTest}} (15 cases) uses an injected fake 
> {{ClientInterface}} and real {{nyholm/psr7}} factories — no {{phpmock}} 
> required. Covers headers, URL pass-through, exception mapping (network, 
> client, invalid URL), empty body, buffer lifecycle, status codes.
> *Migration*
> See {{lib/php/UPGRADING.md}} for Guzzle/Symfony/curl-client install examples 
> and the new constructor signature.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to