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\Core\Core; |
17
|
|
|
use Romm\Formz\Domain\Model\FormMetadata; |
18
|
|
|
use Romm\Formz\Error\FormResult; |
19
|
|
|
use Romm\Formz\Form\FormInterface; |
20
|
|
|
use Romm\Formz\Form\FormObject\Service\FormObjectMetadata; |
21
|
|
|
use Romm\Formz\Form\FormObject\Service\FormObjectRequestData; |
22
|
|
|
use Romm\Formz\Service\HashService; |
23
|
|
|
|
24
|
|
|
class FormObjectProxy |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $name; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var FormObject |
33
|
|
|
*/ |
34
|
|
|
protected $formObject; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var FormInterface |
38
|
|
|
*/ |
39
|
|
|
protected $form; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var FormObjectRequestData |
43
|
|
|
*/ |
44
|
|
|
protected $requestData; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
protected $formHash; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var bool |
53
|
|
|
*/ |
54
|
|
|
protected $formWasSubmitted = false; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var FormResult |
58
|
|
|
*/ |
59
|
|
|
protected $formResult; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var FormObjectMetadata |
63
|
|
|
*/ |
64
|
|
|
protected $metadata; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param FormObject $formObject |
68
|
|
|
* @param FormInterface $form |
69
|
|
|
*/ |
70
|
|
|
public function __construct(FormObject $formObject, FormInterface $form) |
71
|
|
|
{ |
72
|
|
|
$this->formObject = $formObject; |
73
|
|
|
$this->form = $form; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @todo |
78
|
|
|
*/ |
79
|
|
|
public function initializeObject() |
80
|
|
|
{ |
81
|
|
|
$this->metadata = Core::instantiate(FormObjectMetadata::class, $this->formObject); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return FormObjectRequestData |
86
|
|
|
*/ |
87
|
|
|
public function getRequestData() |
88
|
|
|
{ |
89
|
|
|
return $this->requestData; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return FormInterface |
94
|
|
|
*/ |
95
|
|
|
public function getForm() |
96
|
|
|
{ |
97
|
|
|
return $this->form; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Will mark the form as submitted (change the result returned by the |
102
|
|
|
* function `formWasSubmitted()`). |
103
|
|
|
*/ |
104
|
|
|
public function markFormAsSubmitted() |
105
|
|
|
{ |
106
|
|
|
$this->formWasSubmitted = true; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Returns `true` if the form was submitted by the user. |
111
|
|
|
* |
112
|
|
|
* @return bool |
113
|
|
|
*/ |
114
|
|
|
public function formWasSubmitted() |
115
|
|
|
{ |
116
|
|
|
return $this->formWasSubmitted; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return FormResult |
121
|
|
|
*/ |
122
|
|
|
public function getFormResult() |
123
|
|
|
{ |
124
|
|
|
// @todo check has |
125
|
|
|
|
126
|
|
|
return $this->formResult; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @return bool |
131
|
|
|
*/ |
132
|
|
|
public function hasFormResult() |
133
|
|
|
{ |
134
|
|
|
return null !== $this->formResult; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param FormResult $formResult |
139
|
|
|
*/ |
140
|
|
|
public function setFormResult(FormResult $formResult) |
141
|
|
|
{ |
142
|
|
|
$this->formResult = $formResult; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return FormMetadata |
147
|
|
|
*/ |
148
|
|
|
public function getFormMetadata() |
149
|
|
|
{ |
150
|
|
|
return $this->metadata->getMetadata(); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @return string |
155
|
|
|
*/ |
156
|
|
|
public function getFormHash() |
157
|
|
|
{ |
158
|
|
|
if (null === $this->formHash) { |
159
|
|
|
$this->formHash = HashService::get()->getHash(uniqid(get_class($this->form))); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
return $this->formHash; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @param string $hash |
167
|
|
|
*/ |
168
|
|
|
public function setFormHash($hash) |
169
|
|
|
{ |
170
|
|
|
$this->formHash = $hash; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @param FormObjectRequestData $requestData |
175
|
|
|
*/ |
176
|
|
|
public function injectRequestData(FormObjectRequestData $requestData) |
177
|
|
|
{ |
178
|
|
|
$this->requestData = $requestData; |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|