TYPO3 v15 dev-main snapshot ()
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Core\ExpressionLanguage;
|
||||
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
|
||||
|
||||
/**
|
||||
* Provide functions and variables to symfony expression language.
|
||||
*
|
||||
* Note 'variables' should only rely on things that can be injected.
|
||||
* Accessing for instance $GLOBALS['TYPO3_REQUEST'] and providing this
|
||||
* as variable is a misuse - runtime related variables must be provided
|
||||
* by the caller to the Resolver class directly.
|
||||
*/
|
||||
abstract class AbstractProvider implements ProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var list<class-string<ExpressionFunctionProviderInterface>>
|
||||
*/
|
||||
protected array $expressionLanguageProviders = [];
|
||||
|
||||
/**
|
||||
* @var array<non-empty-string, mixed>
|
||||
*/
|
||||
protected array $expressionLanguageVariables = [];
|
||||
|
||||
public function getExpressionLanguageProviders(): array
|
||||
{
|
||||
return $this->expressionLanguageProviders;
|
||||
}
|
||||
|
||||
public function getExpressionLanguageVariables(): array
|
||||
{
|
||||
return $this->expressionLanguageVariables;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Core\ExpressionLanguage;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
|
||||
use TYPO3\CMS\Core\Configuration\Features;
|
||||
use TYPO3\CMS\Core\Context\Context;
|
||||
use TYPO3\CMS\Core\Core\Environment;
|
||||
use TYPO3\CMS\Core\ExpressionLanguage\FunctionsProvider\DefaultFunctionsProvider;
|
||||
use TYPO3\CMS\Core\Information\Typo3Version;
|
||||
|
||||
/**
|
||||
* Prepare a couple of default variables and register some
|
||||
* general functions that work with it.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
#[Autoconfigure(public: true)]
|
||||
class DefaultProvider extends AbstractProvider
|
||||
{
|
||||
public function __construct(
|
||||
Typo3Version $typo3Version,
|
||||
Context $context,
|
||||
Features $features,
|
||||
) {
|
||||
$typo3 = new \stdClass();
|
||||
$typo3->version = $typo3Version->getVersion();
|
||||
$typo3->branch = $typo3Version->getBranch();
|
||||
$typo3->devIpMask = trim($GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'] ?? '');
|
||||
$this->expressionLanguageVariables = [
|
||||
'applicationContext' => (string)Environment::getContext(),
|
||||
'typo3' => $typo3,
|
||||
'date' => $context->getAspect('date'),
|
||||
'features' => $features,
|
||||
];
|
||||
$this->expressionLanguageProviders[] = DefaultFunctionsProvider::class;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Core\ExpressionLanguage\FunctionsProvider;
|
||||
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
|
||||
use TYPO3\CMS\Core\ExpressionLanguage\RequestWrapper;
|
||||
use TYPO3\CMS\Core\Utility\ArrayUtility;
|
||||
use TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Core\Utility\StringUtility;
|
||||
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
|
||||
|
||||
/**
|
||||
* Default expression language functions. This is currently paired with
|
||||
* DefaultProvider class, which provides appropriate variables that
|
||||
* can be injected.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
readonly class DefaultFunctionsProvider implements ExpressionFunctionProviderInterface
|
||||
{
|
||||
/**
|
||||
* @return ExpressionFunction[] An array of Function instances
|
||||
*/
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
$this->getIpFunction(),
|
||||
$this->getCompatVersionFunction(),
|
||||
$this->getLikeFunction(),
|
||||
$this->getEnvFunction(),
|
||||
$this->getDateFunction(),
|
||||
$this->getFeatureToggleFunction(),
|
||||
$this->getTraverseArrayFunction(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getIpFunction(): ExpressionFunction
|
||||
{
|
||||
return new ExpressionFunction(
|
||||
'ip',
|
||||
static fn() => null, // Not implemented, we only use the evaluator
|
||||
static function ($arguments, $str) {
|
||||
if ($str === 'devIP') {
|
||||
$str = $arguments['typo3']->devIpMask;
|
||||
}
|
||||
$request = $arguments['request'] ?? null;
|
||||
if (!$request instanceof RequestWrapper) {
|
||||
throw new \RuntimeException(
|
||||
'Using expression language function "ip(' . $str . ')" in a context without request.',
|
||||
1686745105
|
||||
);
|
||||
}
|
||||
$normalizedParams = $request->getNormalizedParams();
|
||||
if ($normalizedParams === null) {
|
||||
return false;
|
||||
}
|
||||
return GeneralUtility::cmpIP($normalizedParams->getRemoteAddress(), $str);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCompatVersionFunction(): ExpressionFunction
|
||||
{
|
||||
return new ExpressionFunction(
|
||||
'compatVersion',
|
||||
static fn() => null, // Not implemented, we only use the evaluator
|
||||
static function ($arguments, mixed $str) {
|
||||
return VersionNumberUtility::convertVersionNumberToInteger($arguments['typo3']->branch)
|
||||
>= VersionNumberUtility::convertVersionNumberToInteger((string)$str);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected function getLikeFunction(): ExpressionFunction
|
||||
{
|
||||
return new ExpressionFunction(
|
||||
'like',
|
||||
static fn() => null, // Not implemented, we only use the evaluator
|
||||
static function ($arguments, $haystack, $needle) {
|
||||
return StringUtility::searchStringWildcard((string)$haystack, (string)$needle);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected function getEnvFunction(): ExpressionFunction
|
||||
{
|
||||
return ExpressionFunction::fromPhp('getenv');
|
||||
}
|
||||
|
||||
protected function getDateFunction(): ExpressionFunction
|
||||
{
|
||||
return new ExpressionFunction(
|
||||
'date',
|
||||
static fn() => null, // Not implemented, we only use the evaluator
|
||||
static function ($arguments, $format) {
|
||||
return $arguments['date']->getDateTime()->format($format);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected function getFeatureToggleFunction(): ExpressionFunction
|
||||
{
|
||||
return new ExpressionFunction(
|
||||
'feature',
|
||||
static fn() => null, // Not implemented, we only use the evaluator
|
||||
static function ($arguments, $featureName) {
|
||||
return $arguments['features']->isFeatureEnabled($featureName);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected function getTraverseArrayFunction(): ExpressionFunction
|
||||
{
|
||||
return new ExpressionFunction(
|
||||
'traverse',
|
||||
static fn() => null, // Not implemented, we only use the evaluator
|
||||
static function ($arguments, $array, $path) {
|
||||
if (!is_array($array) || !is_string($path) || $path === '') {
|
||||
return '';
|
||||
}
|
||||
try {
|
||||
return ArrayUtility::getValueByPath($array, $path);
|
||||
} catch (MissingArrayPathException) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Core\ExpressionLanguage\FunctionsProvider;
|
||||
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
|
||||
use TYPO3\CMS\Core\Site\Entity\SiteInterface;
|
||||
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
||||
|
||||
/**
|
||||
* Functions available in 'TypoScript' context. Note these rely on variables
|
||||
* being hand over, see IncludeTreeConditionMatcherVisitor for more details.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
readonly class Typo3ConditionFunctionsProvider implements ExpressionFunctionProviderInterface
|
||||
{
|
||||
/**
|
||||
* @return ExpressionFunction[] An array of Function instances
|
||||
*/
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
$this->getSessionFunction(),
|
||||
$this->getSiteFunction(),
|
||||
$this->getSiteLanguageFunction(),
|
||||
$this->getLocaleFunction(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getSessionFunction(): ExpressionFunction
|
||||
{
|
||||
return new ExpressionFunction(
|
||||
'session',
|
||||
static fn() => null, // Not implemented, we only use the evaluator
|
||||
static function ($arguments, $str) {
|
||||
$retVal = null;
|
||||
$keyParts = explode('|', $str);
|
||||
$sessionKey = array_shift($keyParts);
|
||||
$frontendUser = $arguments['request']->getFrontendUser();
|
||||
if ($frontendUser) {
|
||||
$retVal = $frontendUser->getSessionData($sessionKey);
|
||||
foreach ($keyParts as $keyPart) {
|
||||
if (is_object($retVal)) {
|
||||
$retVal = $retVal->{$keyPart};
|
||||
} elseif (is_array($retVal)) {
|
||||
$retVal = $retVal[$keyPart];
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $retVal;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected function getSiteFunction(): ExpressionFunction
|
||||
{
|
||||
return new ExpressionFunction(
|
||||
'site',
|
||||
static fn() => null, // Not implemented, we only use the evaluator
|
||||
static function ($arguments, $str) {
|
||||
$site = $arguments['site'] ?? null;
|
||||
if ($site instanceof SiteInterface) {
|
||||
$methodName = 'get' . ucfirst(trim($str));
|
||||
if (method_exists($site, $methodName)) {
|
||||
return $site->$methodName();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected function getSiteLanguageFunction(): ExpressionFunction
|
||||
{
|
||||
return new ExpressionFunction(
|
||||
'siteLanguage',
|
||||
static fn() => null, // Not implemented, we only use the evaluator
|
||||
static function ($arguments, $str) {
|
||||
$siteLanguage = $arguments['siteLanguage'] ?? null;
|
||||
if ($siteLanguage instanceof SiteLanguage) {
|
||||
$methodName = 'get' . ucfirst(trim($str));
|
||||
if (method_exists($siteLanguage, $methodName)) {
|
||||
return $siteLanguage->$methodName();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected function getLocaleFunction(): ExpressionFunction
|
||||
{
|
||||
return new ExpressionFunction(
|
||||
'locale',
|
||||
static fn() => null, // Not implemented, we only use the evaluator
|
||||
static function (array $arguments) {
|
||||
$siteLanguage = $arguments['siteLanguage'] ?? null;
|
||||
if ($siteLanguage instanceof SiteLanguage) {
|
||||
return $siteLanguage->getLocale();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Core\ExpressionLanguage;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
use TYPO3\CMS\Core\Attribute\AsEventListener;
|
||||
use TYPO3\CMS\Core\Cache\Event\CacheWarmupEvent;
|
||||
use TYPO3\CMS\Core\Cache\Frontend\PhpFrontend;
|
||||
use TYPO3\CMS\Core\Package\PackageManager;
|
||||
|
||||
/**
|
||||
* This class resolves the expression language provider configuration and store in a cache.
|
||||
*/
|
||||
#[Autoconfigure(public: true)]
|
||||
readonly class ProviderConfigurationLoader
|
||||
{
|
||||
public function __construct(
|
||||
private PackageManager $packageManager,
|
||||
#[Autowire(service: 'cache.core')]
|
||||
private PhpFrontend $coreCache,
|
||||
#[Autowire(expression: 'service("package-dependent-cache-identifier").withPrefix("ExpressionLanguageProviders").toString()')]
|
||||
private string $cacheIdentifier,
|
||||
) {}
|
||||
|
||||
public function getExpressionLanguageProviders(): array
|
||||
{
|
||||
$providers = $this->coreCache->require($this->cacheIdentifier);
|
||||
if ($providers !== false) {
|
||||
return $providers;
|
||||
}
|
||||
|
||||
return $this->createCache();
|
||||
}
|
||||
|
||||
private function createCache(): array
|
||||
{
|
||||
$packages = $this->packageManager->getActivePackages();
|
||||
$providers = [];
|
||||
foreach ($packages as $package) {
|
||||
$packageConfiguration = $package->getPackagePath() . 'Configuration/ExpressionLanguage.php';
|
||||
if (file_exists($packageConfiguration)) {
|
||||
$providersInPackage = require $packageConfiguration;
|
||||
if (is_array($providersInPackage)) {
|
||||
$providers[] = $providersInPackage;
|
||||
}
|
||||
}
|
||||
}
|
||||
$providers = count($providers) > 0 ? array_merge_recursive(...$providers) : $providers;
|
||||
$this->coreCache->set($this->cacheIdentifier, 'return ' . var_export($providers, true) . ';');
|
||||
return $providers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
#[AsEventListener]
|
||||
public function warmupCaches(CacheWarmupEvent $event): void
|
||||
{
|
||||
if ($event->hasGroup('system')) {
|
||||
$this->createCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Core\ExpressionLanguage;
|
||||
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
|
||||
|
||||
interface ProviderInterface
|
||||
{
|
||||
/**
|
||||
* An array of class names which implements the ExpressionFunctionProviderInterface
|
||||
*
|
||||
* @return list<class-string<ExpressionFunctionProviderInterface>>
|
||||
*/
|
||||
public function getExpressionLanguageProviders(): array;
|
||||
|
||||
/**
|
||||
* An array with key/value pairs. The key will be available as variable name
|
||||
*
|
||||
* @return array<non-empty-string, mixed>
|
||||
*/
|
||||
public function getExpressionLanguageVariables(): array;
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Core\ExpressionLanguage;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use TYPO3\CMS\Core\Http\NormalizedParams;
|
||||
use TYPO3\CMS\Core\Http\ServerRequest;
|
||||
use TYPO3\CMS\Core\Routing\PageArguments;
|
||||
use TYPO3\CMS\Core\Site\Entity\SiteInterface;
|
||||
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
||||
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
|
||||
|
||||
/**
|
||||
* This class provides access to some methods of the ServerRequest object.
|
||||
* To prevent access to all methods of the ServerRequest object within conditions,
|
||||
* this class was introduced to control which methods are exposed.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class RequestWrapper
|
||||
{
|
||||
protected ServerRequestInterface $request;
|
||||
|
||||
public function __construct(?ServerRequestInterface $request)
|
||||
{
|
||||
$this->request = $request ?? new ServerRequest();
|
||||
}
|
||||
|
||||
public function getQueryParams(): array
|
||||
{
|
||||
return $this->request->getQueryParams();
|
||||
}
|
||||
|
||||
public function getParsedBody(): array
|
||||
{
|
||||
return (array)($this->request->getParsedBody() ?? []);
|
||||
}
|
||||
|
||||
public function getHeaders(): array
|
||||
{
|
||||
return $this->request->getHeaders();
|
||||
}
|
||||
|
||||
public function getCookieParams(): array
|
||||
{
|
||||
return $this->request->getCookieParams();
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo: Could be removed since 'site' variable is provided explicitly.
|
||||
*/
|
||||
public function getSite(): ?SiteInterface
|
||||
{
|
||||
return $this->request->getAttribute('site');
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo: Could be removed since 'siteLanguage' variable is provided explicitly.
|
||||
*/
|
||||
public function getSiteLanguage(): ?SiteLanguage
|
||||
{
|
||||
return $this->request->getAttribute('language');
|
||||
}
|
||||
|
||||
public function getNormalizedParams(): ?NormalizedParams
|
||||
{
|
||||
return $this->request->getAttribute('normalizedParams');
|
||||
}
|
||||
|
||||
public function getPageArguments(): ?PageArguments
|
||||
{
|
||||
return ($routing = $this->request->getAttribute('routing')) instanceof PageArguments ? $routing : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal Exposing the full FE user object may change
|
||||
*/
|
||||
public function getFrontendUser(): ?FrontendUserAuthentication
|
||||
{
|
||||
return $this->request->getAttribute('frontend.user');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Core\ExpressionLanguage;
|
||||
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* The main API endpoint to evaluate symfony expression language.
|
||||
*
|
||||
* This Resolver can prepare common variables and functions for specific scopes,
|
||||
* it is a "prepared" facade to symfony expression language that can load
|
||||
* and provide things from Configuration.
|
||||
*/
|
||||
class Resolver
|
||||
{
|
||||
private ExpressionLanguage $expressionLanguage;
|
||||
private array $expressionLanguageVariables;
|
||||
|
||||
public function __construct(string $context, array $variables)
|
||||
{
|
||||
$functionProviderInstances = [];
|
||||
// @todo: The entire ProviderConfigurationLoader approach should fall and
|
||||
// substituted with a symfony service provider strategy in v13.
|
||||
// Also, the magic "DefaultProvider" approach should fall at this time,
|
||||
// default functions and variable providers should be provided explicitly
|
||||
// by config.
|
||||
// The entire construct should be reviewed at this point and most likely
|
||||
// declared final as well.
|
||||
$providers = GeneralUtility::makeInstance(ProviderConfigurationLoader::class)->getExpressionLanguageProviders()[$context] ?? [];
|
||||
// Always add default provider
|
||||
array_unshift($providers, DefaultProvider::class);
|
||||
$providers = array_unique($providers);
|
||||
$functionProviders = [];
|
||||
$generalVariables = [];
|
||||
foreach ($providers as $provider) {
|
||||
/** @var ProviderInterface $providerInstance */
|
||||
$providerInstance = GeneralUtility::makeInstance($provider);
|
||||
$functionProviders[] = $providerInstance->getExpressionLanguageProviders();
|
||||
$generalVariables[] = $providerInstance->getExpressionLanguageVariables();
|
||||
}
|
||||
$functionProviders = array_merge(...$functionProviders);
|
||||
$generalVariables = array_replace_recursive(...$generalVariables);
|
||||
$this->expressionLanguageVariables = array_replace_recursive($generalVariables, $variables);
|
||||
foreach ($functionProviders as $functionProvider) {
|
||||
/** @var ExpressionFunctionProviderInterface[] $functionProviderInstances */
|
||||
$functionProviderInstances[] = GeneralUtility::makeInstance($functionProvider);
|
||||
}
|
||||
$this->expressionLanguage = new ExpressionLanguage(null, $functionProviderInstances);
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluate an expression.
|
||||
*/
|
||||
public function evaluate(string $expression, array $contextVariables = []): mixed
|
||||
{
|
||||
return $this->expressionLanguage->evaluate($expression, array_replace($this->expressionLanguageVariables, $contextVariables));
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiles an expression to source code.
|
||||
* Currently unused in core: We *may* add support for this later to speed up condition parsing?
|
||||
*/
|
||||
public function compile(string $condition): string
|
||||
{
|
||||
return $this->expressionLanguage->compile($condition, array_keys($this->expressionLanguageVariables));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Core\ExpressionLanguage;
|
||||
|
||||
/**
|
||||
* Provider for the 'routing' expression language context.
|
||||
*
|
||||
* Allows extensions to register additional functions and variables
|
||||
* for route enhancer limitToPages expressions.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class RoutingConditionProvider extends AbstractProvider
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->expressionLanguageProviders = [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Core\ExpressionLanguage;
|
||||
|
||||
use TYPO3\CMS\Core\ExpressionLanguage\FunctionsProvider\Typo3ConditionFunctionsProvider;
|
||||
|
||||
/**
|
||||
* Register default functions in 'typoscript' context. Note the
|
||||
* Typo3ConditionFunctionsProvider relies on variables/arguments
|
||||
* being hand over as variables to the Resolver.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class TypoScriptConditionProvider extends AbstractProvider
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->expressionLanguageProviders = [
|
||||
Typo3ConditionFunctionsProvider::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user