1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* 2016 Romain CANON <[email protected]> |
4
|
|
|
* |
5
|
|
|
* This file is part of the TYPO3 Formz project. |
6
|
|
|
* It is free software; you can redistribute it and/or modify it |
7
|
|
|
* under the terms of the GNU General Public License, either |
8
|
|
|
* version 3 of the License, or any later version. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, see: |
11
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Romm\Formz\Configuration; |
15
|
|
|
|
16
|
|
|
use Romm\ConfigurationObject\Service\Items\Cache\CacheService; |
17
|
|
|
use Romm\ConfigurationObject\Service\ServiceFactory; |
18
|
|
|
use Romm\ConfigurationObject\Service\ServiceInterface; |
19
|
|
|
use Romm\Formz\Core\Core; |
20
|
|
|
use TYPO3\CMS\Core\Cache\Backend\AbstractBackend; |
21
|
|
|
use TYPO3\CMS\Core\SingletonInterface; |
22
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
23
|
|
|
|
24
|
|
|
class ConfigurationServicesUtility implements SingletonInterface |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var ConfigurationServicesUtility |
29
|
|
|
*/ |
30
|
|
|
protected static $instance; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $backendCache; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Returns an instance of this class. |
39
|
|
|
* |
40
|
|
|
* @return ConfigurationServicesUtility |
41
|
|
|
*/ |
42
|
|
|
public static function getInstance() |
43
|
|
|
{ |
44
|
|
|
if (null === self::$instance) { |
45
|
|
|
self::$instance = GeneralUtility::makeInstance(self::class); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return self::$instance; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Will add the cache service configured with the TypoScript backend cache |
53
|
|
|
* type parameter. |
54
|
|
|
* |
55
|
|
|
* @param ServiceFactory $serviceFactory |
56
|
|
|
*/ |
57
|
|
|
public function addCacheServiceToServiceFactory(ServiceFactory $serviceFactory) |
58
|
|
|
{ |
59
|
|
|
$serviceFactory->attach(ServiceInterface::SERVICE_CACHE) |
60
|
|
|
->with(ServiceInterface::SERVICE_CACHE) |
61
|
|
|
->setOption(CacheService::OPTION_CACHE_BACKEND, $this->getBackendCache()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Returns the backend cache type configured in TypoScript at the path |
66
|
|
|
* `settings.defaultBackendCache`. |
67
|
|
|
* |
68
|
|
|
* @return string |
69
|
|
|
* @throws \Exception |
70
|
|
|
*/ |
71
|
|
|
protected function getBackendCache() |
72
|
|
|
{ |
73
|
|
|
if (null === $this->backendCache) { |
74
|
|
|
$backendCache = Core::getTypoScriptUtility() |
75
|
|
|
->getExtensionConfigurationFromPath('settings.defaultBackendCache'); |
76
|
|
|
|
77
|
|
|
if (false === class_exists($backendCache) |
78
|
|
|
&& false === in_array(AbstractBackend::class, class_parents($backendCache)) |
79
|
|
|
) { |
80
|
|
|
throw new \Exception( |
81
|
|
|
'The cache class name given in configuration "config.tx_formz.settings.defaultBackendCache" must inherit "' . AbstractBackend::class . '" (current value: "' . (string)$backendCache . '")', |
82
|
|
|
1459251263 |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $this->backendCache; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|