‪TYPO3CMS  10.4
DefaultFunctionsProvider.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
20 use Symfony\Component\ExpressionLanguage\ExpressionFunction;
21 use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
29 
34 class ‪DefaultFunctionsProvider implements ExpressionFunctionProviderInterface
35 {
39  public function ‪getFunctions()
40  {
41  return [
42  $this->‪getIpFunction(),
44  $this->‪getLikeFunction(),
45  $this->‪getEnvFunction(),
46  $this->‪getDateFunction(),
49  ];
50  }
51 
52  protected function ‪getIpFunction(): ExpressionFunction
53  {
54  return new ExpressionFunction(
55  'ip',
56  function () {
57  // Not implemented, we only use the evaluator
58  },
59  function ($arguments, $str) {
60  if ($str === 'devIP') {
61  $str = trim(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'] ?? '');
62  }
63  return (bool)GeneralUtility::cmpIP(GeneralUtility::getIndpEnv('REMOTE_ADDR'), $str);
64  }
65  );
66  }
67 
68  protected function ‪getCompatVersionFunction(): ExpressionFunction
69  {
70  return new ExpressionFunction(
71  'compatVersion',
72  function () {
73  // Not implemented, we only use the evaluator
74  },
75  function ($arguments, $str) {
78  }
79  );
80  }
81 
82  protected function ‪getLikeFunction(): ExpressionFunction
83  {
84  return new ExpressionFunction('like', function () {
85  // Not implemented, we only use the evaluator
86  }, function ($arguments, $haystack, $needle) {
87  $result = ‪StringUtility::searchStringWildcard((string)$haystack, (string)$needle);
88  return $result;
89  });
90  }
91 
92  protected function ‪getEnvFunction(): ExpressionFunction
93  {
94  return ExpressionFunction::fromPhp('getenv');
95  }
96 
97  protected function ‪getDateFunction(): ExpressionFunction
98  {
99  return new ExpressionFunction('date', function () {
100  // Not implemented, we only use the evaluator
101  }, function ($arguments, $format) {
102  return GeneralUtility::makeInstance(Context::class)
103  ->getAspect('date')->getDateTime()->format($format);
104  });
105  }
106 
107  protected function ‪getFeatureToggleFunction(): ExpressionFunction
108  {
109  return new ExpressionFunction('feature', function () {
110  // Not implemented, we only use the evaluator
111  }, function ($arguments, $featureName) {
112  return GeneralUtility::makeInstance(Features::class)
113  ->isFeatureEnabled($featureName);
114  });
115  }
116 
117  public function ‪getTraverseArrayFunction(): ExpressionFunction
118  {
119  return new ExpressionFunction('traverse', function () {
120  // Not implemented, we only use the evaluator
121  }, function ($arguments, $array, $path) {
122  if (!is_array($array) || !is_string($path) || $path === '') {
123  return '';
124  }
125  try {
126  return ‪ArrayUtility::getValueByPath($array, $path);
127  } catch (‪MissingArrayPathException $e) {
128  return '';
129  }
130  });
131  }
132 }
‪TYPO3\CMS\Core\Utility\VersionNumberUtility
Definition: VersionNumberUtility.php:25
‪TYPO3\CMS\Core\Utility\StringUtility\searchStringWildcard
‪static bool searchStringWildcard($haystack, $needle)
Definition: StringUtility.php:134
‪TYPO3\CMS\Core\ExpressionLanguage\FunctionsProvider
Definition: DefaultFunctionsProvider.php:18
‪TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException
Definition: MissingArrayPathException.php:28
‪TYPO3\CMS\Core\ExpressionLanguage\FunctionsProvider\DefaultFunctionsProvider\getEnvFunction
‪getEnvFunction()
Definition: DefaultFunctionsProvider.php:92
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Core\ExpressionLanguage\FunctionsProvider\DefaultFunctionsProvider\getFunctions
‪ExpressionFunction[] getFunctions()
Definition: DefaultFunctionsProvider.php:39
‪TYPO3\CMS\Core\Utility\VersionNumberUtility\convertVersionNumberToInteger
‪static int convertVersionNumberToInteger($versionNumber)
Definition: VersionNumberUtility.php:32
‪TYPO3\CMS\Core\Utility\ArrayUtility\getValueByPath
‪static mixed getValueByPath(array $array, $path, $delimiter='/')
Definition: ArrayUtility.php:180
‪TYPO3\CMS\Core\ExpressionLanguage\FunctionsProvider\DefaultFunctionsProvider\getDateFunction
‪getDateFunction()
Definition: DefaultFunctionsProvider.php:97
‪TYPO3\CMS\Core\Configuration\Features
Definition: Features.php:56
‪TYPO3\CMS\Core\ExpressionLanguage\FunctionsProvider\DefaultFunctionsProvider\getTraverseArrayFunction
‪getTraverseArrayFunction()
Definition: DefaultFunctionsProvider.php:117
‪TYPO3\CMS\Core\ExpressionLanguage\FunctionsProvider\DefaultFunctionsProvider
Definition: DefaultFunctionsProvider.php:35
‪TYPO3\CMS\Core\Utility\ArrayUtility
Definition: ArrayUtility.php:24
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\ExpressionLanguage\FunctionsProvider\DefaultFunctionsProvider\getCompatVersionFunction
‪getCompatVersionFunction()
Definition: DefaultFunctionsProvider.php:68
‪TYPO3\CMS\Core\ExpressionLanguage\FunctionsProvider\DefaultFunctionsProvider\getLikeFunction
‪getLikeFunction()
Definition: DefaultFunctionsProvider.php:82
‪TYPO3\CMS\Core\ExpressionLanguage\FunctionsProvider\DefaultFunctionsProvider\getIpFunction
‪getIpFunction()
Definition: DefaultFunctionsProvider.php:52
‪TYPO3\CMS\Core\ExpressionLanguage\FunctionsProvider\DefaultFunctionsProvider\getFeatureToggleFunction
‪getFeatureToggleFunction()
Definition: DefaultFunctionsProvider.php:107
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22