|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bdf\Form\Validator; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use Symfony\Component\Validator\Constraint; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @internal |
|
10
|
|
|
*/ |
|
11
|
|
|
final class TransformerExceptionConstraint extends Constraint |
|
12
|
|
|
{ |
|
13
|
|
|
const TRANSFORM_ERROR = 'b5acab45-80b0-4808-8784-6577e37ac869'; |
|
14
|
|
|
|
|
15
|
|
|
/** @var array<string, string> */ |
|
16
|
|
|
protected static $errorNames = [ |
|
17
|
|
|
self::TRANSFORM_ERROR => 'TRANSFORM_ERROR', |
|
18
|
|
|
]; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The error message. If null, the exception's message will be taken |
|
22
|
|
|
* |
|
23
|
|
|
* @var string|null |
|
24
|
|
|
*/ |
|
25
|
|
|
public $message = null; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The error code |
|
29
|
|
|
* |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
public $code = self::TRANSFORM_ERROR; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* The transformer exception |
|
36
|
|
|
* |
|
37
|
|
|
* @var Exception |
|
38
|
|
|
*/ |
|
39
|
|
|
public $exception; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Use to validate the exception |
|
43
|
|
|
* If the closure returns false, the transformer error will be ignored |
|
44
|
|
|
* |
|
45
|
|
|
* Note: To change the message or code corresponding to the exception, set code or message attributes on the constraint |
|
46
|
|
|
* |
|
47
|
|
|
* @var callable(mixed,TransformerExceptionConstraint,\Bdf\Form\ElementInterface):bool|null |
|
48
|
|
|
*/ |
|
49
|
|
|
public $validationCallback; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Does the transformation error should be ignored ? |
|
53
|
|
|
* If true, the transformation exception will be ignored |
|
54
|
|
|
* |
|
55
|
|
|
* @var bool |
|
56
|
|
|
*/ |
|
57
|
|
|
public $ignoreException = false; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
*/ |
|
62
|
390 |
|
public function getDefaultOption() |
|
63
|
|
|
{ |
|
64
|
390 |
|
return 'exception'; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Set the exception on the constraint |
|
69
|
|
|
* |
|
70
|
|
|
* @param Exception $exception |
|
71
|
|
|
* @return static |
|
72
|
|
|
*/ |
|
73
|
21 |
|
public function withException(Exception $exception): self |
|
74
|
|
|
{ |
|
75
|
21 |
|
$constraint = clone $this; |
|
76
|
21 |
|
$constraint->exception = $exception; |
|
77
|
|
|
|
|
78
|
21 |
|
return $constraint; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|