Completed
Push — feature/improve-form-definitio... ( 9e9d4e...0c6558 )
by Romain
02:17
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\Condition\Activation;
21
use Romm\Formz\Form\Definition\Field\Field;
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\FormObjectFactory;
26
use Romm\Formz\Validation\Validator\AbstractValidator;
27
use Romm\Formz\ViewHelpers\ClassViewHelper;
28
use Romm\Formz\ViewHelpers\FieldViewHelper;
29
use Romm\Formz\ViewHelpers\FormatMessageViewHelper;
30
31
class EntryNotFoundException extends FormzException
32
{
33
    const FIELD_NOT_FOUND = 'The field "%s" was not found in the form "%s" with class "%s".';
34
35
    const CONDITION_NOT_FOUND = 'Trying to access a condition which is not registered: "%s". Here is a list of all currently registered conditions: "%s".';
36
37
    const FORM_ADD_CONDITION_NOT_FOUND = 'Trying to add a condition "%s" which is not registered to the form definition. Here is a list of all currently registered conditions: "%s".';
38
39
    const ACTIVATION_ADD_CONDITION_NOT_FOUND = 'Trying to add a condition "%s" which is not registered to the activation. Here is a list of all currently registered conditions: "%s".';
40
41
    const INSTANTIATE_CONDITION_NOT_FOUND = 'Trying to instantiate a condition which is not registered: "%s". Here is a list of all currently registered conditions: "%s".';
42
43
    const ACTIVATION_CONDITION_NOT_FOUND = 'No condition "%s" was found.';
44
45
    const CONFIGURATION_FIELD_NOT_FOUND = 'The field "%s" was not found. Please use the function `%s::hasField()` before.';
46
47
    const VALIDATOR_NOT_FOUND = 'The validation "%s" was not found. Please use the function `%s::hasValidator()` before.';
48
49
    const BEHAVIOUR_NOT_FOUND = 'The behaviour "%s" was not found. Please use the function `%s::hasBehaviour()` before.';
50
51
    const VIEW_LAYOUT_NOT_FOUND = 'The layout "%s" was not found. Please use the function `%s::hasLayout()` before.';
52
53
    const VIEW_LAYOUT_ITEM_NOT_FOUND = 'The layout item "%s" was not found. Please use the function `%s::hasItem()` before.';
54
55
    const VIEW_CLASS_NOT_FOUND = 'The class "%s" was not found. Please use the function `%s::hasItem()` before.';
56
57
    const VALIDATION_NOT_FOUND_FOR_FIELD = 'The field "%s" does not have a rule "%s".';
58
59
    const ERROR_KEY_NOT_FOUND_FOR_VALIDATOR = 'The error key "%s" does not exist for the validator "%s".';
60
61
    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.';
62
63
    const FIELD_VIEW_HELPER_LAYOUT_NOT_FOUND = 'The layout "%s" could not be found. Please check your TypoScript configuration.';
64
65
    const FIELD_VIEW_HELPER_LAYOUT_ITEM_NOT_FOUND = 'The layout "%s" does not have an item "%s".';
66
67
    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.';
68
69
    const SLOT_NOT_FOUND = 'No slot "%s" was found.';
70
71
    const FORM_CONFIGURATION_NOT_FOUND = 'The configuration for form of class "%s" was not found. Please use the function `%s::hasForm()` before.';
72
73
    const CONDITION_NOT_FOUND_IN_DEFINITION = 'The condition "%s" was not found in the form definition. Please use the function `%s::hasCondition()` before.';
74
75
    const CONDITION_DOES_NOT_EXIST = 'The condition "%s" does not exist';
76
77
    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()".';
78
79
    /**
80
     * @code 1472650209
81
     *
82
     * @param string $identifier
83
     * @param array  $list
84
     * @return self
85
     */
86
    final public static function conditionNotFound($identifier, array $list)
87
    {
88
        /** @var self $exception */
89
        $exception = self::getNewExceptionInstance(
90
            self::CONDITION_NOT_FOUND,
91
            [
92
                $identifier,
93
                implode('" ,"', array_keys($list))
94
            ]
95
        );
96
97
        return $exception;
98
    }
99
100
    /**
101
     * @code 1493890438
102
     *
103
     * @param string $identifier
104
     * @param array  $list
105
     * @return self
106
     */
107
    final public static function formAddConditionNotFound($identifier, array $list)
108
    {
109
        /** @var self $exception */
110
        $exception = self::getNewExceptionInstance(
111
            self::FORM_ADD_CONDITION_NOT_FOUND,
112
            [
113
                $identifier,
114
                implode('" ,"', array_keys($list))
115
            ]
116
        );
117
118
        return $exception;
119
    }
120
121
    /**
122
     * @code 1494329341
123
     *
124
     * @param string $identifier
125
     * @param array  $list
126
     * @return self
127
     */
128
    final public static function activationAddConditionNotFound($identifier, array $list)
129
    {
130
        /** @var self $exception */
131
        $exception = self::getNewExceptionInstance(
132
            self::ACTIVATION_ADD_CONDITION_NOT_FOUND,
133
            [
134
                $identifier,
135
                implode('" ,"', array_keys($list))
136
            ]
137
        );
138
139
        return $exception;
140
    }
141
142
    /**
143
     * @code 1493890825
144
     *
145
     * @param string $identifier
146
     * @param array  $list
147
     * @return self
148
     */
149
    final public static function instantiateConditionNotFound($identifier, array $list)
150
    {
151
        /** @var self $exception */
152
        $exception = self::getNewExceptionInstance(
153
            self::INSTANTIATE_CONDITION_NOT_FOUND,
154
            [
155
                $identifier,
156
                implode('" ,"', array_keys($list))
157
            ]
158
        );
159
160
        return $exception;
161
    }
162
163
    /**
164
     * @code 1488482191
165
     *
166
     * @param string $name
167
     * @return self
168
     */
169
    final public static function activationConditionNotFound($name)
170
    {
171
        /** @var self $exception */
172
        $exception = self::getNewExceptionInstance(
173
            self::ACTIVATION_CONDITION_NOT_FOUND,
174
            [$name]
175
        );
176
177
        return $exception;
178
    }
179
180
    /**
181
     * @code 1489765133
182
     *
183
     * @param string $name
184
     * @return self
185
     */
186
    final public static function configurationFieldNotFound($name)
187
    {
188
        /** @var self $exception */
189
        $exception = self::getNewExceptionInstance(
190
            self::CONFIGURATION_FIELD_NOT_FOUND,
191
            [$name, FormDefinition::class]
192
        );
193
194
        return $exception;
195
    }
196
197
    /**
198
     * @code 1487672276
199
     *
200
     * @param string $name
201
     * @return self
202
     */
203
    final public static function validatorNotFound($name)
204
    {
205
        /** @var self $exception */
206
        $exception = self::getNewExceptionInstance(
207
            self::VALIDATOR_NOT_FOUND,
208
            [$name, Field::class]
209
        );
210
211
        return $exception;
212
    }
213
214
    /**
215
     * @code 1494685753
216
     *
217
     * @param string $name
218
     * @return self
219
     */
220
    final public static function behaviourNotFound($name)
221
    {
222
        /** @var self $exception */
223
        $exception = self::getNewExceptionInstance(
224
            self::BEHAVIOUR_NOT_FOUND,
225
            [$name, Field::class]
226
        );
227
228
        return $exception;
229
    }
230
231
    /**
232
     * @code 1489753952
233
     *
234
     * @param string $name
235
     * @return self
236
     */
237
    final public static function viewLayoutNotFound($name)
238
    {
239
        /** @var self $exception */
240
        $exception = self::getNewExceptionInstance(
241
            self::VIEW_LAYOUT_NOT_FOUND,
242
            [$name, View::class]
243
        );
244
245
        return $exception;
246
    }
247
248
    /**
249
     * @code 1489757511
250
     *
251
     * @param string $name
252
     * @return self
253
     */
254
    final public static function viewLayoutItemNotFound($name)
255
    {
256
        /** @var self $exception */
257
        $exception = self::getNewExceptionInstance(
258
            self::VIEW_LAYOUT_ITEM_NOT_FOUND,
259
            [$name, LayoutGroup::class]
260
        );
261
262
        return $exception;
263
    }
264
265
    /**
266
     * @code 1489754909
267
     *
268
     * @param string $name
269
     * @return self
270
     */
271
    final public static function viewClassNotFound($name)
272
    {
273
        /** @var self $exception */
274
        $exception = self::getNewExceptionInstance(
275
            self::VIEW_CLASS_NOT_FOUND,
276
            [$name, ViewClass::class]
277
        );
278
279
        return $exception;
280
    }
281
282
    /**
283
     * @code 1487672956
284
     *
285
     * @param string $validationName
286
     * @param string $fieldName
287
     * @return self
288
     */
289
    final public static function ajaxControllerValidationNotFoundForField($validationName, $fieldName)
290
    {
291
        /** @var self $exception */
292
        $exception = self::getNewExceptionInstance(
293
            self::VALIDATION_NOT_FOUND_FOR_FIELD,
294
            [$fieldName, $validationName]
295
        );
296
297
        return $exception;
298
    }
299
300
    /**
301
     * @code 1487671603
302
     *
303
     * @param string     $fieldName
304
     * @param FormObject $formObject
305
     * @return self
306
     */
307
    final public static function ajaxControllerFieldNotFound($fieldName, FormObject $formObject)
308
    {
309
        /** @var self $exception */
310
        $exception = self::getNewExceptionInstance(
311
            self::FIELD_NOT_FOUND,
312
            [$fieldName, $formObject->getName(), $formObject->getClassName()]
313
        );
314
315
        return $exception;
316
    }
317
318
    /**
319
     * @code 1455272659
320
     *
321
     * @param string            $key
322
     * @param AbstractValidator $validator
323
     * @return self
324
     */
325
    final public static function errorKeyNotFoundForValidator($key, AbstractValidator $validator)
326
    {
327
        /** @var self $exception */
328
        $exception = self::getNewExceptionInstance(
329
            self::ERROR_KEY_NOT_FOUND_FOR_VALIDATOR,
330
            [$key, get_class($validator)]
331
        );
332
333
        return $exception;
334
    }
335
336
    /**
337
     * @code 1487947224
338
     *
339
     * @param string     $fieldName
340
     * @param FormObject $formObject
341
     * @return self
342
     */
343
    final public static function equalsToFieldValidatorFieldNotFound($fieldName, FormObject $formObject)
344
    {
345
        /** @var self $exception */
346
        $exception = self::getNewExceptionInstance(
347
            self::FIELD_NOT_FOUND,
348
            [$fieldName, $formObject->getName(), $formObject->getClassName()]
349
        );
350
351
        return $exception;
352
    }
353
354
    /**
355
     * @code 1467623761
356
     *
357
     * @param string $fieldName
358
     * @return self
359
     */
360
    final public static function classViewHelperFieldNotFound($fieldName)
361
    {
362
        /** @var self $exception */
363
        $exception = self::getNewExceptionInstance(
364
            self::VIEW_HELPER_FIELD_NOT_FOUND,
365
            [$fieldName, ClassViewHelper::class, FieldViewHelper::class]
366
        );
367
368
        return $exception;
369
    }
370
371
    /**
372
     * @code 1467624152
373
     *
374
     * @param string $fieldName
375
     * @return self
376
     */
377
    final public static function formatMessageViewHelperFieldNotFound($fieldName)
378
    {
379
        /** @var self $exception */
380
        $exception = self::getNewExceptionInstance(
381
            self::VIEW_HELPER_FIELD_NOT_FOUND,
382
            [$fieldName, FormatMessageViewHelper::class, FieldViewHelper::class]
383
        );
384
385
        return $exception;
386
    }
387
388
    /**
389
     * @code 1465243586
390
     *
391
     * @param string $layoutName
392
     * @return self
393
     */
394
    final public static function fieldViewHelperLayoutNotFound($layoutName)
395
    {
396
        /** @var self $exception */
397
        $exception = self::getNewExceptionInstance(
398
            self::FIELD_VIEW_HELPER_LAYOUT_NOT_FOUND,
399
            [$layoutName]
400
        );
401
402
        return $exception;
403
    }
404
405
    /**
406
     * @code 1485867803
407
     *
408
     * @param string $layoutName
409
     * @param string $itemName
410
     * @return self
411
     */
412
    final public static function fieldViewHelperLayoutItemNotFound($layoutName, $itemName)
413
    {
414
        /** @var self $exception */
415
        $exception = self::getNewExceptionInstance(
416
            self::FIELD_VIEW_HELPER_LAYOUT_ITEM_NOT_FOUND,
417
            [$layoutName, $itemName]
418
        );
419
420
        return $exception;
421
    }
422
423
    /**
424
     * @code 1473084335
425
     *
426
     * @param string     $fieldName
427
     * @param FormObject $formObject
428
     * @return self
429
     */
430
    final public static function formatMessageViewHelperFieldNotFoundInForm($fieldName, FormObject $formObject)
431
    {
432
        /** @var self $exception */
433
        $exception = self::getNewExceptionInstance(
434
            self::FIELD_NOT_FOUND,
435
            [$fieldName, $formObject->getName(), $formObject->getClassName()]
436
        );
437
438
        return $exception;
439
    }
440
441
    /**
442
     * @code 1457441846
443
     *
444
     * @param string $controllerObjectName
445
     * @param string $actionName
446
     * @param string $formName
447
     * @return self
448
     */
449
    final public static function controllerServiceActionFormArgumentMissing($controllerObjectName, $actionName, $formName)
450
    {
451
        /** @var self $exception */
452
        $exception = self::getNewExceptionInstance(
453
            self::CONTROLLER_SERVICE_ACTION_FORM_ARGUMENT_MISSING,
454
            [$controllerObjectName, $actionName . 'Action', $formName]
455
        );
456
457
        return $exception;
458
    }
459
460
    /**
461
     * @code 1488988452
462
     *
463
     * @param string $name
464
     * @return self
465
     */
466
    final public static function slotClosureSlotNotFound($name)
467
    {
468
        /** @var self $exception */
469
        $exception = self::getNewExceptionInstance(
470
            self::SLOT_NOT_FOUND,
471
            [$name]
472
        );
473
474
        return $exception;
475
    }
476
477
    /**
478
     * @code 1489497046
479
     *
480
     * @param string $name
481
     * @return self
482
     */
483
    final public static function slotArgumentsSlotNotFound($name)
484
    {
485
        /** @var self $exception */
486
        $exception = self::getNewExceptionInstance(
487
            self::SLOT_NOT_FOUND,
488
            [$name]
489
        );
490
491
        return $exception;
492
    }
493
494
    /**
495
     * @code 1491997168
496
     *
497
     * @return self
498
     */
499
    final public static function formConfigurationNotFound()
500
    {
501
        /** @var self $exception */
502
        $exception = self::getNewExceptionInstance(
503
            self::FORM_CONFIGURATION_NOT_FOUND,
504
            [Configuration::class]
505
        );
506
507
        return $exception;
508
    }
509
510
    /**
511
     * @code 1493881671
512
     *
513
     * @param string $name
514
     * @return self
515
     */
516
    final public static function conditionNotFoundInDefinition($name)
517
    {
518
        /** @var self $exception */
519
        $exception = self::getNewExceptionInstance(
520
            self::CONDITION_NOT_FOUND_IN_DEFINITION,
521
            [$name, Configuration::class]
522
        );
523
524
        return $exception;
525
    }
526
527
    /**
528
     * @code 1494514957
529
     *
530
     * @param FormInterface $form
531
     * @return self
532
     */
533
    final public static function formObjectInstanceNotFound(FormInterface $form)
534
    {
535
        /** @var self $exception */
536
        $exception = self::getNewExceptionInstance(
537
            self::FORM_OBJECT_INSTANCE_NOT_FOUND,
538
            [get_class($form), FormObjectFactory::class]
539
        );
540
541
        return $exception;
542
    }
543
}
544