Skip to content

Commit

Permalink
[BUGFIX] Use TYPO3 http client
Browse files Browse the repository at this point in the history
Since all $GLOBALS['TYPO3_CONF_VARS']['HTTP'] options should be
respected we can simple use the built in client. Also 'proxy'
is respected in this case, so we don't need a extra setting for this.

Resolves: web-vision#370
Relates: web-vision#331
  • Loading branch information
Mabahe committed Oct 22, 2024
1 parent d82b991 commit 7dde8f2
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions Classes/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DeepL\Translator;
use DeepL\TranslatorOptions;
use Psr\Log\LoggerInterface;
use TYPO3\CMS\Core\Http\Client\GuzzleClientFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use WebVision\WvDeepltranslate\Exception\ApiKeyNotSetException;

Expand Down Expand Up @@ -44,36 +45,9 @@ protected function getTranslator(): Translator
if ($this->configuration->getApiKey() === '') {
throw new ApiKeyNotSetException('The api key ist not set', 1708081233823);
}
$proxyUrl = $this->getConfiguredSystemProxy();
$options = [];
if ($proxyUrl !== null) {
$options[TranslatorOptions::PROXY] = $proxyUrl;
}
$options[TranslatorOptions::HTTP_CLIENT] = GeneralUtility::makeInstance(GuzzleClientFactory::class)->getClient();
$this->translator = new Translator($this->configuration->getApiKey(), $options);
return $this->translator;
}

/**
* Determines the configured TYPO3 proxy url for http(s) requests, dealing with
* the fact that this could be a single url or an array of urls per protocol.
*/
protected function getConfiguredSystemProxy(): ?string
{
if (empty($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy'])) {
return null;
}
if (is_string($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy'])
&& GeneralUtility::isValidUrl($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy'])
) {
return $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy'];
}
if (isset($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy']['http'])
&& is_string($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy']['http'])
&& $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy']['http'] !== ''
&& GeneralUtility::isValidUrl($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy']['http'])
) {
return $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy']['http'];
}
return null;
}
}

0 comments on commit 7dde8f2

Please sign in to comment.