TYPO3 CMS  TYPO3_8-7
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 
18 
23 {
27  protected $rootLine = [];
28 
34  public $id;
35 
39  public $type;
40 
50  public function parseTSconfig($TStext, $type, $id = 0, array $rootLine = [])
51  {
52  $this->type = $type;
53  $this->id = $id;
54  $this->rootLine = $rootLine;
55  $hash = md5($type . ':' . $TStext);
56  $cachedContent = BackendUtility::getHash($hash);
57  if (is_array($cachedContent)) {
58  $storedData = $cachedContent[0];
59  $storedMD5 = $cachedContent[1];
60  $storedData['match'] = [];
61  $storedData = $this->matching($storedData);
62  $checkMD5 = md5(serialize($storedData));
63  if ($checkMD5 == $storedMD5) {
64  $res = [
65  'TSconfig' => $storedData['TSconfig'],
66  'cached' => 1,
67  'hash' => $hash
68  ];
69  } else {
70  $shash = md5($checkMD5 . $hash);
71  $cachedSpec = BackendUtility::getHash($shash);
72  if (is_array($cachedSpec)) {
73  $storedData = $cachedSpec;
74  $res = [
75  'TSconfig' => $storedData['TSconfig'],
76  'cached' => 1,
77  'hash' => $shash
78  ];
79  } else {
80  $storeData = $this->parseWithConditions($TStext);
81  BackendUtility::storeHash($shash, $storeData, $type . '_TSconfig');
82  $res = [
83  'TSconfig' => $storeData['TSconfig'],
84  'cached' => 0,
85  'hash' => $shash
86  ];
87  }
88  }
89  } else {
90  $storeData = $this->parseWithConditions($TStext);
91  $md5 = md5(serialize($storeData));
92  BackendUtility::storeHash($hash, [$storeData, $md5], $type . '_TSconfig');
93  $res = [
94  'TSconfig' => $storeData['TSconfig'],
95  'cached' => 0,
96  'hash' => $hash
97  ];
98  }
99  return $res;
100  }
101 
108  protected function parseWithConditions($TSconfig)
109  {
111  $matchObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher::class);
112  $matchObj->setRootline($this->rootLine);
113  $matchObj->setPageId($this->id);
114  $this->parse($TSconfig, $matchObj);
115  return [
116  'TSconfig' => $this->setup,
117  'sections' => $this->sections,
118  'match' => $this->sectionsMatch
119  ];
120  }
121 
128  protected function matching(array $cc)
129  {
130  if (is_array($cc['sections'])) {
132  $matchObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher::class);
133  $matchObj->setRootline($this->rootLine);
134  $matchObj->setPageId($this->id);
135  foreach ($cc['sections'] as $key => $pre) {
136  if ($matchObj->match($pre)) {
137  $cc['match'][$key] = $pre;
138  }
139  }
140  }
141  return $cc;
142  }
143 }
parseTSconfig($TStext, $type, $id=0, array $rootLine=[])
static makeInstance($className,... $constructorArguments)