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\Field\Activation\Activation; |
18
|
|
|
use Romm\Formz\Form\Definition\FormDefinition; |
19
|
|
|
use Romm\Formz\Form\FormObject\FormObject; |
20
|
|
|
use Romm\Formz\Form\FormObject\FormObjectStatic; |
21
|
|
|
|
22
|
|
|
class DuplicateEntryException extends FormzException |
23
|
|
|
{ |
24
|
|
|
const DUPLICATED_FORM_CONTEXT = 'You can not use a form view helper inside another one.'; |
25
|
|
|
|
26
|
|
|
const FORM_WAS_ALREADY_REGISTERED = 'The form "%s" was already registered. You can only register a form once. Check the function `%s::hasForm()`.'; |
27
|
|
|
|
28
|
|
|
const FORM_INSTANCE_ALREADY_ADDED = 'The form instance was already added for the form object of class "%s". You cannot add it twice.'; |
29
|
|
|
|
30
|
|
|
const FIELD_ALREADY_ADDED = 'The field "%s" already exists in the form definition. Please use the function `%s::hasField()` before.'; |
31
|
|
|
|
32
|
|
|
const FORM_CONDITION_ALREADY_ADDED = 'The condition "%s" already exists in the form definition. Please use the function `%s::hasCondition()` before.'; |
33
|
|
|
|
34
|
|
|
const ACTIVATION_CONDITION_ALREADY_ADDED = 'The condition "%s" already exists for the activation. Please use the function `%s::hasCondition()` before.'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @code 1465242575 |
38
|
|
|
* |
39
|
|
|
* @return self |
40
|
|
|
*/ |
41
|
|
|
final public static function duplicatedFormContext() |
42
|
|
|
{ |
43
|
|
|
/** @var self $exception */ |
44
|
|
|
$exception = self::getNewExceptionInstance(self::DUPLICATED_FORM_CONTEXT); |
45
|
|
|
|
46
|
|
|
return $exception; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @code 1477255145 |
51
|
|
|
* |
52
|
|
|
* @param FormObjectStatic $form |
53
|
|
|
* @return self |
54
|
|
|
*/ |
55
|
|
|
final public static function formWasAlreadyRegistered(FormObjectStatic $form) |
56
|
|
|
{ |
57
|
|
|
/** @var self $exception */ |
58
|
|
|
$exception = self::getNewExceptionInstance( |
59
|
|
|
self::FORM_WAS_ALREADY_REGISTERED, |
60
|
|
|
[$form->getClassName(), Configuration::class] |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
return $exception; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @code 1491898212 |
68
|
|
|
* |
69
|
|
|
* @param FormObject $formObject |
70
|
|
|
* @return self |
71
|
|
|
*/ |
72
|
|
|
final public static function formInstanceAlreadyAdded(FormObject $formObject) |
73
|
|
|
{ |
74
|
|
|
/** @var self $exception */ |
75
|
|
|
$exception = self::getNewExceptionInstance( |
76
|
|
|
self::FORM_INSTANCE_ALREADY_ADDED, |
77
|
|
|
[$formObject->getClassName()] |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
return $exception; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @code 1493881202 |
85
|
|
|
* |
86
|
|
|
* @param string $name |
87
|
|
|
* @return self |
88
|
|
|
*/ |
89
|
|
|
final public static function fieldAlreadyAdded($name) |
90
|
|
|
{ |
91
|
|
|
/** @var self $exception */ |
92
|
|
|
$exception = self::getNewExceptionInstance( |
93
|
|
|
self::FIELD_ALREADY_ADDED, |
94
|
|
|
[$name, FormDefinition::class] |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
return $exception; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @code 1493882348 |
102
|
|
|
* |
103
|
|
|
* @param string $name |
104
|
|
|
* @return self |
105
|
|
|
*/ |
106
|
|
|
final public static function formConditionAlreadyAdded($name) |
107
|
|
|
{ |
108
|
|
|
/** @var self $exception */ |
109
|
|
|
$exception = self::getNewExceptionInstance( |
110
|
|
|
self::FORM_CONDITION_ALREADY_ADDED, |
111
|
|
|
[$name, FormDefinition::class] |
112
|
|
|
); |
113
|
|
|
|
114
|
|
|
return $exception; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @code 1494329265 |
119
|
|
|
* |
120
|
|
|
* @param string $name |
121
|
|
|
* @return self |
122
|
|
|
*/ |
123
|
|
|
final public static function activationConditionAlreadyAdded($name) |
124
|
|
|
{ |
125
|
|
|
/** @var self $exception */ |
126
|
|
|
$exception = self::getNewExceptionInstance( |
127
|
|
|
self::ACTIVATION_CONDITION_ALREADY_ADDED, |
128
|
|
|
[$name, Activation::class] |
129
|
|
|
); |
130
|
|
|
|
131
|
|
|
return $exception; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|