TYPO3 CMS  TYPO3_7-6
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 
45  public function parseTSconfig($TStext, $type, $id = 0, array $rootLine = [])
46  {
47  $this->type = $type;
48  $this->id = $id;
49  $this->rootLine = $rootLine;
50  $hash = md5($type . ':' . $TStext);
51  $cachedContent = BackendUtility::getHash($hash);
52  if (is_array($cachedContent)) {
53  $storedData = $cachedContent[0];
54  $storedMD5 = $cachedContent[1];
55  $storedData['match'] = [];
56  $storedData = $this->matching($storedData);
57  $checkMD5 = md5(serialize($storedData));
58  if ($checkMD5 == $storedMD5) {
59  $res = [
60  'TSconfig' => $storedData['TSconfig'],
61  'cached' => 1,
62  'hash' => $hash
63  ];
64  } else {
65  $shash = md5($checkMD5 . $hash);
66  $cachedSpec = BackendUtility::getHash($shash);
67  if (is_array($cachedSpec)) {
68  $storedData = $cachedSpec;
69  $res = [
70  'TSconfig' => $storedData['TSconfig'],
71  'cached' => 1,
72  'hash' => $shash
73  ];
74  } else {
75  $storeData = $this->parseWithConditions($TStext);
76  BackendUtility::storeHash($shash, $storeData, $type . '_TSconfig');
77  $res = [
78  'TSconfig' => $storeData['TSconfig'],
79  'cached' => 0,
80  'hash' => $shash
81  ];
82  }
83  }
84  } else {
85  $storeData = $this->parseWithConditions($TStext);
86  $md5 = md5(serialize($storeData));
87  BackendUtility::storeHash($hash, [$storeData, $md5], $type . '_TSconfig');
88  $res = [
89  'TSconfig' => $storeData['TSconfig'],
90  'cached' => 0,
91  'hash' => $hash
92  ];
93  }
94  return $res;
95  }
96 
103  protected function parseWithConditions($TSconfig)
104  {
106  $matchObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher::class);
107  $matchObj->setRootline($this->rootLine);
108  $matchObj->setPageId($this->id);
109  $this->parse($TSconfig, $matchObj);
110  return [
111  'TSconfig' => $this->setup,
112  'sections' => $this->sections,
113  'match' => $this->sectionsMatch
114  ];
115  }
116 
123  protected function matching(array $cc)
124  {
125  if (is_array($cc['sections'])) {
127  $matchObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Configuration\TypoScript\ConditionMatching\ConditionMatcher::class);
128  $matchObj->setRootline($this->rootLine);
129  $matchObj->setPageId($this->id);
130  foreach ($cc['sections'] as $key => $pre) {
131  if ($matchObj->match($pre)) {
132  $cc['match'][$key] = $pre;
133  }
134  }
135  }
136  return $cc;
137  }
138 }
parseTSconfig($TStext, $type, $id=0, array $rootLine=[])