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