Completed
Push — feature/improve-form-object ( b88d74 )
by Romain
03:06
created

formObjectInstanceNotFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
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\Classes\ViewClass;
18
use Romm\Formz\Configuration\View\Layouts\LayoutGroup;
19
use Romm\Formz\Configuration\View\View;
20
use Romm\Formz\Form\Definition\Field\Activation\AbstractActivation;
21
use Romm\Formz\Form\Definition\FormDefinition;
22
use Romm\Formz\Form\FormInterface;
23
use Romm\Formz\Form\FormObject\FormObject;
24
use Romm\Formz\Form\FormObject\FormObjectFactory;
25
use Romm\Formz\Validation\Validator\AbstractValidator;
26
use Romm\Formz\ViewHelpers\ClassViewHelper;
27
use Romm\Formz\ViewHelpers\FieldViewHelper;
28
use Romm\Formz\ViewHelpers\FormatMessageViewHelper;
29
30
class EntryNotFoundException extends FormzException
31
{
32
    const FIELD_NOT_FOUND = 'The field "%s" was not found in the form "%s" with class "%s".';
33
34
    const CONDITION_NOT_FOUND = 'Trying to access a condition which is not registered: "%s". Here is a list of all currently registered conditions: "%s".';
35
36
    const ACTIVATION_CONDITION_NOT_FOUND = 'No condition "%s" was found.';
37
38
    const CONFIGURATION_FIELD_NOT_FOUND = 'The field "%s" was not found. Please use the function `%s::hasField()` before.';
39
40
    const VALIDATION_NOT_FOUND = 'The validation "%s" was not found. Please use the function `%s::hasValidation()` before.';
41
42
    const VIEW_LAYOUT_NOT_FOUND = 'The layout "%s" was not found. Please use the function `%s::hasLayout()` before.';
43
44
    const VIEW_LAYOUT_ITEM_NOT_FOUND = 'The layout item "%s" was not found. Please use the function `%s::hasItem()` before.';
45
46
    const VIEW_CLASS_NOT_FOUND = 'The class "%s" was not found. Please use the function `%s::hasItem()` before.';
47
48
    const VALIDATION_NOT_FOUND_FOR_FIELD = 'The field "%s" does not have a rule "%s".';
49
50
    const ERROR_KEY_NOT_FOUND_FOR_VALIDATOR = 'The error key "%s" does not exist for the validator "%s".';
51
52
    const VIEW_HELPER_FIELD_NOT_FOUND = 'The field "%s" could not be fetched for the view helper "%s": please either use this view helper inside the view helper "%s", or fill the parameter `field` of this view helper with the field name you want.';
53
54
    const FIELD_VIEW_HELPER_LAYOUT_NOT_FOUND = 'The layout "%s" could not be found. Please check your TypoScript configuration.';
55
56
    const FIELD_VIEW_HELPER_LAYOUT_ITEM_NOT_FOUND = 'The layout "%s" does not have an item "%s".';
57
58
    const CONTROLLER_SERVICE_ACTION_FORM_ARGUMENT_MISSING = 'The method `%s::%s()` must have a parameter `$%s`. Note that you can also change the parameter `name` of the form view helper.';
59
60
    const SLOT_NOT_FOUND = 'No slot "%s" was found.';
61
62
    const FORM_CONFIGURATION_NOT_FOUND = 'The configuration for form of class "%s" was not found. Please use the function `%s::hasForm()` before.';
63
64
    const FORM_OBJECT_INSTANCE_NOT_FOUND = 'The form instance for the object of type "%s" was not found. Please take care of registering it before with "%s::registerFormInstance()".';
65
66
    /**
67
     * @code 1472650209
68
     *
69
     * @param string $name
70
     * @param array  $list
71
     * @return self
72
     */
73
    final public static function conditionNotFound($name, array $list)
74
    {
75
        /** @var self $exception */
76
        $exception = self::getNewExceptionInstance(
77
            self::CONDITION_NOT_FOUND,
78
            [
79
                $name,
80
                implode('" ,"', array_keys($list))
81
            ]
82
        );
83
84
        return $exception;
85
    }
86
87
    /**
88
     * @code 1488482191
89
     *
90
     * @param string $name
91
     * @return self
92
     */
93
    final public static function activationConditionNotFound($name)
94
    {
95
        /** @var self $exception */
96
        $exception = self::getNewExceptionInstance(
97
            self::ACTIVATION_CONDITION_NOT_FOUND,
98
            [$name]
99
        );
100
101
        return $exception;
102
    }
103
104
    /**
105
     * @code 1489765133
106
     *
107
     * @param string $name
108
     * @return self
109
     */
110
    final public static function configurationFieldNotFound($name)
111
    {
112
        /** @var self $exception */
113
        $exception = self::getNewExceptionInstance(
114
            self::CONFIGURATION_FIELD_NOT_FOUND,
115
            [$name, FormDefinition::class]
116
        );
117
118
        return $exception;
119
    }
120
121
    /**
122
     * @code 1487672276
123
     *
124
     * @param string $name
125
     * @return self
126
     */
127
    final public static function validationNotFound($name)
128
    {
129
        /** @var self $exception */
130
        $exception = self::getNewExceptionInstance(
131
            self::VALIDATION_NOT_FOUND,
132
            [$name, AbstractActivation::class]
133
        );
134
135
        return $exception;
136
    }
137
138
    /**
139
     * @code 1489753952
140
     *
141
     * @param string $name
142
     * @return self
143
     */
144
    final public static function viewLayoutNotFound($name)
145
    {
146
        /** @var self $exception */
147
        $exception = self::getNewExceptionInstance(
148
            self::VIEW_LAYOUT_NOT_FOUND,
149
            [$name, View::class]
150
        );
151
152
        return $exception;
153
    }
154
155
    /**
156
     * @code 1489757511
157
     *
158
     * @param string $name
159
     * @return self
160
     */
161
    final public static function viewLayoutItemNotFound($name)
162
    {
163
        /** @var self $exception */
164
        $exception = self::getNewExceptionInstance(
165
            self::VIEW_LAYOUT_ITEM_NOT_FOUND,
166
            [$name, LayoutGroup::class]
167
        );
168
169
        return $exception;
170
    }
171
172
    /**
173
     * @code 1489754909
174
     *
175
     * @param string $name
176
     * @return self
177
     */
178
    final public static function viewClassNotFound($name)
179
    {
180
        /** @var self $exception */
181
        $exception = self::getNewExceptionInstance(
182
            self::VIEW_CLASS_NOT_FOUND,
183
            [$name, ViewClass::class]
184
        );
185
186
        return $exception;
187
    }
188
189
    /**
190
     * @code 1487672956
191
     *
192
     * @param string $validationName
193
     * @param string $fieldName
194
     * @return self
195
     */
196
    final public static function ajaxControllerValidationNotFoundForField($validationName, $fieldName)
197
    {
198
        /** @var self $exception */
199
        $exception = self::getNewExceptionInstance(
200
            self::VALIDATION_NOT_FOUND_FOR_FIELD,
201
            [$fieldName, $validationName]
202
        );
203
204
        return $exception;
205
    }
206
207
    /**
208
     * @code 1487671603
209
     *
210
     * @param string     $fieldName
211
     * @param FormObject $formObject
212
     * @return self
213
     */
214
    final public static function ajaxControllerFieldNotFound($fieldName, FormObject $formObject)
215
    {
216
        /** @var self $exception */
217
        $exception = self::getNewExceptionInstance(
218
            self::FIELD_NOT_FOUND,
219
            [$fieldName, $formObject->getName(), $formObject->getClassName()]
220
        );
221
222
        return $exception;
223
    }
224
225
    /**
226
     * @code 1455272659
227
     *
228
     * @param string            $key
229
     * @param AbstractValidator $validator
230
     * @return self
231
     */
232
    final public static function errorKeyNotFoundForValidator($key, AbstractValidator $validator)
233
    {
234
        /** @var self $exception */
235
        $exception = self::getNewExceptionInstance(
236
            self::ERROR_KEY_NOT_FOUND_FOR_VALIDATOR,
237
            [$key, get_class($validator)]
238
        );
239
240
        return $exception;
241
    }
242
243
    /**
244
     * @code 1487947224
245
     *
246
     * @param string     $fieldName
247
     * @param FormObject $formObject
248
     * @return self
249
     */
250
    final public static function equalsToFieldValidatorFieldNotFound($fieldName, FormObject $formObject)
251
    {
252
        /** @var self $exception */
253
        $exception = self::getNewExceptionInstance(
254
            self::FIELD_NOT_FOUND,
255
            [$fieldName, $formObject->getName(), $formObject->getClassName()]
256
        );
257
258
        return $exception;
259
    }
260
261
    /**
262
     * @code 1467623761
263
     *
264
     * @param string $fieldName
265
     * @return self
266
     */
267
    final public static function classViewHelperFieldNotFound($fieldName)
268
    {
269
        /** @var self $exception */
270
        $exception = self::getNewExceptionInstance(
271
            self::VIEW_HELPER_FIELD_NOT_FOUND,
272
            [$fieldName, ClassViewHelper::class, FieldViewHelper::class]
273
        );
274
275
        return $exception;
276
    }
277
278
    /**
279
     * @code 1467624152
280
     *
281
     * @param string $fieldName
282
     * @return self
283
     */
284
    final public static function formatMessageViewHelperFieldNotFound($fieldName)
285
    {
286
        /** @var self $exception */
287
        $exception = self::getNewExceptionInstance(
288
            self::VIEW_HELPER_FIELD_NOT_FOUND,
289
            [$fieldName, FormatMessageViewHelper::class, FieldViewHelper::class]
290
        );
291
292
        return $exception;
293
    }
294
295
    /**
296
     * @code 1465243586
297
     *
298
     * @param string $layoutName
299
     * @return self
300
     */
301
    final public static function fieldViewHelperLayoutNotFound($layoutName)
302
    {
303
        /** @var self $exception */
304
        $exception = self::getNewExceptionInstance(
305
            self::FIELD_VIEW_HELPER_LAYOUT_NOT_FOUND,
306
            [$layoutName]
307
        );
308
309
        return $exception;
310
    }
311
312
    /**
313
     * @code 1485867803
314
     *
315
     * @param string $layoutName
316
     * @param string $itemName
317
     * @return self
318
     */
319
    final public static function fieldViewHelperLayoutItemNotFound($layoutName, $itemName)
320
    {
321
        /** @var self $exception */
322
        $exception = self::getNewExceptionInstance(
323
            self::FIELD_VIEW_HELPER_LAYOUT_ITEM_NOT_FOUND,
324
            [$layoutName, $itemName]
325
        );
326
327
        return $exception;
328
    }
329
330
    /**
331
     * @code 1473084335
332
     *
333
     * @param string     $fieldName
334
     * @param FormObject $formObject
335
     * @return self
336
     */
337
    final public static function formatMessageViewHelperFieldNotFoundInForm($fieldName, FormObject $formObject)
338
    {
339
        /** @var self $exception */
340
        $exception = self::getNewExceptionInstance(
341
            self::FIELD_NOT_FOUND,
342
            [$fieldName, $formObject->getName(), $formObject->getClassName()]
343
        );
344
345
        return $exception;
346
    }
347
348
    /**
349
     * @code 1457441846
350
     *
351
     * @param string $controllerObjectName
352
     * @param string $actionName
353
     * @param string $formName
354
     * @return self
355
     */
356
    final public static function controllerServiceActionFormArgumentMissing($controllerObjectName, $actionName, $formName)
357
    {
358
        /** @var self $exception */
359
        $exception = self::getNewExceptionInstance(
360
            self::CONTROLLER_SERVICE_ACTION_FORM_ARGUMENT_MISSING,
361
            [$controllerObjectName, $actionName . 'Action', $formName]
362
        );
363
364
        return $exception;
365
    }
366
367
    /**
368
     * @code 1488988452
369
     *
370
     * @param string $name
371
     * @return self
372
     */
373
    final public static function slotClosureSlotNotFound($name)
374
    {
375
        /** @var self $exception */
376
        $exception = self::getNewExceptionInstance(
377
            self::SLOT_NOT_FOUND,
378
            [$name]
379
        );
380
381
        return $exception;
382
    }
383
384
    /**
385
     * @code 1489497046
386
     *
387
     * @param string $name
388
     * @return self
389
     */
390
    final public static function slotArgumentsSlotNotFound($name)
391
    {
392
        /** @var self $exception */
393
        $exception = self::getNewExceptionInstance(
394
            self::SLOT_NOT_FOUND,
395
            [$name]
396
        );
397
398
        return $exception;
399
    }
400
401
    /**
402
     * @code 1491997168
403
     *
404
     * @return self
405
     */
406
    final public static function formConfigurationNotFound()
407
    {
408
        /** @var self $exception */
409
        $exception = self::getNewExceptionInstance(
410
            self::FORM_CONFIGURATION_NOT_FOUND,
411
            [Configuration::class]
412
        );
413
414
        return $exception;
415
    }
416
417
    /**
418
     * @code 1494514957
419
     *
420
     * @param FormInterface $form
421
     * @return self
422
     */
423
    final public static function formObjectInstanceNotFound(FormInterface $form)
424
    {
425
        /** @var self $exception */
426
        $exception = self::getNewExceptionInstance(
427
            self::FORM_OBJECT_INSTANCE_NOT_FOUND,
428
            [get_class($form), FormObjectFactory::class]
429
        );
430
431
        return $exception;
432
    }
433
}
434