‪TYPO3CMS  10.4
TsConfigParser.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 
29 {
33  protected ‪$rootLine = [];
34 
40  public ‪$id;
41 
45  public ‪$type;
46 
47  public function ‪__construct()
48  {
49  trigger_error(__CLASS__ . ' has been superseded by PageTsConfigParser. This class will be removed in TYPO3 v11.0', E_USER_DEPRECATED);
50  }
51 
61  public function ‪parseTSconfig($TStext, ‪$type, ‪$id = 0, array ‪$rootLine = [])
62  {
63  $this->type = ‪$type;
64  $this->id = ‪$id;
65  $this->rootLine = ‪$rootLine;
66  $hash = md5(‪$type . ':' . $TStext);
67 
68  $cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('hash');
69  $cachedContent = $cache->get($hash);
70  if (is_array($cachedContent)) {
71  $storedData = $cachedContent[0];
72  $storedMD5 = $cachedContent[1];
73  $storedData['match'] = [];
74  $storedData = $this->‪matching($storedData);
75  $checkMD5 = md5(serialize($storedData));
76  if ($checkMD5 == $storedMD5) {
77  $res = [
78  'TSconfig' => $storedData['TSconfig'],
79  'cached' => 1,
80  'hash' => $hash
81  ];
82  } else {
83  $shash = md5($checkMD5 . $hash);
84  $cachedSpec = $cache->get($shash);
85  if (is_array($cachedSpec)) {
86  $storedData = $cachedSpec;
87  $res = [
88  'TSconfig' => $storedData['TSconfig'],
89  'cached' => 1,
90  'hash' => $shash
91  ];
92  } else {
93  $storeData = $this->‪parseWithConditions($TStext);
94  $res = [
95  'TSconfig' => $storeData['TSconfig'],
96  'cached' => 0,
97  'hash' => $shash
98  ];
99  $cache->set($shash, $storeData, ['ident_' . ‪$type . '_TSconfig'], 0);
100  }
101  }
102  } else {
103  $storeData = $this->‪parseWithConditions($TStext);
104  $md5 = md5(serialize($storeData));
105  $cache->set($hash, [$storeData, $md5], ['ident_' . ‪$type . '_TSconfig'], 0);
106  $res = [
107  'TSconfig' => $storeData['TSconfig'],
108  'cached' => 0,
109  'hash' => $hash
110  ];
111  }
112  return $res;
113  }
114 
121  protected function ‪parseWithConditions($TSconfig)
122  {
124  $matchObj = GeneralUtility::makeInstance(ConditionMatcher::class);
125  $matchObj->setRootline($this->rootLine);
126  $matchObj->setPageId($this->id);
127  $this->‪parse($TSconfig, $matchObj);
128  return [
129  'TSconfig' => ‪$this->setup,
130  'sections' => ‪$this->sections,
131  'match' => ‪$this->sectionsMatch
132  ];
133  }
134 
141  protected function ‪matching(array $cc)
142  {
143  if (is_array($cc['sections'])) {
145  $matchObj = GeneralUtility::makeInstance(ConditionMatcher::class);
146  $matchObj->setRootline($this->rootLine);
147  $matchObj->setPageId($this->id);
148  foreach ($cc['sections'] as $key => $pre) {
149  if ($matchObj->match($pre)) {
150  $cc['match'][$key] = $pre;
151  }
152  }
153  }
154  return $cc;
155  }
156 }
‪TYPO3\CMS\Backend\Configuration\TsConfigParser\$rootLine
‪array $rootLine
Definition: TsConfigParser.php:32
‪TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser
Definition: TypoScriptParser.php:37
‪TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\$sections
‪array $sections
Definition: TypoScriptParser.php:103
‪TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher
Definition: ConditionMatcher.php:30
‪TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\$sectionsMatch
‪array $sectionsMatch
Definition: TypoScriptParser.php:109
‪TYPO3\CMS\Backend\Configuration\TsConfigParser\$id
‪int $id
Definition: TsConfigParser.php:38
‪TYPO3\CMS\Backend\Configuration\TsConfigParser\parseTSconfig
‪array parseTSconfig($TStext, $type, $id=0, array $rootLine=[])
Definition: TsConfigParser.php:58
‪TYPO3\CMS\Backend\Configuration\TsConfigParser\matching
‪array matching(array $cc)
Definition: TsConfigParser.php:138
‪TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\$setup
‪array $setup
Definition: TypoScriptParser.php:42
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\Backend\Configuration
Definition: BackendUserConfiguration.php:18
‪TYPO3\CMS\Backend\Configuration\TsConfigParser\__construct
‪__construct()
Definition: TsConfigParser.php:44
‪TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser\parse
‪parse($string, $matchObj='')
Definition: TypoScriptParser.php:213
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Configuration\TsConfigParser
Definition: TsConfigParser.php:29
‪TYPO3\CMS\Backend\Configuration\TsConfigParser\$type
‪string $type
Definition: TsConfigParser.php:42
‪TYPO3\CMS\Backend\Configuration\TsConfigParser\parseWithConditions
‪array parseWithConditions($TSconfig)
Definition: TsConfigParser.php:118