6ec9ca04b83fd1f6e179217eb7fadb1edd7c7d1c
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / ExpressionLanguage / TypoScriptConditionProvider.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\ExpressionLanguage;
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\ExpressionFunctionProviderInterface;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * Class TypoScriptConditionProvider
23 * @internal
24 */
25 class TypoScriptConditionProvider extends AbstractProvider
26 {
27 public function __construct(array $expressionLanguageVariables = [], array $expressionLanguageProviders = [])
28 {
29 $typo3 = new \stdClass();
30 $typo3->version = TYPO3_version;
31 $typo3->branch = TYPO3_branch;
32 $typo3->devIpMask = trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask']);
33 $this->expressionLanguageVariables = array_merge([
34 'request' => GeneralUtility::makeInstance(RequestWrapper::class),
35 'applicationContext' => (string)GeneralUtility::getApplicationContext(),
36 'typo3' => $typo3,
37 ], $expressionLanguageVariables);
38
39 $this->expressionLanguageProviders = $expressionLanguageProviders;
40 $this->initFunctions();
41 }
42
43 protected function initFunctions(): void
44 {
45 $this->expressionLanguageProviders[] = GeneralUtility::makeInstance(DefaultFunctionsProvider::class);
46 $this->expressionLanguageProviders[] = GeneralUtility::makeInstance(TypoScriptConditionFunctionsProvider::class);
47
48 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][__CLASS__]['additionalExpressionLanguageProvider'] ?? [] as $className) {
49 $expressionLanguageProvider = GeneralUtility::makeInstance($className);
50 if ($expressionLanguageProvider instanceof ExpressionFunctionProviderInterface) {
51 $this->expressionLanguageProviders[] = $expressionLanguageProvider;
52 }
53 }
54 }
55 }