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

FormObject::getName()   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\Configuration\Form\Form;
17
use Romm\Formz\Core\Core;
18
use Romm\Formz\Domain\Model\FormMetadata;
19
use Romm\Formz\Error\FormResult;
20
use Romm\Formz\Form\FormInterface;
21
use Romm\Formz\Form\Service\FormObjectMetadata;
22
use Romm\Formz\Form\Service\FormObjectRequestData;
23
use Romm\Formz\Persistence\PersistenceManager;
24
use TYPO3\CMS\Extbase\Error\Result;
25
26
/**
27
 * This is the object representation of a form. In here we can manage which
28
 * properties the form does have, its configuration, and more.
29
 */
30
class FormObject
31
{
32
    /**
33
     * @var string
34
     */
35
    protected $name;
36
37
    /**
38
     * @var FormObjectStatic
39
     */
40
    protected $static;
41
42
    /**
43
     * @var FormObjectProxy
44
     */
45
    protected $proxy;
46
47
    /**
48
     * @var FormObjectFactory
49
     */
50
    protected $formObjectFactory;
51
52
    /**
53
     * You should never create a new instance of this class directly, use the
54
     * `FormObjectFactory->getInstanceFromClassName()` function instead.
55
     *
56
     * @param string           $name
57
     * @param FormObjectStatic $static
58
     */
59
    public function __construct($name, FormObjectStatic $static)
60
    {
61
        $this->name = $name;
62
        $this->static = $static;
63
64
        $this->metadata = Core::instantiate(FormObjectMetadata::class, $this);
0 ignored issues
show
Bug introduced by
The property metadata does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    public function getName()
71
    {
72
        return $this->name;
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    public function getClassName()
79
    {
80
        return $this->static->getClassName();
81
    }
82
83
    /**
84
     * @return Form
85
     */
86
    public function getConfiguration()
87
    {
88
        return $this->static->getConfiguration();
89
    }
90
91
    /**
92
     * @return Result
93
     */
94
    public function getConfigurationValidationResult()
95
    {
96
        return $this->static->getConfigurationValidationResult();
97
    }
98
99
    /**
100
     * @return FormObjectRequestData
101
     */
102
    public function getRequestData()
103
    {
104
        return $this->getProxy()->getRequestData();
105
    }
106
107
    /**
108
     * @return FormInterface
109
     */
110
    public function getForm()
111
    {
112
        return $this->getProxy()->getForm();
113
    }
114
115
    /**
116
     * @return bool
117
     */
118
    public function hasForm()
119
    {
120
        return $this->proxy !== null;
121
    }
122
123
    /**
124
     * @param FormInterface $form
125
     */
126
    public function setForm(FormInterface $form)
127
    {
128
        $this->proxy = $this->formObjectFactory->getProxy($this, $form);
129
    }
130
131
    /**
132
     * Will mark the form as submitted (change the result returned by the
133
     * function `formWasSubmitted()`).
134
     */
135
    public function markFormAsSubmitted()
136
    {
137
        $this->getProxy()->markFormAsSubmitted();
138
    }
139
140
    /**
141
     * Returns `true` if the form was submitted by the user.
142
     *
143
     * @return bool
144
     */
145
    public function formWasSubmitted()
146
    {
147
        return $this->hasForm() && $this->getProxy()->formWasSubmitted();
148
    }
149
150
    /**
151
     * @return FormResult
152
     */
153
    public function getFormResult()
154
    {
155
        return $this->getProxy()->getFormResult();
156
    }
157
158
    /**
159
     * @return bool
160
     */
161
    public function hasFormResult()
162
    {
163
        return $this->getProxy()->hasFormResult();
164
    }
165
166
    /**
167
     * @param FormResult $formResult
168
     */
169
    public function setFormResult($formResult)
170
    {
171
        $this->getProxy()->setFormResult($formResult);
172
    }
173
174
    /**
175
     * @return FormMetadata
176
     */
177
    public function getMetadata()
178
    {
179
        return $this->getProxy()->getMetadata();
180
    }
181
182
    /**
183
     * @param string $hash
184
     */
185
    public function setFormHash($hash)
186
    {
187
        $this->getProxy()->setFormHash($hash);
188
    }
189
190
    /**
191
     * @return string
192
     */
193
    public function getFormHash()
194
    {
195
        return $this->getProxy()->getFormHash();
196
    }
197
198
    /**
199
     * Returns a unique hash for this form object.
200
     *
201
     * @return string
202
     */
203
    public function getObjectHash()
204
    {
205
        return $this->static->getObjectHash();
206
    }
207
208
    /**
209
     * @return PersistenceManager
210
     */
211
    public function getPersistenceManager()
212
    {
213
        return $this->getProxy()->getPersistenceManager();
214
    }
215
216
    /**
217
     * @return FormObjectProxy
218
     */
219
    public function getProxy()
220
    {
221
        // @todo exception
222
223
        return $this->proxy;
224
    }
225
226
    /**
227
     * @param FormObjectFactory $formObjectFactory
228
     */
229
    public function injectFormObjectFactory(FormObjectFactory $formObjectFactory)
230
    {
231
        $this->formObjectFactory = $formObjectFactory;
232
    }
233
}
234