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\Service\FormObjectConfiguration; |
19
|
|
|
use Romm\Formz\Service\HashService; |
20
|
|
|
use TYPO3\CMS\Extbase\Error\Result; |
21
|
|
|
|
22
|
|
|
class FormObjectStatic |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $className; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The properties of the form. |
31
|
|
|
* |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
protected $properties = []; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var FormObjectConfiguration |
38
|
|
|
*/ |
39
|
|
|
protected $configuration; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $objectHash; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $className |
48
|
|
|
* @param array $configurationArray |
49
|
|
|
*/ |
50
|
|
|
public function __construct($className, array $configurationArray) |
51
|
|
|
{ |
52
|
|
|
$this->className = $className; |
53
|
|
|
|
54
|
|
|
$this->configuration = Core::instantiate(FormObjectConfiguration::class, $this, $configurationArray); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function getClassName() |
61
|
|
|
{ |
62
|
|
|
return $this->className; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
public function getProperties() |
69
|
|
|
{ |
70
|
|
|
return $this->properties; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param string $name |
75
|
|
|
* @return bool |
76
|
|
|
*/ |
77
|
|
|
public function hasProperty($name) |
78
|
|
|
{ |
79
|
|
|
return in_array($name, $this->properties); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Registers a new property for this form. |
84
|
|
|
* |
85
|
|
|
* @param string $name |
86
|
|
|
* @return $this |
87
|
|
|
*/ |
88
|
|
|
public function addProperty($name) |
89
|
|
|
{ |
90
|
|
|
if (false === $this->hasProperty($name)) { |
91
|
|
|
$this->properties[] = $name; |
92
|
|
|
$this->objectHash = null; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return Form |
100
|
|
|
*/ |
101
|
|
|
public function getConfiguration() |
102
|
|
|
{ |
103
|
|
|
/** @var Form $configuration */ |
104
|
|
|
$configuration = $this->configuration->getConfigurationObject()->getObject(true); |
105
|
|
|
|
106
|
|
|
return $configuration; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* This function will merge and return the validation results of both the |
111
|
|
|
* global FormZ configuration object, and this form configuration object. |
112
|
|
|
* |
113
|
|
|
* @return Result |
114
|
|
|
*/ |
115
|
|
|
public function getConfigurationValidationResult() |
116
|
|
|
{ |
117
|
|
|
return $this->configuration->getConfigurationValidationResult(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Returns the hash of the form object, which should be calculated only once |
122
|
|
|
* for performance concerns. |
123
|
|
|
* |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
public function getObjectHash() |
127
|
|
|
{ |
128
|
|
|
if (null === $this->objectHash) { |
129
|
|
|
$this->objectHash = $this->calculateObjectHash(); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
return $this->objectHash; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Returns the calculated hash of the form object. |
137
|
|
|
* |
138
|
|
|
* @return string |
139
|
|
|
*/ |
140
|
|
|
protected function calculateObjectHash() |
141
|
|
|
{ |
142
|
|
|
return HashService::get()->getHash(serialize($this)); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|