File tree Expand file tree Collapse file tree 4 files changed +43
-6
lines changed Expand file tree Collapse file tree 4 files changed +43
-6
lines changed Original file line number Diff line number Diff line change 7
7
/**
8
8
* CakePHP validation error convert.
9
9
*/
10
- final class CakeValidationValidationConverter implements ValidationConverterInterface
10
+ final class CakeValidationConverter implements ValidationConverterInterface
11
11
{
12
12
/**
13
13
* Create validation result from array with errors.
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Selective \Validation \Converter ;
4
+
5
+ use Selective \Validation \ValidationResult ;
6
+
7
+ /**
8
+ * Valitron validation error collector.
9
+ */
10
+ final class ValitronValidationValidationConverter implements ValidationConverterInterface
11
+ {
12
+ /**
13
+ * Create validation result from array with errors.
14
+ *
15
+ * @param array $errors The errors
16
+ *
17
+ * @return ValidationResult The result
18
+ */
19
+ public function createValidationResult ($ errors ): ValidationResult
20
+ {
21
+ $ result = new ValidationResult ();
22
+
23
+ $ fields = [];
24
+
25
+ foreach ($ errors as $ field => $ message ) {
26
+ if (isset ($ fields [$ field ])) {
27
+ continue ;
28
+ }
29
+
30
+ $ result ->addError ($ field , $ message );
31
+
32
+ $ fields [$ field ] = 1 ;
33
+ }
34
+
35
+ return $ result ;
36
+ }
37
+ }
Original file line number Diff line number Diff line change 3
3
namespace Selective \Validation \Factory ;
4
4
5
5
use Cake \Validation \Validator ;
6
- use Selective \Validation \Converter \CakeValidationValidationConverter ;
6
+ use Selective \Validation \Converter \CakeValidationConverter ;
7
7
use Selective \Validation \ValidationResult ;
8
8
9
9
/**
@@ -30,6 +30,6 @@ public function createValidator(): Validator
30
30
*/
31
31
public function createValidationResult (array $ errors ): ValidationResult
32
32
{
33
- return (new CakeValidationValidationConverter ())->createValidationResult ($ errors );
33
+ return (new CakeValidationConverter ())->createValidationResult ($ errors );
34
34
}
35
35
}
Original file line number Diff line number Diff line change 3
3
namespace Selective \Validation \Test \Converter ;
4
4
5
5
use PHPUnit \Framework \TestCase ;
6
- use Selective \Validation \Converter \CakeValidationValidationConverter ;
6
+ use Selective \Validation \Converter \CakeValidationConverter ;
7
7
use Selective \Validation \Transformer \ErrorDetailsResultTransformer ;
8
8
use Selective \Validation \ValidationResult ;
9
9
@@ -31,7 +31,7 @@ private function getValidationResultAsArray(ValidationResult $validationResult):
31
31
*/
32
32
public function testCreateResultFromErrorsSimple ()
33
33
{
34
- $ result = (new CakeValidationValidationConverter ())->createValidationResult ([
34
+ $ result = (new CakeValidationConverter ())->createValidationResult ([
35
35
'first_name ' => [
36
36
'_empty ' => 'This field cannot be left empty ' ,
37
37
],
@@ -104,7 +104,7 @@ public function testCreateResultFromErrorsSimple()
104
104
*/
105
105
public function testCreateResultFromErrorsNestedArray ()
106
106
{
107
- $ result = (new CakeValidationValidationConverter ())->createValidationResult ([
107
+ $ result = (new CakeValidationConverter ())->createValidationResult ([
108
108
'bills ' => [
109
109
0 => [
110
110
'billing_number ' => [
You can’t perform that action at this time.
0 commit comments