@@ -34,14 +34,19 @@ public function fillModel(array $dto, $model, string $mapName = 'dto'): void
34
34
protected function resolveRefHydrate (array $ dto , array $ rules ): array
35
35
{
36
36
foreach ($ dto as $ key => $ value ) {
37
- if ($ value !== null && array_key_exists ( $ key , $ rules) && array_key_exists ( ' ref ' , $ rules [ $ key] )) {
37
+ if ($ value !== null && $ this -> checkRuleForHydrate ( $ rules , $ key )) {
38
38
$ dto [$ key ] = $ this ->hydrateRefValue ($ this ->getRefRules ($ rules [$ key ]), $ value , $ rules [$ key ]);
39
39
}
40
40
}
41
41
42
42
return $ dto ;
43
43
}
44
44
45
+ protected function checkRuleForHydrate (array $ rules , string $ key ): bool
46
+ {
47
+ return array_key_exists ($ key , $ rules ) && array_key_exists ('ref ' , $ rules [$ key ]);
48
+ }
49
+
45
50
protected function getRefRules (array $ rule )
46
51
{
47
52
return $ this ->mapsManager ->getMap ($ rule ['ref ' ]['model ' ], $ rule ['ref ' ]['map ' ]);
@@ -94,8 +99,8 @@ public function toDTO($model, string $mapName = 'dto', array $excludeFields = []
94
99
protected function resolveRefExtract (array $ dto , array $ rules ): array
95
100
{
96
101
foreach ($ dto as $ key => $ value ) {
97
- $ rule = $ rules[ $ key];
98
- if ( $ value !== null && array_key_exists ( ' ref ' , $ rule)) {
102
+ if ( $ value !== null && $ this -> checkRuleForHydrate ( $ rules, $ key)) {
103
+ $ rule = $ rules [ $ key ];
99
104
$ refRules = $ this ->mapsManager ->getMap ($ rule ['ref ' ]['model ' ], $ rule ['ref ' ]['map ' ]);
100
105
$ refDTO = $ this ->extractRefValue ($ refRules , $ value , $ rule );
101
106
$ dto [$ key ] = $ refDTO ;
0 commit comments