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
|
|
|
|
18
|
|
|
namespace TYPO3\CMS\Core\ExpressionLanguage; |
19
|
|
|
|
20
|
|
|
use TYPO3\CMS\Core\Cache\Frontend\PhpFrontend; |
21
|
|
|
use TYPO3\CMS\Core\Package\PackageManager; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class ProviderConfigurationLoader |
25
|
|
|
* This class resolves the expression language provider configuration and store in a cache. |
26
|
|
|
*/ |
27
|
|
|
class ProviderConfigurationLoader |
28
|
|
|
{ |
29
|
|
|
protected PackageManager $packageManager; |
30
|
|
|
|
31
|
|
|
protected PhpFrontend $cache; |
32
|
|
|
|
33
|
|
|
protected string $cacheIdentifier = 'expressionLanguageProviders'; |
34
|
|
|
|
35
|
|
|
public function __construct(PackageManager $packageManager, PhpFrontend $coreCache) |
36
|
|
|
{ |
37
|
|
|
$this->packageManager = $packageManager; |
38
|
|
|
$this->cache = $coreCache; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
public function getExpressionLanguageProviders(): array |
45
|
|
|
{ |
46
|
|
|
$providers = $this->cache->require($this->cacheIdentifier); |
47
|
|
|
if ($providers !== false) { |
48
|
|
|
return $providers; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $this->createCache(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
private function createCache(): array |
55
|
|
|
{ |
56
|
|
|
$packages = $this->packageManager->getActivePackages(); |
57
|
|
|
$providers = []; |
58
|
|
|
foreach ($packages as $package) { |
59
|
|
|
$packageConfiguration = $package->getPackagePath() . 'Configuration/ExpressionLanguage.php'; |
60
|
|
|
if (file_exists($packageConfiguration)) { |
61
|
|
|
$providersInPackage = require $packageConfiguration; |
62
|
|
|
if (is_array($providersInPackage)) { |
63
|
|
|
$providers[] = $providersInPackage; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
$providers = count($providers) > 0 ? array_merge_recursive(...$providers) : $providers; |
68
|
|
|
$this->cache->set($this->cacheIdentifier, 'return ' . var_export($providers, true) . ';'); |
69
|
|
|
return $providers; |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|