From 7be25f92bbb579c491a27bf07e0b1a3875ee7120 Mon Sep 17 00:00:00 2001 From: ornicar Date: Tue, 26 Apr 2011 11:24:21 -0700 Subject: [PATCH] Make the automatic object to array transformer generate deep arrays --- Transformer/ObjectToArrayAutomaticTransformer.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Transformer/ObjectToArrayAutomaticTransformer.php b/Transformer/ObjectToArrayAutomaticTransformer.php index cc31c3c..2ab8e84 100644 --- a/Transformer/ObjectToArrayAutomaticTransformer.php +++ b/Transformer/ObjectToArrayAutomaticTransformer.php @@ -38,13 +38,13 @@ class ObjectToArrayAutomaticTransformer implements ObjectToArrayTransformerInter public function normalizeValue($value) { if (is_array($value) || $value instanceof Traversable || $value instanceof ArrayAccess) { - $values = array(); - foreach ($value as $v) { - $values[] = (string) $v; - } - $value = implode(', ', $values); + $value = array_map(function($v) { + return (string) $v; + }, is_array($value) ? $value : iterator_to_array($value)); + } else { + $value = (string) $value; } - return (string) $value; + return $value; } }