Completed
Push — middleware-wip-tmp ( d8f2e1 )
by Romain
02:50
created

FormObjectProxy   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 164
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 3

Importance

Changes 0
Metric Value
wmc 14
lcom 4
cbo 3
dl 0
loc 164
rs 10
c 0
b 0
f 0

13 Methods

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