‪TYPO3CMS  9.5
Resolver.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
20 
25 {
29  protected ‪$provider;
30 
34  protected ‪$expressionLanguage;
35 
40 
45  public function ‪__construct(string $context, array $variables)
46  {
47  $functionProviderInstances = [];
48  $providers = GeneralUtility::makeInstance(ProviderConfigurationLoader::class)->getExpressionLanguageProviders()[$context] ?? [];
49  // Always add default provider
50  array_unshift($providers, DefaultProvider::class);
51  $providers = array_unique($providers);
52  $functionProviders = [];
53  $generalVariables = [];
54  foreach ($providers as ‪$provider) {
56  $providerInstance = GeneralUtility::makeInstance(‪$provider);
57  $functionProviders[] = $providerInstance->getExpressionLanguageProviders();
58  $generalVariables[] = $providerInstance->getExpressionLanguageVariables();
59  }
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);
65  }
66  $this->expressionLanguage = new ExpressionLanguage(null, $functionProviderInstances);
67  }
68 
75  public function ‪evaluate(string $condition): bool
76  {
77  return (bool)$this->expressionLanguage->evaluate($condition, $this->expressionLanguageVariables);
78  }
79 
86  public function ‪compile(string $condition): string
87  {
88  return (string)$this->expressionLanguage->compile($condition, array_keys($this->expressionLanguageVariables));
89  }
90 }
‪TYPO3\CMS\Core\ExpressionLanguage\Resolver\$expressionLanguageVariables
‪array $expressionLanguageVariables
Definition: Resolver.php:36
‪TYPO3\CMS\Core\ExpressionLanguage\Resolver\evaluate
‪bool evaluate(string $condition)
Definition: Resolver.php:72
‪TYPO3\CMS\Core\ExpressionLanguage\Resolver\$expressionLanguage
‪Symfony Component ExpressionLanguage ExpressionLanguage $expressionLanguage
Definition: Resolver.php:32
‪TYPO3\CMS\Core\ExpressionLanguage\Resolver\compile
‪string compile(string $condition)
Definition: Resolver.php:83
‪TYPO3\CMS\Core\ExpressionLanguage\ProviderInterface
Definition: ProviderInterface.php:24
‪TYPO3\CMS\Core\ExpressionLanguage
Definition: AbstractProvider.php:3
‪TYPO3\CMS\Core\ExpressionLanguage\Resolver
Definition: Resolver.php:25
‪TYPO3\CMS\Core\ExpressionLanguage\Resolver\$provider
‪ProviderInterface $provider
Definition: Resolver.php:28
‪TYPO3\CMS\Core\ExpressionLanguage\Resolver\__construct
‪__construct(string $context, array $variables)
Definition: Resolver.php:42
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45