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