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\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 $contentObjectTable; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var int |
38
|
|
|
*/ |
39
|
|
|
protected $contentObjectUid; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* The given argument must be a string, hashed with the hash service, and |
43
|
|
|
* must contain an instance of this class. The data will be fetched from the |
44
|
|
|
* instance, and injected in the actual class. |
45
|
|
|
* |
46
|
|
|
* @param string $hash |
47
|
|
|
*/ |
48
|
|
|
public function fillFromHash($hash) |
49
|
|
|
{ |
50
|
|
|
/** @var FormObjectRequestData $requestData */ |
51
|
|
|
$requestData = $this->hashService->validateAndStripHmac($hash); |
52
|
|
|
$requestData = unserialize(base64_decode($requestData)); |
53
|
|
|
|
54
|
|
|
foreach ($requestData as $key => $value) { |
55
|
|
|
$this->$key = $value; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $key |
61
|
|
|
* @param mixed $value |
62
|
|
|
*/ |
63
|
|
|
public function addData($key, $value) |
64
|
|
|
{ |
65
|
|
|
$this->data[$key] = $value; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return array |
70
|
|
|
*/ |
71
|
|
|
public function getData() |
72
|
|
|
{ |
73
|
|
|
return $this->data; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param string $key |
78
|
|
|
* @return bool |
79
|
|
|
*/ |
80
|
|
|
public function hasData($key) |
81
|
|
|
{ |
82
|
|
|
return true === isset($this->data[$key]); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param string $key |
87
|
|
|
* @return mixed |
88
|
|
|
* @throws EntryNotFoundException |
89
|
|
|
*/ |
90
|
|
|
public function getDataValue($key) |
91
|
|
|
{ |
92
|
|
|
if (false === $this->hasData($key)) { |
93
|
|
|
throw EntryNotFoundException::formRequestDataNotFound($key); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $this->data[$key]; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public function getContentObjectTable() |
103
|
|
|
{ |
104
|
|
|
return $this->contentObjectTable; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param string $contentObjectTable |
109
|
|
|
*/ |
110
|
|
|
public function setContentObjectTable($contentObjectTable) |
111
|
|
|
{ |
112
|
|
|
$this->contentObjectTable = $contentObjectTable; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return int |
117
|
|
|
*/ |
118
|
|
|
public function getContentObjectUid() |
119
|
|
|
{ |
120
|
|
|
return (int)$this->contentObjectUid; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param int $contentObjectUid |
125
|
|
|
*/ |
126
|
|
|
public function setContentObjectUid($contentObjectUid) |
127
|
|
|
{ |
128
|
|
|
$this->contentObjectUid = (int)$contentObjectUid; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param HashService $hashService |
133
|
|
|
*/ |
134
|
|
|
public function injectHashService(HashService $hashService) |
135
|
|
|
{ |
136
|
|
|
$this->hashService = $hashService; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return array |
141
|
|
|
*/ |
142
|
|
|
public function toArray() |
143
|
|
|
{ |
144
|
|
|
$result = []; |
145
|
|
|
|
146
|
|
|
$properties = get_object_vars($this); |
147
|
|
|
unset($properties['hashService']); |
148
|
|
|
|
149
|
|
|
foreach (array_keys($properties) as $propertyName) { |
150
|
|
|
$result[$propertyName] = $this->$propertyName; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
return $result; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|