|
11 | 11 | $succeededCompositionElements = {{ availableAmount }};
|
12 | 12 | $validatorComponentIndex = 0;
|
13 | 13 | $originalModelData = $value;
|
14 |
| - $originalPropertyValidationState = $this->_propertyValidationState ?? []; |
15 | 14 | $proposedValue = null;
|
16 | 15 |
|
| 16 | + {% if not generatorConfiguration.isImmutable() %} |
| 17 | + $originalPropertyValidationState = $this->_propertyValidationState ?? []; |
| 18 | + {% endif %} |
| 19 | + |
17 | 20 | {% if generatorConfiguration.collectErrors() %}
|
18 | 21 | $originalErrorRegistry = $this->_errorRegistry;
|
19 | 22 | {% endif %}
|
20 | 23 |
|
21 | 24 | {% foreach compositionProperties as compositionProperty %}
|
22 | 25 | try {
|
23 |
| - // check if the state of the validator is already known. |
24 |
| - // If none of the properties affected by the validator are changed the validator must not be re-evaluated |
25 |
| - if (isset($validatorIndex) && |
26 |
| - isset($this->_propertyValidationState[$validatorIndex][$validatorComponentIndex]) && |
27 |
| - !array_intersect( |
28 |
| - array_keys($modifiedModelData), |
29 |
| - [ |
30 |
| - {% foreach compositionProperty.getAffectedObjectProperties() as affectedObjectProperty %} |
31 |
| - '{{ affectedObjectProperty.getName() }}', |
32 |
| - {% endforeach %} |
33 |
| - ] |
34 |
| - ) |
35 |
| - ) { |
36 |
| - {% if generatorConfiguration.collectErrors() %} |
37 |
| - $compositionErrorCollection[] = $this->_propertyValidationState[$validatorIndex][$validatorComponentIndex]; |
38 |
| - {% endif %} |
39 |
| - |
40 |
| - if ({% if generatorConfiguration.collectErrors() %} |
41 |
| - $this->_propertyValidationState[$validatorIndex][$validatorComponentIndex]->getErrors() |
42 |
| - {% else %} |
43 |
| - $this->_propertyValidationState[$validatorIndex][$validatorComponentIndex] !== true |
44 |
| - {% endif %} |
| 26 | + {% if not generatorConfiguration.isImmutable() %} |
| 27 | + // check if the state of the validator is already known. |
| 28 | + // If none of the properties affected by the validator are changed the validator must not be re-evaluated |
| 29 | + if (isset($validatorIndex) && |
| 30 | + isset($this->_propertyValidationState[$validatorIndex][$validatorComponentIndex]) && |
| 31 | + !array_intersect( |
| 32 | + array_keys($modifiedModelData), |
| 33 | + [ |
| 34 | + {% foreach compositionProperty.getAffectedObjectProperties() as affectedObjectProperty %} |
| 35 | + '{{ affectedObjectProperty.getName() }}', |
| 36 | + {% endforeach %} |
| 37 | + ] |
| 38 | + ) |
45 | 39 | ) {
|
46 |
| - throw new \Exception(); |
47 |
| - } |
48 |
| - } else { |
| 40 | + {% if generatorConfiguration.collectErrors() %} |
| 41 | + $compositionErrorCollection[] = $this->_propertyValidationState[$validatorIndex][$validatorComponentIndex]; |
| 42 | + {% endif %} |
| 43 | + |
| 44 | + if ({% if generatorConfiguration.collectErrors() %} |
| 45 | + $this->_propertyValidationState[$validatorIndex][$validatorComponentIndex]->getErrors() |
| 46 | + {% else %} |
| 47 | + $this->_propertyValidationState[$validatorIndex][$validatorComponentIndex] !== true |
| 48 | + {% endif %} |
| 49 | + ) { |
| 50 | + throw new \Exception(); |
| 51 | + } |
| 52 | + } else { |
| 53 | + {% endif %} |
| 54 | + |
49 | 55 | {% if generatorConfiguration.collectErrors() %}
|
50 | 56 | // collect errors for each composition element
|
51 | 57 | $this->_errorRegistry = new {{ viewHelper.getSimpleClassName(generatorConfiguration.getErrorRegistryClass()) }}();
|
|
66 | 72 |
|
67 | 73 | {% if generatorConfiguration.collectErrors() %}
|
68 | 74 | $compositionErrorCollection[] = $this->_errorRegistry;
|
69 |
| - if (isset($validatorIndex)) { |
70 |
| - $this->_propertyValidationState[$validatorIndex][$validatorComponentIndex] = $this->_errorRegistry; |
71 |
| - } |
| 75 | + |
| 76 | + {% if not generatorConfiguration.isImmutable() %} |
| 77 | + if (isset($validatorIndex)) { |
| 78 | + $this->_propertyValidationState[$validatorIndex][$validatorComponentIndex] = $this->_errorRegistry; |
| 79 | + } |
| 80 | + {% endif %} |
72 | 81 |
|
73 | 82 | // an error inside the composed validation occurred. Throw an exception to count the validity of the
|
74 | 83 | // composition item
|
|
81 | 90 | $proposedValue = $proposedValue ?? $value;
|
82 | 91 | {% endif %}
|
83 | 92 |
|
| 93 | + {% if not generatorConfiguration.isImmutable() %} |
84 | 94 | {% if not generatorConfiguration.collectErrors() %}
|
85 | 95 | if (isset($validatorIndex)) {
|
86 | 96 | $this->_propertyValidationState[$validatorIndex][$validatorComponentIndex] = true;
|
87 | 97 | }
|
88 | 98 | {% endif %}
|
89 | 99 | }
|
| 100 | + {% endif %} |
90 | 101 | } catch (\Exception $e) {
|
91 | 102 | {% if not generatorConfiguration.collectErrors() %}
|
92 | 103 | if (isset($validatorIndex)) {
|
|
121 | 132 |
|
122 | 133 | $result = !({{ composedValueValidation }});
|
123 | 134 |
|
124 |
| - if ($result) { |
125 |
| - $this->_propertyValidationState = $originalPropertyValidationState; |
126 |
| - } |
| 135 | + {% if not generatorConfiguration.isImmutable() %} |
| 136 | + if ($result) { |
| 137 | + $this->_propertyValidationState = $originalPropertyValidationState; |
| 138 | + } |
| 139 | + {% endif %} |
127 | 140 |
|
128 | 141 | return $result;
|
129 | 142 | })($value)
|
0 commit comments