Skip to content

Commit 0379e11

Browse files
committed
Added serializedObjectToArray
1 parent 91f8146 commit 0379e11

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/Transformer/Helpers/RecursiveRenamerHelper.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,33 @@ private static function renameMatchedClassKeys(array &$mappings, array &$array,
7676
}
7777
}
7878
}
79+
80+
/**
81+
* Transforms unmapped objects (Serializer::CLASS_IDENTIFIER_KEY) to arrays (Serializer::MAP_TYPE)
82+
*
83+
* @param array $array
84+
* @param \NilPortugues\Api\Mapping\Mapping[] $mappings
85+
* @return array
86+
*/
87+
public static function serializedObjectToArray(array &$array, array &$mappings)
88+
{
89+
foreach ($array as $key => &$value) {
90+
if ($key === Serializer::CLASS_IDENTIFIER_KEY) {
91+
$type = $array[Serializer::CLASS_IDENTIFIER_KEY];
92+
if (empty($mappings[$type])) {
93+
unset($array[Serializer::CLASS_IDENTIFIER_KEY]);
94+
}
95+
}
96+
97+
if (is_array($value)) {
98+
foreach($value as $k => &$v) {
99+
if (is_array($v)) {
100+
$v = self::serializedObjectToArray($v, $mappings);
101+
}
102+
}
103+
}
104+
}
105+
106+
return $array;
107+
}
79108
}

0 commit comments

Comments
 (0)