Skip to content

Commit

Permalink
[BUGFIX] Ensure full compatible for proxy setting to retrieve Translator
Browse files Browse the repository at this point in the history
With web-vision#331 the TYPO3 proxy setting has been validated
and set as `DeepL Guzzle Client` transport option to
have a proper configured proxy used.

The TYPO3 proxy setting however allows setting it as a
single string url or as array for different protocols,
which is not respected.

This change modifies the `AbstractClient->getTranslator()`
implementation to handle this double structure for named
option correctly now.

Related: web-vision#331
  • Loading branch information
audef1 authored and sbuerk committed Jun 10, 2024
1 parent da5540f commit 7f3b8e7
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions Classes/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,39 @@ protected function getTranslator(): Translator
if ($this->translator instanceof Translator) {
return $this->translator;
}

if ($this->configuration->getApiKey() === '') {
throw new ApiKeyNotSetException('The api key ist not set', 1708081233823);
}

$proxyUrl = $this->getConfiguredSystemProxy();
$options = [];
if (
isset($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy'])
&& $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy'] !== ''
&& GeneralUtility::isValidUrl($GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy'])
) {
$options[TranslatorOptions::PROXY] = $GLOBALS['TYPO3_CONF_VARS']['HTTP']['proxy'];
if ($proxyUrl !== null) {
$options[TranslatorOptions::PROXY] = $proxyUrl;
}

$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 7f3b8e7

Please sign in to comment.