Completed
Push — feature/middleware ( 864c18...e1fdd7 )
by Romain
02:52
created

FormObjectProxy::getForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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