Completed
Push — middleware-wip ( 9da264...f499dc )
by Romain
03:03
created

formObjectInstanceAlreadyRegistered()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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