|
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\Form\FormInterface; |
|
17
|
|
|
use Romm\Formz\Middleware\Item\AbstractMiddleware; |
|
18
|
|
|
use Romm\Formz\Middleware\Signal\SendsMiddlewareSignal; |
|
19
|
|
|
use Romm\Formz\Persistence\PersistenceInterface; |
|
20
|
|
|
|
|
21
|
|
|
class InvalidEntryException extends FormzException |
|
22
|
|
|
{ |
|
23
|
|
|
const INVALID_CSS_CLASS_NAMESPACE = 'The class "%s" is not valid: the namespace of the error must be one of the following: %s.'; |
|
24
|
|
|
|
|
25
|
|
|
const MIDDLEWARE_NOT_SENDING_SIGNALS = 'The middleware "%s" does not implement interface "%s", therefore it can not dispatch signals.'; |
|
26
|
|
|
|
|
27
|
|
|
const PERSISTENCE_INVALID_ENTRY_FETCHED = 'The form instance fetched from persistence service "%s" is not valid: an instance of "%s" is awaited, result is of type "%s".'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @code 1467623504 |
|
31
|
|
|
* |
|
32
|
|
|
* @param string $className |
|
33
|
|
|
* @param array $acceptedClassesNameSpace |
|
34
|
|
|
* @return self |
|
35
|
|
|
*/ |
|
36
|
|
|
final public static function invalidCssClassNamespace($className, array $acceptedClassesNameSpace) |
|
37
|
|
|
{ |
|
38
|
|
|
/** @var self $exception */ |
|
39
|
|
|
$exception = self::getNewExceptionInstance( |
|
40
|
|
|
self::INVALID_CSS_CLASS_NAMESPACE, |
|
41
|
|
|
[$className, implode(', ', $acceptedClassesNameSpace)] |
|
42
|
|
|
); |
|
43
|
|
|
|
|
44
|
|
|
return $exception; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @code 1490798324 |
|
49
|
|
|
* |
|
50
|
|
|
* @param AbstractMiddleware $middleware |
|
51
|
|
|
* @return InvalidEntryException |
|
52
|
|
|
*/ |
|
53
|
|
|
final public static function middlewareNotSendingSignals(AbstractMiddleware $middleware) |
|
54
|
|
|
{ |
|
55
|
|
|
/** @var self $exception */ |
|
56
|
|
|
$exception = self::getNewExceptionInstance( |
|
57
|
|
|
self::MIDDLEWARE_NOT_SENDING_SIGNALS, |
|
58
|
|
|
[get_class($middleware), SendsMiddlewareSignal::class] |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
return $exception; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @code 1491294224 |
|
66
|
|
|
* |
|
67
|
|
|
* @param PersistenceInterface $persistence |
|
68
|
|
|
* @param mixed $result |
|
69
|
|
|
* @return InvalidEntryException |
|
70
|
|
|
*/ |
|
71
|
|
|
final public static function persistenceInvalidEntryFetched(PersistenceInterface $persistence, $result) |
|
72
|
|
|
{ |
|
73
|
|
|
$resultType = is_object($result) |
|
74
|
|
|
? get_class($result) |
|
75
|
|
|
: gettype($result); |
|
76
|
|
|
|
|
77
|
|
|
/** @var self $exception */ |
|
78
|
|
|
$exception = self::getNewExceptionInstance( |
|
79
|
|
|
self::PERSISTENCE_INVALID_ENTRY_FETCHED, |
|
80
|
|
|
[get_class($persistence), FormInterface::class, $resultType] |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
return $exception; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|