|
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 FORM_OBJECT_INSTANCE_ALREADY_REGISTERED = 'The form instance of type "%s" (name "%s") was already registered in the form object factory.'; |
|
36
|
|
|
|
|
37
|
|
|
const FIELD_ALREADY_ADDED = 'The field "%s" already exists in the form definition. Please use the function `%s::hasField()` before.'; |
|
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
|
|
|
/** |
|
54
|
|
|
* @code 1465242575 |
|
55
|
|
|
* |
|
56
|
|
|
* @return self |
|
57
|
|
|
*/ |
|
58
|
|
|
final public static function duplicatedFormContext() |
|
59
|
|
|
{ |
|
60
|
|
|
/** @var self $exception */ |
|
61
|
|
|
$exception = self::getNewExceptionInstance(self::DUPLICATED_FORM_CONTEXT); |
|
62
|
|
|
|
|
63
|
|
|
return $exception; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @code 1477255145 |
|
68
|
|
|
* |
|
69
|
|
|
* @param FormObjectStatic $form |
|
70
|
|
|
* @return self |
|
71
|
|
|
*/ |
|
72
|
|
|
final public static function formWasAlreadyRegistered(FormObjectStatic $form) |
|
73
|
|
|
{ |
|
74
|
|
|
/** @var self $exception */ |
|
75
|
|
|
$exception = self::getNewExceptionInstance( |
|
76
|
|
|
self::FORM_WAS_ALREADY_REGISTERED, |
|
77
|
|
|
[$form->getClassName(), Configuration::class] |
|
78
|
|
|
); |
|
79
|
|
|
|
|
80
|
|
|
return $exception; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @code 1491898212 |
|
85
|
|
|
* |
|
86
|
|
|
* @param FormObject $formObject |
|
87
|
|
|
* @return self |
|
88
|
|
|
*/ |
|
89
|
|
|
final public static function formInstanceAlreadyAdded(FormObject $formObject) |
|
90
|
|
|
{ |
|
91
|
|
|
/** @var self $exception */ |
|
92
|
|
|
$exception = self::getNewExceptionInstance( |
|
93
|
|
|
self::FORM_INSTANCE_ALREADY_ADDED, |
|
94
|
|
|
[$formObject->getClassName()] |
|
95
|
|
|
); |
|
96
|
|
|
|
|
97
|
|
|
return $exception; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @code 1494515318 |
|
102
|
|
|
* |
|
103
|
|
|
* @param FormInterface $form |
|
104
|
|
|
* @param string $name |
|
105
|
|
|
* @return self |
|
106
|
|
|
*/ |
|
107
|
|
|
final public static function formObjectInstanceAlreadyRegistered(FormInterface $form, $name) |
|
108
|
|
|
{ |
|
109
|
|
|
/** @var self $exception */ |
|
110
|
|
|
$exception = self::getNewExceptionInstance( |
|
111
|
|
|
self::FORM_OBJECT_INSTANCE_ALREADY_REGISTERED, |
|
112
|
|
|
[get_class($form), $name] |
|
113
|
|
|
); |
|
114
|
|
|
|
|
115
|
|
|
return $exception; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @code 1493881202 |
|
120
|
|
|
* |
|
121
|
|
|
* @param string $name |
|
122
|
|
|
* @return self |
|
123
|
|
|
*/ |
|
124
|
|
|
final public static function fieldAlreadyAdded($name) |
|
125
|
|
|
{ |
|
126
|
|
|
/** @var self $exception */ |
|
127
|
|
|
$exception = self::getNewExceptionInstance( |
|
128
|
|
|
self::FIELD_ALREADY_ADDED, |
|
129
|
|
|
[$name, FormDefinition::class] |
|
130
|
|
|
); |
|
131
|
|
|
|
|
132
|
|
|
return $exception; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @code 1493882348 |
|
137
|
|
|
* |
|
138
|
|
|
* @param string $name |
|
139
|
|
|
* @return self |
|
140
|
|
|
*/ |
|
141
|
|
|
final public static function formConditionAlreadyAdded($name) |
|
142
|
|
|
{ |
|
143
|
|
|
/** @var self $exception */ |
|
144
|
|
|
$exception = self::getNewExceptionInstance( |
|
145
|
|
|
self::FORM_CONDITION_ALREADY_ADDED, |
|
146
|
|
|
[$name, FormDefinition::class] |
|
147
|
|
|
); |
|
148
|
|
|
|
|
149
|
|
|
return $exception; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @code 1494329265 |
|
154
|
|
|
* |
|
155
|
|
|
* @param string $name |
|
156
|
|
|
* @return self |
|
157
|
|
|
*/ |
|
158
|
|
|
final public static function activationConditionAlreadyAdded($name) |
|
159
|
|
|
{ |
|
160
|
|
|
/** @var self $exception */ |
|
161
|
|
|
$exception = self::getNewExceptionInstance( |
|
162
|
|
|
self::ACTIVATION_CONDITION_ALREADY_ADDED, |
|
163
|
|
|
[$name, Activation::class] |
|
164
|
|
|
); |
|
165
|
|
|
|
|
166
|
|
|
return $exception; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @code 1494685038 |
|
171
|
|
|
* |
|
172
|
|
|
* @param string $validatorName |
|
173
|
|
|
* @param string $fieldName |
|
174
|
|
|
* @return self |
|
175
|
|
|
*/ |
|
176
|
|
|
final public static function fieldValidatorAlreadyAdded($validatorName, $fieldName) |
|
177
|
|
|
{ |
|
178
|
|
|
/** @var self $exception */ |
|
179
|
|
|
$exception = self::getNewExceptionInstance( |
|
180
|
|
|
self::FIELD_VALIDATOR_ALREADY_ADDED, |
|
181
|
|
|
[$validatorName, $fieldName, Field::class] |
|
182
|
|
|
); |
|
183
|
|
|
|
|
184
|
|
|
return $exception; |
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* @code 1494685575 |
|
189
|
|
|
* |
|
190
|
|
|
* @param string $behaviourName |
|
191
|
|
|
* @param Field $field |
|
192
|
|
|
* @return self |
|
193
|
|
|
*/ |
|
194
|
|
|
final public static function fieldBehaviourAlreadyAdded($behaviourName, Field $field) |
|
195
|
|
|
{ |
|
196
|
|
|
/** @var self $exception */ |
|
197
|
|
|
$exception = self::getNewExceptionInstance( |
|
198
|
|
|
self::FIELD_BEHAVIOUR_ALREADY_ADDED, |
|
199
|
|
|
[$behaviourName, $field->getName(), Field::class] |
|
200
|
|
|
); |
|
201
|
|
|
|
|
202
|
|
|
return $exception; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* @code 1494694566 |
|
207
|
|
|
* |
|
208
|
|
|
* @param string $messageName |
|
209
|
|
|
* @param Validator $validator |
|
210
|
|
|
* @return self |
|
211
|
|
|
*/ |
|
212
|
|
|
final public static function validatorMessageAlreadyAdded($messageName, Validator $validator) |
|
213
|
|
|
{ |
|
214
|
|
|
/** @var self $exception */ |
|
215
|
|
|
$exception = self::getNewExceptionInstance( |
|
216
|
|
|
self::VALIDATOR_MESSAGE_ALREADY_ADDED, |
|
217
|
|
|
[$messageName, $validator->getName(), Validator::class] |
|
218
|
|
|
); |
|
219
|
|
|
|
|
220
|
|
|
return $exception; |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* @code 1494846335 |
|
225
|
|
|
* |
|
226
|
|
|
* @param string $name |
|
227
|
|
|
* @return self |
|
228
|
|
|
*/ |
|
229
|
|
|
final public static function viewLayoutAlreadyAdded($name) |
|
230
|
|
|
{ |
|
231
|
|
|
/** @var self $exception */ |
|
232
|
|
|
$exception = self::getNewExceptionInstance( |
|
233
|
|
|
self::VIEW_LAYOUT_ALREADY_ADDED, |
|
234
|
|
|
[$name, View::class] |
|
235
|
|
|
); |
|
236
|
|
|
|
|
237
|
|
|
return $exception; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* @code 1494846944 |
|
242
|
|
|
* |
|
243
|
|
|
* @param string $name |
|
244
|
|
|
* @param LayoutGroup $layoutGroup |
|
245
|
|
|
* @return self |
|
246
|
|
|
*/ |
|
247
|
|
|
final public static function layoutItemAlreadyAdded($name, LayoutGroup $layoutGroup) |
|
248
|
|
|
{ |
|
249
|
|
|
/** @var self $exception */ |
|
250
|
|
|
$exception = self::getNewExceptionInstance( |
|
251
|
|
|
self::LAYOUT_ITEM_ALREADY_ADDED, |
|
252
|
|
|
[$name, $layoutGroup->getName(), LayoutGroup::class] |
|
253
|
|
|
); |
|
254
|
|
|
|
|
255
|
|
|
return $exception; |
|
256
|
|
|
} |
|
257
|
|
|
} |
|
258
|
|
|
|