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\Service; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\Exceptions\EntryNotFoundException; |
17
|
|
|
use TYPO3\CMS\Extbase\Security\Cryptography\HashService; |
18
|
|
|
|
19
|
|
|
class FormObjectRequestData |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var HashService |
23
|
|
|
*/ |
24
|
|
|
protected $hashService; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
protected $data = []; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $formHash; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $currentStepIdentifier; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
protected $contentObjectTable; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var int |
48
|
|
|
*/ |
49
|
|
|
protected $contentObjectUid; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* The given argument must be a string, hashed with the hash service, and |
53
|
|
|
* must contain an instance of this class. The data will be fetched from the |
54
|
|
|
* instance, and injected in the actual class. |
55
|
|
|
* |
56
|
|
|
* @param string $hash |
57
|
|
|
*/ |
58
|
|
|
public function fillFromHash($hash) |
59
|
|
|
{ |
60
|
|
|
/** @var FormObjectRequestData $requestData */ |
61
|
|
|
$requestData = $this->hashService->validateAndStripHmac($hash); |
62
|
|
|
$requestData = unserialize(base64_decode($requestData)); |
63
|
|
|
|
64
|
|
|
foreach ($requestData as $key => $value) { |
65
|
|
|
$this->$key = $value; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param string $key |
71
|
|
|
* @param mixed $value |
72
|
|
|
*/ |
73
|
|
|
public function addData($key, $value) |
74
|
|
|
{ |
75
|
|
|
$this->data[$key] = $value; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
|
public function getData() |
82
|
|
|
{ |
83
|
|
|
return $this->data; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param string $key |
88
|
|
|
* @return bool |
89
|
|
|
*/ |
90
|
|
|
public function hasData($key) |
91
|
|
|
{ |
92
|
|
|
return true === isset($this->data[$key]); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param string $key |
97
|
|
|
* @return mixed |
98
|
|
|
* @throws EntryNotFoundException |
99
|
|
|
*/ |
100
|
|
|
public function getDataValue($key) |
101
|
|
|
{ |
102
|
|
|
if (false === $this->hasData($key)) { |
103
|
|
|
throw EntryNotFoundException::formRequestDataNotFound($key); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $this->data[$key]; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
public function getFormHash() |
113
|
|
|
{ |
114
|
|
|
return $this->formHash; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param string $formHash |
119
|
|
|
*/ |
120
|
|
|
public function setFormHash($formHash) |
121
|
|
|
{ |
122
|
|
|
$this->formHash = $formHash; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
|
|
public function getCurrentStepIdentifier() |
129
|
|
|
{ |
130
|
|
|
return $this->currentStepIdentifier; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param string $currentStepIdentifier |
135
|
|
|
*/ |
136
|
|
|
public function setCurrentStepIdentifier($currentStepIdentifier) |
137
|
|
|
{ |
138
|
|
|
$this->currentStepIdentifier = $currentStepIdentifier; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return string |
143
|
|
|
*/ |
144
|
|
|
public function getContentObjectTable() |
145
|
|
|
{ |
146
|
|
|
return $this->contentObjectTable; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param string $contentObjectTable |
151
|
|
|
*/ |
152
|
|
|
public function setContentObjectTable($contentObjectTable) |
153
|
|
|
{ |
154
|
|
|
$this->contentObjectTable = $contentObjectTable; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return int |
159
|
|
|
*/ |
160
|
|
|
public function getContentObjectUid() |
161
|
|
|
{ |
162
|
|
|
return (int)$this->contentObjectUid; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @param int $contentObjectUid |
167
|
|
|
*/ |
168
|
|
|
public function setContentObjectUid($contentObjectUid) |
169
|
|
|
{ |
170
|
|
|
$this->contentObjectUid = (int)$contentObjectUid; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @param HashService $hashService |
175
|
|
|
*/ |
176
|
|
|
public function injectHashService(HashService $hashService) |
177
|
|
|
{ |
178
|
|
|
$this->hashService = $hashService; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @return array |
183
|
|
|
*/ |
184
|
|
|
public function toArray() |
185
|
|
|
{ |
186
|
|
|
$result = []; |
187
|
|
|
|
188
|
|
|
$properties = get_object_vars($this); |
189
|
|
|
unset($properties['hashService']); |
190
|
|
|
|
191
|
|
|
foreach (array_keys($properties) as $propertyName) { |
192
|
|
|
$result[$propertyName] = $this->$propertyName; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
return $result; |
196
|
|
|
} |
197
|
|
|
} |
198
|
|
|
|