Completed
Push — unit-tests-conditions ( 10987e...dba20c )
by Romain
03:04
created

Validation::setValidationName()   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.Formz:Internal\ClassExists
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 instance in the
66
     * array containing all the validation 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
     * @return int
90
     */
91
    public function getPriority()
92
    {
93
        return $this->priority;
94
    }
95
96
    /**
97
     * @return array
98
     */
99
    public function getOptions()
100
    {
101
        return $this->options;
102
    }
103
104
    /**
105
     * @param string $optionName
106
     * @return null|mixed
107
     */
108
    public function getOption($optionName)
109
    {
110
        return (null !== $optionName && true === isset($this->options[$optionName]))
111
            ? $this->options[$optionName]
112
            : null;
113
    }
114
115
    /**
116
     * @return \Romm\Formz\Configuration\Form\Field\Validation\Message[]
117
     */
118
    public function getMessages()
119
    {
120
        return $this->messages;
121
    }
122
123
    /**
124
     * @return ActivationInterface
125
     */
126
    public function getActivation()
127
    {
128
        return $this->activation;
129
    }
130
131
    /**
132
     * @return bool
133
     */
134
    public function hasActivation()
135
    {
136
        return !($this->activation instanceof EmptyActivation);
137
    }
138
139
    /**
140
     * @return string
141
     */
142
    public function getValidationName()
143
    {
144
        if (null === $this->validationName) {
145
            $this->validationName = $this->getArrayIndex();
146
        }
147
148
        return $this->validationName;
149
    }
150
151
    /**
152
     * @param string $validationName
153
     */
154
    public function setValidationName($validationName)
155
    {
156
        $this->validationName = $validationName;
157
    }
158
159
    /**
160
     * @return bool
161
     */
162
    public function doesUseAjax()
163
    {
164
        return (bool) $this->useAjax;
165
    }
166
167
    /**
168
     * @return Field
169
     */
170
    public function getParentField()
171
    {
172
        return $this->getFirstParent(Field::class);
173
    }
174
}
175