Skip to content

Commit

Permalink
Added serializedObjectToArray
Browse files Browse the repository at this point in the history
  • Loading branch information
nilportugues committed Jun 30, 2016
1 parent 91f8146 commit 0379e11
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Transformer/Helpers/RecursiveRenamerHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,33 @@ private static function renameMatchedClassKeys(array &$mappings, array &$array,
}
}
}

/**
* Transforms unmapped objects (Serializer::CLASS_IDENTIFIER_KEY) to arrays (Serializer::MAP_TYPE)
*
* @param array $array
* @param \NilPortugues\Api\Mapping\Mapping[] $mappings
* @return array
*/
public static function serializedObjectToArray(array &$array, array &$mappings)
{
foreach ($array as $key => &$value) {
if ($key === Serializer::CLASS_IDENTIFIER_KEY) {
$type = $array[Serializer::CLASS_IDENTIFIER_KEY];
if (empty($mappings[$type])) {
unset($array[Serializer::CLASS_IDENTIFIER_KEY]);
}
}

if (is_array($value)) {
foreach($value as $k => &$v) {
if (is_array($v)) {
$v = self::serializedObjectToArray($v, $mappings);
}
}
}
}

return $array;
}
}

0 comments on commit 0379e11

Please sign in to comment.