1
|
|
|
<?php |
2
|
|
|
namespace Aoe\Asdis\System\Configuration; |
3
|
|
|
|
4
|
|
|
use Aoe\Asdis\System\Configuration\Exception\InvalidTypoScriptSetting; |
5
|
|
|
use Aoe\Asdis\System\Configuration\Exception\TypoScriptSettingNotExists; |
6
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
7
|
|
|
use TYPO3\CMS\Core\TypoScript\TemplateService; |
8
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
9
|
|
|
use TYPO3\CMS\Core\Utility\RootlineUtility; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* TypoScript configuration provider. |
13
|
|
|
*/ |
14
|
|
|
class TypoScriptConfiguration implements SingletonInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
private $configuration; |
|
|
|
|
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
private $configurationCache = []; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param string $key The setting key. E.g. "logger.severity" |
28
|
|
|
* @param string $validateType The data type to be validated against (E.g. "string"). Empty string to skip validation. |
29
|
|
|
* @param boolean $hasSubkeys Tells whether the requested key is assumed to has subkeys. |
30
|
|
|
* @return mixed |
31
|
|
|
* @throws \Aoe\Asdis\System\Configuration\Exception\InvalidTypoScriptSetting |
32
|
|
|
* @throws \Aoe\Asdis\System\Configuration\Exception\TypoScriptSettingNotExists |
33
|
|
|
*/ |
34
|
2 |
|
public function getSetting($key, $validateType = '', $hasSubkeys = false) |
35
|
|
|
{ |
36
|
2 |
|
if (isset($this->configurationCache[$key])) { |
37
|
|
|
return $this->configurationCache[$key]; |
38
|
|
|
} |
39
|
2 |
|
$parts = explode('.', $key); |
40
|
2 |
|
if (false === is_array($parts) || sizeof($parts) < 1) { |
41
|
|
|
throw new TypoScriptSettingNotExists($key, 1372050700894); |
42
|
|
|
} |
43
|
2 |
|
$conf = $this->getTypoScriptConfigurationArray(); |
44
|
2 |
|
$lastPartIndex = sizeof($parts) - 1; |
45
|
2 |
|
foreach($parts as $index => $part) { |
46
|
2 |
|
$subkey = $part; |
47
|
2 |
|
if ($lastPartIndex !== $index || $hasSubkeys) { |
48
|
1 |
|
$subkey .= '.'; |
49
|
|
|
} |
50
|
2 |
|
if (false === isset($conf[$subkey])) { |
51
|
1 |
|
throw new TypoScriptSettingNotExists($key, 1372063884313); |
52
|
|
|
} |
53
|
1 |
|
$conf = $conf[$subkey]; |
54
|
1 |
|
if ($lastPartIndex === $index) { |
55
|
1 |
|
break; |
56
|
|
|
} |
57
|
|
|
} |
58
|
1 |
|
if (strlen($validateType) > 0 && strcmp($validateType, gettype($conf)) !== 0) { |
59
|
1 |
|
throw new InvalidTypoScriptSetting($key, gettype($conf), 1372064668444); |
60
|
|
|
} |
61
|
|
|
$this->configurationCache[$key] = $conf; |
62
|
|
|
return $conf; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
protected function getTypoScriptConfigurationArray() |
69
|
|
|
{ |
70
|
|
|
if (true === version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '9.5.0', '<')) { |
71
|
|
|
return $GLOBALS['TSFE']->tmpl->setup['config.']['tx_asdis.']; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** @var Site $site */ |
75
|
|
|
$site = $GLOBALS['TYPO3_REQUEST']->getAttribute('site'); |
76
|
|
|
/** @var RootlineUtility $rootlineUtility */ |
77
|
|
|
$rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $site->getRootPageId()); |
78
|
|
|
$rootline = $rootlineUtility->get(); |
79
|
|
|
/** @var TemplateService $templateService */ |
80
|
|
|
$templateService = GeneralUtility::makeInstance(TemplateService::class); |
81
|
|
|
$templateService->tt_track = 0; |
|
|
|
|
82
|
|
|
$templateService->runThroughTemplates($rootline); |
83
|
|
|
$templateService->generateConfig(); |
84
|
|
|
|
85
|
|
|
return $templateService->setup['config.']['tx_asdis.']; |
86
|
|
|
} |
87
|
|
|
} |