DeepLcom / deepl-php

Official PHP library for the DeepL language translation API.
MIT License
207 stars 22 forks source link

FEATURE REQUEST: Add support for changing httpClient #19

Closed Radon8472 closed 1 year ago

Radon8472 commented 1 year ago

Currently you are using a static internal http client based on curl. It would be good if there would be an option to set an alternative http client (e.g. guzzlephp, php streams or any psr18 compatible client).

This would be usefull e.g. when you can`t use curl, or when you are using any framework with its own httpclient.

I would suggest to add a new option to the options array e.g.

  $translator = new \DeepL\Translator($authKey);
  $translator->translateText($text, $source, $target, [
      'httpClient' => new Psr18Client()
  ]);

The option httpClient should accept any client matching to an from predefined defined "HttpClientInterface" and you change your code to only use HttpClientInterface to be compatible with all comming implementations on this interface.

Benefit would be, you only need to implement the basic logic of passing new clients based on this interface, createing different clients could be done by the community.

examples how this could be done can be found in other projects using changeable http clients like here

EDIT: This feature would automatically resolve #14 because you could ad or change an alternative curl client with custom config.

daniel-jones-deepl commented 1 year ago

Hi @Radon8472, sorry that we didn't react to this issue earlier. @JanEbbing has been working on this feature, you can see the work in this comment.

JanEbbing commented 1 year ago

This is implemented now in the new v1.5.0, please update to use this feature (and feel free to provide any feedback).

Radon8472 commented 1 year ago

Hi @Radon8472, sorry that we didn't react to this issue earlier. @JanEbbing has been working on this feature, you can see the work in this comment.

@JanEbbing , @daniel-jones-deepl

I tested this feature in v1.5, but unfortunally it still has some bugs. I created a new issue #29 for this, because it seems to be another context