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\Error\FormResult; |
17
|
|
|
use Romm\Formz\Form\FormInterface; |
18
|
|
|
use Romm\Formz\Service\HashService; |
19
|
|
|
|
20
|
|
|
class FormObjectProxy |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var FormObject |
24
|
|
|
*/ |
25
|
|
|
protected $formObject; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var FormInterface |
29
|
|
|
*/ |
30
|
|
|
protected $form; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $formHash; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var bool |
39
|
|
|
*/ |
40
|
|
|
protected $formWasSubmitted = false; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var bool |
44
|
|
|
*/ |
45
|
|
|
protected $formWasValidated = false; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var FormResult |
49
|
|
|
*/ |
50
|
|
|
protected $formResult; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param FormObject $formObject |
54
|
|
|
* @param FormInterface $form |
55
|
|
|
*/ |
56
|
|
|
public function __construct(FormObject $formObject, FormInterface $form) |
57
|
|
|
{ |
58
|
|
|
$this->formObject = $formObject; |
59
|
|
|
$this->form = $form; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return FormInterface |
64
|
|
|
*/ |
65
|
|
|
public function getForm() |
66
|
|
|
{ |
67
|
|
|
return $this->form; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Will mark the form as submitted (change the result returned by the |
72
|
|
|
* function `formWasSubmitted()`). |
73
|
|
|
*/ |
74
|
|
|
public function markFormAsSubmitted() |
75
|
|
|
{ |
76
|
|
|
$this->formWasSubmitted = true; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Returns `true` if the form was submitted by the user. |
81
|
|
|
* |
82
|
|
|
* @return bool |
83
|
|
|
*/ |
84
|
|
|
public function formWasSubmitted() |
85
|
|
|
{ |
86
|
|
|
return $this->formWasSubmitted; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Marks the form as validated. |
91
|
|
|
*/ |
92
|
|
|
public function markFormAsValidated() |
93
|
|
|
{ |
94
|
|
|
$this->formWasValidated = true; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return bool |
99
|
|
|
*/ |
100
|
|
|
public function formWasValidated() |
101
|
|
|
{ |
102
|
|
|
return $this->formWasValidated; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return FormResult |
107
|
|
|
*/ |
108
|
|
|
public function getFormResult() |
109
|
|
|
{ |
110
|
|
|
if (null === $this->formResult) { |
111
|
|
|
$this->formResult = new FormResult; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return $this->formResult; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
|
|
public function getFormHash() |
121
|
|
|
{ |
122
|
|
|
if (null === $this->formHash) { |
123
|
|
|
$this->formHash = HashService::get()->getHash(uniqid(get_class($this->form))); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return $this->formHash; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param string $hash |
131
|
|
|
*/ |
132
|
|
|
public function setFormHash($hash) |
133
|
|
|
{ |
134
|
|
|
$this->formHash = $hash; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|