2 declare(strict_types = 1);
18 use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
45 public function __construct(
string $context, array $variables)
47 $functionProviderInstances = [];
48 $providers = GeneralUtility::makeInstance(ProviderConfigurationLoader::class)->getExpressionLanguageProviders()[$context] ?? [];
50 array_unshift($providers, DefaultProvider::class);
51 $providers = array_unique($providers);
52 $functionProviders = [];
53 $generalVariables = [];
56 $providerInstance = GeneralUtility::makeInstance(
$provider);
57 $functionProviders[] = $providerInstance->getExpressionLanguageProviders();
58 $generalVariables[] = $providerInstance->getExpressionLanguageVariables();
60 $functionProviders = array_merge(...$functionProviders);
61 $generalVariables = array_replace_recursive(...$generalVariables);
62 $this->expressionLanguageVariables = array_replace_recursive($generalVariables, $variables);
63 foreach ($functionProviders as $functionProvider) {
64 $functionProviderInstances[] = GeneralUtility::makeInstance($functionProvider);
66 $this->expressionLanguage =
new ExpressionLanguage(
null, $functionProviderInstances);
75 public function evaluate(
string $condition):
bool
77 return (
bool)$this->expressionLanguage->evaluate($condition, $this->expressionLanguageVariables);
86 public function compile(
string $condition):
string
88 return (
string)$this->expressionLanguage->compile($condition, array_keys($this->expressionLanguageVariables));