2 namespace TYPO3\CMS\Backend\Configuration
;
5 * This file is part of the TYPO3 CMS project.
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Core\Cache\CacheManager
;
18 use TYPO3\CMS\Core\Utility\GeneralUtility
;
21 * A TS-Config parsing class which performs condition evaluation
23 class TsConfigParser
extends \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
28 protected $rootLine = [];
31 * The uid of the page being handled
43 * Parses the passed TS-Config using conditions and caching
45 * @param string $TStext The TSConfig being parsed
46 * @param string $type The type of TSConfig (either "userTS" or "PAGES")
47 * @param int $id The uid of the page being handled
48 * @param array $rootLine The rootline of the page being handled
49 * @return array Array containing the parsed TSConfig and a flag whether the content was retrieved from cache
51 public function parseTSconfig($TStext, $type, $id = 0, array $rootLine = [])
55 $this->rootLine
= $rootLine;
56 $hash = md5($type . ':' . $TStext);
58 $cache = GeneralUtility
::makeInstance(CacheManager
::class)->getCache('cache_hash');
59 $cachedContent = $cache->get($hash);
60 if (is_array($cachedContent)) {
61 $storedData = $cachedContent[0];
62 $storedMD5 = $cachedContent[1];
63 $storedData['match'] = [];
64 $storedData = $this->matching($storedData);
65 $checkMD5 = md5(serialize($storedData));
66 if ($checkMD5 == $storedMD5) {
68 'TSconfig' => $storedData['TSconfig'],
73 $shash = md5($checkMD5 . $hash);
74 $cachedSpec = $cache->get($shash);
75 if (is_array($cachedSpec)) {
76 $storedData = $cachedSpec;
78 'TSconfig' => $storedData['TSconfig'],
83 $storeData = $this->parseWithConditions($TStext);
85 'TSconfig' => $storeData['TSconfig'],
89 $cache->set($shash, $storeData, ['ident_' . $type . '_TSconfig'], 0);
93 $storeData = $this->parseWithConditions($TStext);
94 $md5 = md5(serialize($storeData));
95 $cache->set($hash, [$storeData, $md5], ['ident_' . $type . '_TSconfig'], 0);
97 'TSconfig' => $storeData['TSconfig'],
106 * Does the actual parsing using the parent objects "parse" method. Creates the match-Object
108 * @param string $TSconfig The TSConfig being parsed
109 * @return array Array containing the parsed TSConfig, the encountered sectiosn, the matched sections
111 protected function parseWithConditions($TSconfig)
113 /** @var $matchObj \TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher */
114 $matchObj = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance(\TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher
::class);
115 $matchObj->setRootline($this->rootLine
);
116 $matchObj->setPageId($this->id
);
117 $this->parse($TSconfig, $matchObj);
119 'TSconfig' => $this->setup
,
120 'sections' => $this->sections
,
121 'match' => $this->sectionsMatch
126 * Is just going through an array of conditions to determine which are matching (for getting correct cache entry)
128 * @param array $cc An array containing the sections to match
129 * @return array The input array with matching sections filled into the "match" key
131 protected function matching(array $cc)
133 if (is_array($cc['sections'])) {
134 /** @var $matchObj \TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher */
135 $matchObj = \TYPO3\CMS\Core\Utility\GeneralUtility
::makeInstance(\TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher
::class);
136 $matchObj->setRootline($this->rootLine
);
137 $matchObj->setPageId($this->id
);
138 foreach ($cc['sections'] as $key => $pre) {
139 if ($matchObj->match($pre)) {
140 $cc['match'][$key] = $pre;