|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* 2017 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\ConfigurationObjectInterface; |
|
17
|
|
|
use Romm\ConfigurationObject\Service\Items\Cache\CacheService; |
|
18
|
|
|
use Romm\ConfigurationObject\Service\ServiceFactory; |
|
19
|
|
|
use Romm\ConfigurationObject\Service\ServiceInterface; |
|
20
|
|
|
use Romm\ConfigurationObject\Traits\ConfigurationObject\ArrayConversionTrait; |
|
21
|
|
|
use Romm\ConfigurationObject\Traits\ConfigurationObject\DefaultConfigurationObjectTrait; |
|
22
|
|
|
use Romm\Formz\Configuration\Settings\Settings; |
|
23
|
|
|
use Romm\Formz\Configuration\View\View; |
|
24
|
|
|
use Romm\Formz\Service\CacheService as InternalCacheService; |
|
25
|
|
|
use Romm\Formz\Service\HashService; |
|
26
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
27
|
|
|
|
|
28
|
|
|
class Configuration extends AbstractConfiguration implements ConfigurationObjectInterface |
|
29
|
|
|
{ |
|
30
|
|
|
use DefaultConfigurationObjectTrait; |
|
31
|
|
|
use ArrayConversionTrait; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var \Romm\Formz\Configuration\Settings\Settings |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $settings; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var \Romm\Formz\Configuration\View\View |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $view; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $hash; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var ConfigurationState |
|
50
|
|
|
*/ |
|
51
|
|
|
private $state; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Constructor. |
|
55
|
|
|
*/ |
|
56
|
|
|
public function __construct() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->settings = GeneralUtility::makeInstance(Settings::class); |
|
59
|
|
|
$this->settings->attachParent($this); |
|
60
|
|
|
|
|
61
|
|
|
$this->view = GeneralUtility::makeInstance(View::class); |
|
62
|
|
|
$this->view->attachParent($this); |
|
63
|
|
|
|
|
64
|
|
|
$this->state = GeneralUtility::makeInstance(ConfigurationState::class); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return Settings |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getSettings() |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->settings; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return View |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getView() |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->view; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Calculates a hash for this configuration, which can be used as a unique |
|
85
|
|
|
* identifier. It should be called once, before the configuration is put in |
|
86
|
|
|
* cache, so it is not needed to call it again after being fetched from |
|
87
|
|
|
* cache. |
|
88
|
|
|
*/ |
|
89
|
|
|
public function calculateHash() |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->hash = HashService::get()->getHash(serialize($this)); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getHash() |
|
98
|
|
|
{ |
|
99
|
|
|
if (null === $this->hash) { |
|
100
|
|
|
$this->hash = $this->calculateHash(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return $this->hash; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return ConfigurationState |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getState() |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->state; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Will initialize correctly the configuration object settings. |
|
116
|
|
|
* |
|
117
|
|
|
* @return ServiceFactory |
|
118
|
|
|
*/ |
|
119
|
|
|
public static function getConfigurationObjectServices() |
|
120
|
|
|
{ |
|
121
|
|
|
return ServiceFactory::getInstance() |
|
122
|
|
|
->attach(ServiceInterface::SERVICE_CACHE) |
|
123
|
|
|
->with(ServiceInterface::SERVICE_CACHE) |
|
124
|
|
|
->setOption(CacheService::OPTION_CACHE_NAME, InternalCacheService::CONFIGURATION_OBJECT_CACHE_IDENTIFIER) |
|
125
|
|
|
->setOption(CacheService::OPTION_CACHE_BACKEND, InternalCacheService::get()->getBackendCache()) |
|
126
|
|
|
->attach(ServiceInterface::SERVICE_PARENTS) |
|
127
|
|
|
->attach(ServiceInterface::SERVICE_DATA_PRE_PROCESSOR) |
|
128
|
|
|
->attach(ServiceInterface::SERVICE_MIXED_TYPES); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|