Skip to content

Commit

Permalink
Merge pull request #336 from staempfli-webteam/feature/proxy
Browse files Browse the repository at this point in the history
[BUGFIX] Ensure full compatible for proxy setting to retrieve Translator
  • Loading branch information
NarkNiro authored Jun 10, 2024
2 parents da5540f + 8beebbd commit dea7d0d
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 dea7d0d

Please sign in to comment.