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 bool |
58
|
|
|
*/ |
59
|
|
|
protected $formWasValidated = false; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var FormResult |
63
|
|
|
*/ |
64
|
|
|
protected $formResult; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var FormObjectMetadata |
68
|
|
|
*/ |
69
|
|
|
protected $metadata; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param FormObject $formObject |
73
|
|
|
* @param FormInterface $form |
74
|
|
|
*/ |
75
|
|
|
public function __construct(FormObject $formObject, FormInterface $form) |
76
|
|
|
{ |
77
|
|
|
$this->formObject = $formObject; |
78
|
|
|
$this->form = $form; |
79
|
|
|
|
80
|
|
|
$this->metadata = Core::instantiate(FormObjectMetadata::class, $this->formObject); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return FormObjectRequestData |
85
|
|
|
*/ |
86
|
|
|
public function getRequestData() |
87
|
|
|
{ |
88
|
|
|
return $this->requestData; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return FormInterface |
93
|
|
|
*/ |
94
|
|
|
public function getForm() |
95
|
|
|
{ |
96
|
|
|
return $this->form; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Will mark the form as submitted (change the result returned by the |
101
|
|
|
* function `formWasSubmitted()`). |
102
|
|
|
*/ |
103
|
|
|
public function markFormAsSubmitted() |
104
|
|
|
{ |
105
|
|
|
$this->formWasSubmitted = true; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Returns `true` if the form was submitted by the user. |
110
|
|
|
* |
111
|
|
|
* @return bool |
112
|
|
|
*/ |
113
|
|
|
public function formWasSubmitted() |
114
|
|
|
{ |
115
|
|
|
return $this->formWasSubmitted; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Marks the form as validated. |
120
|
|
|
*/ |
121
|
|
|
public function markFormAsValidated() |
122
|
|
|
{ |
123
|
|
|
$this->formWasValidated = true; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return bool |
128
|
|
|
*/ |
129
|
|
|
public function formWasValidated() |
130
|
|
|
{ |
131
|
|
|
return $this->formWasValidated; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return FormResult |
136
|
|
|
*/ |
137
|
|
|
public function getFormResult() |
138
|
|
|
{ |
139
|
|
|
if (null === $this->formResult) { |
140
|
|
|
$this->formResult = new FormResult; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
return $this->formResult; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return FormMetadata |
148
|
|
|
*/ |
149
|
|
|
public function getFormMetadata() |
150
|
|
|
{ |
151
|
|
|
return $this->metadata->getMetadata(); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return string |
156
|
|
|
*/ |
157
|
|
|
public function getFormHash() |
158
|
|
|
{ |
159
|
|
|
if (null === $this->formHash) { |
160
|
|
|
$this->formHash = HashService::get()->getHash(uniqid(get_class($this->form))); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
return $this->formHash; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param string $hash |
168
|
|
|
*/ |
169
|
|
|
public function setFormHash($hash) |
170
|
|
|
{ |
171
|
|
|
$this->formHash = $hash; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @param FormObjectRequestData $requestData |
176
|
|
|
*/ |
177
|
|
|
public function injectRequestData(FormObjectRequestData $requestData) |
178
|
|
|
{ |
179
|
|
|
$this->requestData = $requestData; |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|