‪TYPO3CMS  9.5
TsConfigParser.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
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.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 
24 {
28  protected ‪$rootLine = [];
29 
35  public ‪$id;
36 
40  public ‪$type;
41 
51  public function ‪parseTSconfig($TStext, ‪$type, ‪$id = 0, array ‪$rootLine = [])
52  {
53  $this->type = ‪$type;
54  $this->id = ‪$id;
55  $this->rootLine = ‪$rootLine;
56  $hash = md5(‪$type . ':' . $TStext);
57 
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) {
67  $res = [
68  'TSconfig' => $storedData['TSconfig'],
69  'cached' => 1,
70  'hash' => $hash
71  ];
72  } else {
73  $shash = md5($checkMD5 . $hash);
74  $cachedSpec = $cache->get($shash);
75  if (is_array($cachedSpec)) {
76  $storedData = $cachedSpec;
77  $res = [
78  'TSconfig' => $storedData['TSconfig'],
79  'cached' => 1,
80  'hash' => $shash
81  ];
82  } else {
83  $storeData = $this->‪parseWithConditions($TStext);
84  $res = [
85  'TSconfig' => $storeData['TSconfig'],
86  'cached' => 0,
87  'hash' => $shash
88  ];
89  $cache->set($shash, $storeData, ['ident_' . ‪$type . '_TSconfig'], 0);
90  }
91  }
92  } else {
93  $storeData = $this->‪parseWithConditions($TStext);
94  $md5 = md5(serialize($storeData));
95  $cache->set($hash, [$storeData, $md5], ['ident_' . ‪$type . '_TSconfig'], 0);
96  $res = [
97  'TSconfig' => $storeData['TSconfig'],
98  'cached' => 0,
99  'hash' => $hash
100  ];
101  }
102  return $res;
103  }
104 
111  protected function ‪parseWithConditions($TSconfig)
112  {
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);
118  return [
119  'TSconfig' => ‪$this->setup,
120  'sections' => ‪$this->sections,
121  'match' => ‪$this->sectionsMatch
122  ];
123  }
124 
131  protected function ‪matching(array $cc)
132  {
133  if (is_array($cc['sections'])) {
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;
141  }
142  }
143  }
144  return $cc;
145  }
146 }
‪TYPO3\CMS\Backend\Configuration\TsConfigParser\$rootLine
‪array $rootLine
Definition: TsConfigParser.php:27
‪TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
Definition: TypoScriptParser.php:37
‪TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\$sections
‪array $sections
Definition: TypoScriptParser.php:132
‪TYPO3
‪TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\$sectionsMatch
‪array $sectionsMatch
Definition: TypoScriptParser.php:138
‪TYPO3\CMS\Backend\Configuration\TsConfigParser\$id
‪int $id
Definition: TsConfigParser.php:33
‪TYPO3\CMS\Backend\Configuration\TsConfigParser\parseTSconfig
‪array parseTSconfig($TStext, $type, $id=0, array $rootLine=[])
Definition: TsConfigParser.php:48
‪TYPO3\CMS\Backend\Configuration\TsConfigParser\matching
‪array matching(array $cc)
Definition: TsConfigParser.php:128
‪TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\$setup
‪array $setup
Definition: TypoScriptParser.php:71
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Backend\Configuration
Definition: BackendUserConfiguration.php:3
‪TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\parse
‪parse($string, $matchObj='')
Definition: TypoScriptParser.php:242
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Configuration\TsConfigParser
Definition: TsConfigParser.php:24
‪TYPO3\CMS\Backend\Configuration\TsConfigParser\$type
‪string $type
Definition: TsConfigParser.php:37
‪TYPO3\CMS\Backend\Configuration\TsConfigParser\parseWithConditions
‪array parseWithConditions($TSconfig)
Definition: TsConfigParser.php:108