Completed
Push — feature/improve-form-definitio... ( 5df9ba...6ebf3c )
by Romain
02:15
created

validatorMessageAlreadyAdded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
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\Exceptions;
15
16
use Romm\Formz\Configuration\Configuration;
17
use Romm\Formz\Form\Definition\Condition\Activation;
18
use Romm\Formz\Form\Definition\Field\Field;
19
use Romm\Formz\Form\Definition\Field\Validation\Validator;
20
use Romm\Formz\Form\Definition\FormDefinition;
21
use Romm\Formz\Form\FormInterface;
22
use Romm\Formz\Form\FormObject\FormObject;
23
use Romm\Formz\Form\FormObject\FormObjectStatic;
24
25
class DuplicateEntryException extends FormzException
26
{
27
    const DUPLICATED_FORM_CONTEXT = 'You can not use a form view helper inside another one.';
28
29
    const FORM_WAS_ALREADY_REGISTERED = 'The form "%s" was already registered. You can only register a form once. Check the function `%s::hasForm()`.';
30
31
    const FORM_INSTANCE_ALREADY_ADDED = 'The form instance was already added for the form object of class "%s". You cannot add it twice.';
32
33
    const FORM_OBJECT_INSTANCE_ALREADY_REGISTERED = 'The form instance of type "%s" (name "%s") was already registered in the form object factory.';
34
35
    const FIELD_ALREADY_ADDED = 'The field "%s" already exists in the form definition. Please use the function `%s::hasField()` before.';
36
37
    const FORM_CONDITION_ALREADY_ADDED = 'The condition "%s" already exists in the form definition. Please use the function `%s::hasCondition()` before.';
38
39
    const ACTIVATION_CONDITION_ALREADY_ADDED = 'The condition "%s" already exists for the activation. Please use the function `%s::hasCondition()` before.';
40
41
    const FIELD_VALIDATOR_ALREADY_ADDED = 'The validator "%s" already exists for the field "%s". Please use the function `%s::hasValidator()` before.';
42
43
    const FIELD_BEHAVIOUR_ALREADY_ADDED = 'The behaviour "%s" already exists for the field "%s". Please use the function `%s::hasBehaviour()` before.';
44
45
    const VALIDATOR_MESSAGE_ALREADY_ADDED = 'The message "%s" already exists for the validator "%s". Please use the function `%s::hasMessage()` before.';
46
47
    /**
48
     * @code 1465242575
49
     *
50
     * @return self
51
     */
52
    final public static function duplicatedFormContext()
53
    {
54
        /** @var self $exception */
55
        $exception = self::getNewExceptionInstance(self::DUPLICATED_FORM_CONTEXT);
56
57
        return $exception;
58
    }
59
60
    /**
61
     * @code 1477255145
62
     *
63
     * @param FormObjectStatic $form
64
     * @return self
65
     */
66
    final public static function formWasAlreadyRegistered(FormObjectStatic $form)
67
    {
68
        /** @var self $exception */
69
        $exception = self::getNewExceptionInstance(
70
            self::FORM_WAS_ALREADY_REGISTERED,
71
            [$form->getClassName(), Configuration::class]
72
        );
73
74
        return $exception;
75
    }
76
77
    /**
78
     * @code 1491898212
79
     *
80
     * @param FormObject $formObject
81
     * @return self
82
     */
83
    final public static function formInstanceAlreadyAdded(FormObject $formObject)
84
    {
85
        /** @var self $exception */
86
        $exception = self::getNewExceptionInstance(
87
            self::FORM_INSTANCE_ALREADY_ADDED,
88
            [$formObject->getClassName()]
89
        );
90
91
        return $exception;
92
    }
93
94
    /**
95
     * @code 1494515318
96
     *
97
     * @param FormInterface $form
98
     * @param string        $name
99
     * @return self
100
     */
101
    final public static function formObjectInstanceAlreadyRegistered(FormInterface $form, $name)
102
    {
103
        /** @var self $exception */
104
        $exception = self::getNewExceptionInstance(
105
            self::FORM_OBJECT_INSTANCE_ALREADY_REGISTERED,
106
            [get_class($form), $name]
107
        );
108
109
        return $exception;
110
    }
111
112
    /**
113
     * @code 1493881202
114
     *
115
     * @param string $name
116
     * @return self
117
     */
118
    final public static function fieldAlreadyAdded($name)
119
    {
120
        /** @var self $exception */
121
        $exception = self::getNewExceptionInstance(
122
            self::FIELD_ALREADY_ADDED,
123
            [$name, FormDefinition::class]
124
        );
125
126
        return $exception;
127
    }
128
129
    /**
130
     * @code 1493882348
131
     *
132
     * @param string $name
133
     * @return self
134
     */
135
    final public static function formConditionAlreadyAdded($name)
136
    {
137
        /** @var self $exception */
138
        $exception = self::getNewExceptionInstance(
139
            self::FORM_CONDITION_ALREADY_ADDED,
140
            [$name, FormDefinition::class]
141
        );
142
143
        return $exception;
144
    }
145
146
    /**
147
     * @code 1494329265
148
     *
149
     * @param string $name
150
     * @return self
151
     */
152
    final public static function activationConditionAlreadyAdded($name)
153
    {
154
        /** @var self $exception */
155
        $exception = self::getNewExceptionInstance(
156
            self::ACTIVATION_CONDITION_ALREADY_ADDED,
157
            [$name, Activation::class]
158
        );
159
160
        return $exception;
161
    }
162
163
    /**
164
     * @code 1494685038
165
     *
166
     * @param string $validatorName
167
     * @param string $fieldName
168
     * @return self
169
     */
170
    final public static function fieldValidatorAlreadyAdded($validatorName, $fieldName)
171
    {
172
        /** @var self $exception */
173
        $exception = self::getNewExceptionInstance(
174
            self::FIELD_VALIDATOR_ALREADY_ADDED,
175
            [$validatorName, $fieldName, Field::class]
176
        );
177
178
        return $exception;
179
    }
180
181
    /**
182
     * @code 1494685575
183
     *
184
     * @param string $behaviourName
185
     * @param Field  $field
186
     * @return self
187
     */
188
    final public static function fieldBehaviourAlreadyAdded($behaviourName, Field $field)
189
    {
190
        /** @var self $exception */
191
        $exception = self::getNewExceptionInstance(
192
            self::FIELD_BEHAVIOUR_ALREADY_ADDED,
193
            [$behaviourName, $field->getName(), Field::class]
194
        );
195
196
        return $exception;
197
    }
198
199
    /**
200
     * @code 1494694566
201
     *
202
     * @param string    $messageName
203
     * @param Validator $validator
204
     * @return self
205
     */
206
    final public static function validatorMessageAlreadyAdded($messageName, Validator $validator)
207
    {
208
        /** @var self $exception */
209
        $exception = self::getNewExceptionInstance(
210
            self::VALIDATOR_MESSAGE_ALREADY_ADDED,
211
            [$messageName, $validator->getName(), Validator::class]
212
        );
213
214
        return $exception;
215
    }
216
}
217