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