|
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\Form\FormObject; |
|
15
|
|
|
|
|
16
|
|
|
use Romm\Formz\Configuration\Form\Form; |
|
17
|
|
|
use Romm\Formz\Core\Core; |
|
18
|
|
|
use Romm\Formz\Form\FormObject\Configuration\FormConfiguration; |
|
19
|
|
|
use Romm\Formz\Form\FormObject\Service\FormObjectConfiguration; |
|
20
|
|
|
use Romm\Formz\Service\HashService; |
|
21
|
|
|
use TYPO3\CMS\Extbase\Error\Result; |
|
22
|
|
|
|
|
23
|
|
|
class FormObjectStatic |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $className; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var FormConfiguration |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $configuration; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $objectHash; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var FormObjectConfiguration |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $configurationService; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param string $className |
|
47
|
|
|
* @param FormConfiguration $configuration |
|
48
|
|
|
*/ |
|
49
|
|
|
public function __construct($className, FormConfiguration $configuration) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->className = $className; |
|
52
|
|
|
$this->configuration = $configuration; |
|
53
|
|
|
$this->configurationService = Core::instantiate(FormObjectConfiguration::class, $this, $configuration); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return string |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getClassName() |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->className; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @return Form |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getConfigurationService() |
|
68
|
|
|
{ |
|
69
|
|
|
/** @var Form $configuration */ |
|
70
|
|
|
$configuration = $this->configuration->getObject(true); |
|
71
|
|
|
|
|
72
|
|
|
return $configuration; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* This function will merge and return the validation results of both the |
|
77
|
|
|
* global FormZ configuration object, and this form configuration object. |
|
78
|
|
|
* |
|
79
|
|
|
* @return Result |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getConfigurationValidationResult() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->configurationService->getConfigurationValidationResult(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Returns the hash of the form object, which should be calculated only once |
|
88
|
|
|
* for performance concerns. |
|
89
|
|
|
* |
|
90
|
|
|
* @return string |
|
91
|
|
|
*/ |
|
92
|
|
|
public function getObjectHash() |
|
93
|
|
|
{ |
|
94
|
|
|
if (null === $this->objectHash) { |
|
95
|
|
|
$this->objectHash = $this->calculateObjectHash(); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $this->objectHash; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Returns the calculated hash of the form object. |
|
103
|
|
|
* |
|
104
|
|
|
* @return string |
|
105
|
|
|
*/ |
|
106
|
|
|
protected function calculateObjectHash() |
|
107
|
|
|
{ |
|
108
|
|
|
return HashService::get()->getHash(serialize($this)); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|