Completed
Push — unit-tests-validation ( 4a3d84...420a0c )
by Romain
02:02
created

Validation::setClassName()   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 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\Configuration\Form\Field\Validation;
15
16
use Romm\ConfigurationObject\Service\Items\Parents\ParentsTrait;
17
use Romm\ConfigurationObject\Traits\ConfigurationObject\ArrayConversionTrait;
18
use Romm\ConfigurationObject\Traits\ConfigurationObject\StoreArrayIndexTrait;
19
use Romm\Formz\Configuration\AbstractFormzConfiguration;
20
use Romm\Formz\Configuration\Form\Condition\Activation\ActivationInterface;
21
use Romm\Formz\Configuration\Form\Condition\Activation\EmptyActivation;
22
use Romm\Formz\Configuration\Form\Field\Field;
23
24
class Validation extends AbstractFormzConfiguration
25
{
26
    use StoreArrayIndexTrait;
27
    use ArrayConversionTrait;
28
    use ParentsTrait;
29
30
    /**
31
     * @var string
32
     * @validate NotEmpty
33
     * @validate Romm.ConfigurationObject:ClassImplements(interface=TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface)
34
     */
35
    protected $className;
36
37
    /**
38
     * @var string
39
     * @validate Number
40
     */
41
    protected $priority;
42
43
    /**
44
     * @var array
45
     */
46
    protected $options = [];
47
48
    /**
49
     * @var \ArrayObject<Romm\Formz\Configuration\Form\Field\Validation\Message>
50
     */
51
    protected $messages = [];
52
53
    /**
54
     * @var \Romm\Formz\Configuration\Form\Condition\Activation\ActivationResolver
55
     * @validate Romm.Formz:Internal\ConditionIsValid
56
     */
57
    protected $activation;
58
59
    /**
60
     * @var bool
61
     */
62
    protected $useAjax = false;
63
64
    /**
65
     * Name of the validation. By default, it is the key of this validation in
66
     * the array containing all validations for the parent field.
67
     *
68
     * @var string
69
     */
70
    private $validationName;
71
72
    /**
73
     * Constructor.
74
     */
75
    public function __construct()
76
    {
77
        $this->activation = EmptyActivation::get();
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getClassName()
84
    {
85
        return $this->className;
86
    }
87
88
    /**
89
     * @param string $className
90
     */
91
    public function setClassName($className)
92
    {
93
        $this->className = $className;
94
    }
95
96
    /**
97
     * @return int
98
     */
99
    public function getPriority()
100
    {
101
        return $this->priority;
102
    }
103
104
    /**
105
     * @return array
106
     */
107
    public function getOptions()
108
    {
109
        return $this->options;
110
    }
111
112
    /**
113
     * @param string $optionName
114
     * @return null|mixed
115
     */
116
    public function getOption($optionName)
117
    {
118
        return (null !== $optionName && true === isset($this->options[$optionName]))
119
            ? $this->options[$optionName]
120
            : null;
121
    }
122
123
    /**
124
     * @return Message[]
125
     */
126
    public function getMessages()
127
    {
128
        return $this->messages;
129
    }
130
131
    /**
132
     * @param Message[] $messages
133
     */
134
    public function setMessages(array $messages)
135
    {
136
        $this->messages = $messages;
137
    }
138
139
    /**
140
     * @return ActivationInterface
141
     */
142
    public function getActivation()
143
    {
144
        return $this->activation;
145
    }
146
147
    /**
148
     * @return bool
149
     */
150
    public function hasActivation()
151
    {
152
        return !($this->activation instanceof EmptyActivation);
153
    }
154
155
    /**
156
     * @return string
157
     */
158
    public function getValidationName()
159
    {
160
        if (null === $this->validationName) {
161
            $this->validationName = $this->getArrayIndex();
162
        }
163
164
        return $this->validationName;
165
    }
166
167
    /**
168
     * @return bool
169
     */
170
    public function doesUseAjax()
171
    {
172
        return (bool)$this->useAjax;
173
    }
174
175
    /**
176
     * @param bool $flag
177
     */
178
    public function activateAjaxUsage($flag = true)
179
    {
180
        $this->useAjax = (bool)$flag;
181
    }
182
183
    /**
184
     * @param string $validationName
185
     */
186
    public function setValidationName($validationName)
187
    {
188
        $this->validationName = $validationName;
189
    }
190
191
    /**
192
     * @return Field
193
     */
194
    public function getParentField()
195
    {
196
        return $this->getFirstParent(Field::class);
197
    }
198
}
199