-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53a7583
commit acc3183
Showing
2 changed files
with
26 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,45 +14,39 @@ | |
use Brotkrueml\MatomoWidgets\Domain\Entity\CustomDimension; | ||
use Brotkrueml\MatomoWidgets\Domain\Validation\CustomDimensionConfigurationValidator; | ||
use Brotkrueml\MatomoWidgets\Extension; | ||
use Psr\Log\NullLogger; | ||
use Symfony\Component\Finder\Exception\DirectoryNotFoundException; | ||
use Symfony\Component\Finder\Finder; | ||
use Symfony\Component\Yaml\Yaml; | ||
use TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ConfigurationFinder | ||
{ | ||
/** | ||
* Regex pattern for allowed characters in environment variables | ||
* @see https://regex101.com/r/hIXvef/1 | ||
* @see https://stackoverflow.com/questions/2821043/allowed-characters-in-linux-environment-variable-names | ||
*/ | ||
private const ENV_VAR_REGEX = '/^%env\(([a-zA-Z_]\w*)\)%$/'; | ||
|
||
public static function buildConfigurations(string $configPath, bool $isMatomoIntegrationAvailable): Configurations | ||
{ | ||
$yamlFileLoader = new YamlFileLoader(new NullLogger()); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
brotkrueml
Author
Owner
|
||
$configurationsArray = []; | ||
foreach (self::getConfigurationFiles($configPath) as $file) { | ||
$realFile = $file->getRealPath(); | ||
if ($realFile === false) { | ||
continue; | ||
} | ||
$siteConfiguration = Yaml::parseFile($realFile); | ||
$realFile = GeneralUtility::fixWindowsFilePath($realFile); | ||
$siteConfiguration = $yamlFileLoader->load($realFile); | ||
|
||
$considerMatomoIntegration = $isMatomoIntegrationAvailable | ||
&& ($siteConfiguration['matomoWidgetsConsiderMatomoIntegration'] ?? false); | ||
|
||
if ($considerMatomoIntegration) { | ||
$url = $siteConfiguration['matomoIntegrationUrl'] ?? ''; | ||
$idSite = (string) ($siteConfiguration['matomoIntegrationSiteId'] ?? 0); | ||
$idSite = (int) ($siteConfiguration['matomoIntegrationSiteId'] ?? 0); | ||
} else { | ||
$url = $siteConfiguration['matomoWidgetsUrl'] ?? ''; | ||
$idSite = (string) ($siteConfiguration['matomoWidgetsIdSite'] ?? 0); | ||
$idSite = (int) ($siteConfiguration['matomoWidgetsIdSite'] ?? 0); | ||
} | ||
$url = self::resolveEnvironmentVariable($url); | ||
$idSite = (int) self::resolveEnvironmentVariable($idSite); | ||
if ($url === '') { | ||
continue; | ||
} | ||
|
@@ -65,10 +59,9 @@ public static function buildConfigurations(string $configPath, bool $isMatomoInt | |
} else { | ||
$pagesNotFoundTemplate = $siteConfiguration['matomoWidgetsPagesNotFoundTemplate'] ?? ''; | ||
} | ||
$pagesNotFoundTemplate = self::resolveEnvironmentVariable($pagesNotFoundTemplate); | ||
|
||
$siteTitle = self::resolveEnvironmentVariable($siteConfiguration['matomoWidgetsTitle'] ?? ''); | ||
$tokenAuth = self::resolveEnvironmentVariable($siteConfiguration['matomoWidgetsTokenAuth'] ?? ''); | ||
$siteTitle = $siteConfiguration['matomoWidgetsTitle'] ?? ''; | ||
$tokenAuth = $siteConfiguration['matomoWidgetsTokenAuth'] ?? ''; | ||
|
||
$pathSegments = \explode('/', $file->getPath()); | ||
$identifier = \end($pathSegments); | ||
|
@@ -80,7 +73,7 @@ public static function buildConfigurations(string $configPath, bool $isMatomoInt | |
|
||
$activeWidgets = GeneralUtility::trimExplode( | ||
',', | ||
self::resolveEnvironmentVariable($siteConfiguration['matomoWidgetsActiveWidgets'] ?? ''), | ||
$siteConfiguration['matomoWidgetsActiveWidgets'] ?? '', | ||
true, | ||
); | ||
$customDimensions = self::buildCustomDimensions($siteConfiguration['matomoWidgetsCustomDimensions'] ?? []); | ||
|
@@ -128,24 +121,6 @@ private static function getConfigurationFiles(string $configPath): array | |
return [...$siteFiles, ...$additionalFiles]; | ||
} | ||
|
||
/** | ||
* This method is necessary as environment variables are not resolved when configuration | ||
* is available in controllers. | ||
*/ | ||
private static function resolveEnvironmentVariable(string $value): string | ||
{ | ||
if (\preg_match(self::ENV_VAR_REGEX, $value, $matches) !== 1) { | ||
return $value; | ||
} | ||
|
||
$resolvedValue = \getenv($matches[1]); | ||
if ($resolvedValue === false) { | ||
return ''; | ||
} | ||
|
||
return $resolvedValue; | ||
} | ||
|
||
/** | ||
* @param list<array{scope: string, idDimension: int|string, title?: string, description?: string}> $configurations | ||
* @return CustomDimension[] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YamlFileLoader has no constructor, the logger needs so be set using the setter when instantiated manually:
Without that change i constantly get the this exception (e.g. when clearing cache through typo3 cli):