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\Configuration\View\Layouts\LayoutGroup; |
18
|
|
|
use Romm\Formz\Configuration\View\View; |
19
|
|
|
use Romm\Formz\Form\Definition\Condition\Activation; |
20
|
|
|
use Romm\Formz\Form\Definition\Field\Field; |
21
|
|
|
use Romm\Formz\Form\Definition\Field\Validation\Validator; |
22
|
|
|
use Romm\Formz\Form\Definition\FormDefinition; |
23
|
|
|
use Romm\Formz\Form\FormInterface; |
24
|
|
|
use Romm\Formz\Form\FormObject\FormObject; |
25
|
|
|
use Romm\Formz\Form\FormObject\FormObjectStatic; |
26
|
|
|
|
27
|
|
|
class DuplicateEntryException extends FormzException |
28
|
|
|
{ |
29
|
|
|
const DUPLICATED_FORM_CONTEXT = 'You can not use a form view helper inside another one.'; |
30
|
|
|
|
31
|
|
|
const FORM_WAS_ALREADY_REGISTERED = 'The form "%s" was already registered. You can only register a form once. Check the function `%s::hasForm()`.'; |
32
|
|
|
|
33
|
|
|
const FORM_INSTANCE_ALREADY_ADDED = 'The form instance was already added for the form object of class "%s". You cannot add it twice.'; |
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_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
|
|
|
const VIEW_LAYOUT_ALREADY_ADDED = 'The layout "%s" already exists for the view. Please use the function `%s::hasLayout()` before.'; |
50
|
|
|
|
51
|
|
|
const LAYOUT_ITEM_ALREADY_ADDED = 'The item "%s" already exists for the layout "%s". Please use the function `%s::hasItem()` before.'; |
52
|
|
|
|
53
|
|
|
const MIDDLEWARE_ALREADY_ADDED = 'The middleware "%s" was already added to the form. Please use the function `%s::hasMiddleware()` before.'; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @code 1465242575 |
57
|
|
|
* |
58
|
|
|
* @return self |
59
|
|
|
*/ |
60
|
|
|
final public static function duplicatedFormContext() |
61
|
|
|
{ |
62
|
|
|
/** @var self $exception */ |
63
|
|
|
$exception = self::getNewExceptionInstance(self::DUPLICATED_FORM_CONTEXT); |
64
|
|
|
|
65
|
|
|
return $exception; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @code 1477255145 |
70
|
|
|
* |
71
|
|
|
* @param FormObjectStatic $form |
72
|
|
|
* @return self |
73
|
|
|
*/ |
74
|
|
|
final public static function formWasAlreadyRegistered(FormObjectStatic $form) |
75
|
|
|
{ |
76
|
|
|
/** @var self $exception */ |
77
|
|
|
$exception = self::getNewExceptionInstance( |
78
|
|
|
self::FORM_WAS_ALREADY_REGISTERED, |
79
|
|
|
[$form->getClassName(), Configuration::class] |
80
|
|
|
); |
81
|
|
|
|
82
|
|
|
return $exception; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @code 1491898212 |
87
|
|
|
* |
88
|
|
|
* @param FormObject $formObject |
89
|
|
|
* @return self |
90
|
|
|
*/ |
91
|
|
|
final public static function formInstanceAlreadyAdded(FormObject $formObject) |
92
|
|
|
{ |
93
|
|
|
/** @var self $exception */ |
94
|
|
|
$exception = self::getNewExceptionInstance( |
95
|
|
|
self::FORM_INSTANCE_ALREADY_ADDED, |
96
|
|
|
[$formObject->getClassName()] |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
return $exception; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @code 1494515318 |
104
|
|
|
* |
105
|
|
|
* @param FormInterface $form |
106
|
|
|
* @param string $name |
107
|
|
|
* @return self |
108
|
|
|
*/ |
109
|
|
|
final public static function formObjectInstanceAlreadyRegistered(FormInterface $form, $name) |
110
|
|
|
{ |
111
|
|
|
/** @var self $exception */ |
112
|
|
|
$exception = self::getNewExceptionInstance( |
113
|
|
|
self::FORM_OBJECT_INSTANCE_ALREADY_REGISTERED, |
114
|
|
|
[get_class($form), $name] |
115
|
|
|
); |
116
|
|
|
|
117
|
|
|
return $exception; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @code 1493881202 |
122
|
|
|
* |
123
|
|
|
* @param string $name |
124
|
|
|
* @return self |
125
|
|
|
*/ |
126
|
|
|
final public static function fieldAlreadyAdded($name) |
127
|
|
|
{ |
128
|
|
|
/** @var self $exception */ |
129
|
|
|
$exception = self::getNewExceptionInstance( |
130
|
|
|
self::FIELD_ALREADY_ADDED, |
131
|
|
|
[$name, FormDefinition::class] |
132
|
|
|
); |
133
|
|
|
|
134
|
|
|
return $exception; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @code 1493882348 |
139
|
|
|
* |
140
|
|
|
* @param string $name |
141
|
|
|
* @return self |
142
|
|
|
*/ |
143
|
|
|
final public static function formConditionAlreadyAdded($name) |
144
|
|
|
{ |
145
|
|
|
/** @var self $exception */ |
146
|
|
|
$exception = self::getNewExceptionInstance( |
147
|
|
|
self::FORM_CONDITION_ALREADY_ADDED, |
148
|
|
|
[$name, FormDefinition::class] |
149
|
|
|
); |
150
|
|
|
|
151
|
|
|
return $exception; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @code 1494329265 |
156
|
|
|
* |
157
|
|
|
* @param string $name |
158
|
|
|
* @return self |
159
|
|
|
*/ |
160
|
|
|
final public static function activationConditionAlreadyAdded($name) |
161
|
|
|
{ |
162
|
|
|
/** @var self $exception */ |
163
|
|
|
$exception = self::getNewExceptionInstance( |
164
|
|
|
self::ACTIVATION_CONDITION_ALREADY_ADDED, |
165
|
|
|
[$name, Activation::class] |
166
|
|
|
); |
167
|
|
|
|
168
|
|
|
return $exception; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @code 1494685038 |
173
|
|
|
* |
174
|
|
|
* @param string $validatorName |
175
|
|
|
* @param string $fieldName |
176
|
|
|
* @return self |
177
|
|
|
*/ |
178
|
|
|
final public static function fieldValidatorAlreadyAdded($validatorName, $fieldName) |
179
|
|
|
{ |
180
|
|
|
/** @var self $exception */ |
181
|
|
|
$exception = self::getNewExceptionInstance( |
182
|
|
|
self::FIELD_VALIDATOR_ALREADY_ADDED, |
183
|
|
|
[$validatorName, $fieldName, Field::class] |
184
|
|
|
); |
185
|
|
|
|
186
|
|
|
return $exception; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @code 1494685575 |
191
|
|
|
* |
192
|
|
|
* @param string $behaviourName |
193
|
|
|
* @param Field $field |
194
|
|
|
* @return self |
195
|
|
|
*/ |
196
|
|
|
final public static function fieldBehaviourAlreadyAdded($behaviourName, Field $field) |
197
|
|
|
{ |
198
|
|
|
/** @var self $exception */ |
199
|
|
|
$exception = self::getNewExceptionInstance( |
200
|
|
|
self::FIELD_BEHAVIOUR_ALREADY_ADDED, |
201
|
|
|
[$behaviourName, $field->getName(), Field::class] |
202
|
|
|
); |
203
|
|
|
|
204
|
|
|
return $exception; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @code 1494694566 |
209
|
|
|
* |
210
|
|
|
* @param string $messageName |
211
|
|
|
* @param Validator $validator |
212
|
|
|
* @return self |
213
|
|
|
*/ |
214
|
|
|
final public static function validatorMessageAlreadyAdded($messageName, Validator $validator) |
215
|
|
|
{ |
216
|
|
|
/** @var self $exception */ |
217
|
|
|
$exception = self::getNewExceptionInstance( |
218
|
|
|
self::VALIDATOR_MESSAGE_ALREADY_ADDED, |
219
|
|
|
[$messageName, $validator->getName(), Validator::class] |
220
|
|
|
); |
221
|
|
|
|
222
|
|
|
return $exception; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @code 1494846335 |
227
|
|
|
* |
228
|
|
|
* @param string $name |
229
|
|
|
* @return self |
230
|
|
|
*/ |
231
|
|
|
final public static function viewLayoutAlreadyAdded($name) |
232
|
|
|
{ |
233
|
|
|
/** @var self $exception */ |
234
|
|
|
$exception = self::getNewExceptionInstance( |
235
|
|
|
self::VIEW_LAYOUT_ALREADY_ADDED, |
236
|
|
|
[$name, View::class] |
237
|
|
|
); |
238
|
|
|
|
239
|
|
|
return $exception; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @code 1494846944 |
244
|
|
|
* |
245
|
|
|
* @param string $name |
246
|
|
|
* @param LayoutGroup $layoutGroup |
247
|
|
|
* @return self |
248
|
|
|
*/ |
249
|
|
|
final public static function layoutItemAlreadyAdded($name, LayoutGroup $layoutGroup) |
250
|
|
|
{ |
251
|
|
|
/** @var self $exception */ |
252
|
|
|
$exception = self::getNewExceptionInstance( |
253
|
|
|
self::LAYOUT_ITEM_ALREADY_ADDED, |
254
|
|
|
[$name, $layoutGroup->getName(), LayoutGroup::class] |
255
|
|
|
); |
256
|
|
|
|
257
|
|
|
return $exception; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* @code 1502104500 |
262
|
|
|
* |
263
|
|
|
* @param string $name |
264
|
|
|
* @return self |
265
|
|
|
*/ |
266
|
|
|
final public static function middlewareAlreadyAdded($name) |
267
|
|
|
{ |
268
|
|
|
/** @var self $exception */ |
269
|
|
|
$exception = self::getNewExceptionInstance( |
270
|
|
|
self::MIDDLEWARE_ALREADY_ADDED, |
271
|
|
|
[$name, FormDefinition::class] |
272
|
|
|
); |
273
|
|
|
|
274
|
|
|
return $exception; |
275
|
|
|
} |
276
|
|
|
} |
277
|
|
|
|