21
21
*/
22
22
class FilterValidator extends PropertyTemplateValidator
23
23
{
24
+ /** @var FilterInterface $filter */
25
+ protected $ filter ;
26
+
24
27
/**
25
28
* FilterValidator constructor.
26
29
*
@@ -31,6 +34,7 @@ class FilterValidator extends PropertyTemplateValidator
31
34
* @param TransformingFilterInterface|null $transformingFilter
32
35
*
33
36
* @throws SchemaException
37
+ * @throws ReflectionException
34
38
*/
35
39
public function __construct (
36
40
GeneratorConfiguration $ generatorConfiguration ,
@@ -39,6 +43,8 @@ public function __construct(
39
43
array $ filterOptions = [],
40
44
?TransformingFilterInterface $ transformingFilter = null
41
45
) {
46
+ $ this ->filter = $ filter ;
47
+
42
48
$ transformingFilter === null
43
49
? $ this ->validateFilterCompatibilityWithBaseType ($ filter , $ property )
44
50
: $ this ->validateFilterCompatibilityWithTransformedType ($ filter , $ transformingFilter , $ property );
@@ -51,7 +57,8 @@ public function __construct(
51
57
),
52
58
DIRECTORY_SEPARATOR . 'Validator ' . DIRECTORY_SEPARATOR . 'Filter.phptpl ' ,
53
59
[
54
- 'skipTransformedValuesCheck ' => false ,
60
+ 'skipTransformedValuesCheck ' => $ transformingFilter !== null ? '!$transformationFailed ' : '' ,
61
+ 'isTransformingFilter ' => $ filter instanceof TransformingFilterInterface,
55
62
// check if the given value has a type matched by the filter
56
63
'typeCheck ' => !empty ($ filter ->getAcceptedTypes ())
57
64
? '($value !== null && ( ' .
@@ -73,6 +80,19 @@ public function __construct(
73
80
);
74
81
}
75
82
83
+ /**
84
+ * Track if a transformation failed. If a transformation fails don't execute subsequent filter as they'd fail with
85
+ * an invalid type
86
+ *
87
+ * @return string
88
+ */
89
+ public function getValidatorSetUp (): string
90
+ {
91
+ return $ this ->filter instanceof TransformingFilterInterface
92
+ ? '$transformationFailed = false; '
93
+ : '' ;
94
+ }
95
+
76
96
/**
77
97
* Make sure the filter is only executed if a non-transformed value is provided.
78
98
* This is required as a setter (eg. for a string property which is modified by the DateTime filter into a DateTime
0 commit comments