DeepLcom / deepl-php

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

fix: make logger option compatible with PSR-3 Logger #12

Closed Schleuse closed 1 year ago

Schleuse commented 2 years ago

Contrary to the documentation it's currently not possible to pass a PSR-3 logger implementation (e.g. Monolog) as the logger option, because of the types declared in the constructor of HttpClient.

According to the constructor you have to pass a DeepL\LoggerInterface. Monolog for example implements Psr\Log\LoggerInterface but of cause not DeepL\LoggerInterface.

Because of that you''ll get an Exception when you pass a Monolog logger to the logger option of the Translator:

Argument 5 passed to DeepL\HttpClient::__construct() must be an instance of DeepL\LoggerInterface or null, instance of Monolog\Logger given

This PR replaces DeepL\LoggerInterface with the Psr\Log\LoggerInterface which Monolog and other Logging Frameworks implement, making it possible to pass them as a logger to Translator.

daniel-jones-deepl commented 1 year ago

Hi @Schleuse, thanks for the contribution, sorry that it took so long to respond. We will merge your Pull Request soon.

We were a bit unsure about adding a new dependency, but as psr/log is standardized we think it should not break backward-compatibility.