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