From d24003598376da92a40dbce13639ad2942905607 Mon Sep 17 00:00:00 2001 From: Iain Mckay Date: Wed, 25 Jan 2017 11:52:23 +0100 Subject: [PATCH] WIP --- src/Mapper/CastingObjectMapper.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Mapper/CastingObjectMapper.php b/src/Mapper/CastingObjectMapper.php index 64c490e..1ae0d4d 100644 --- a/src/Mapper/CastingObjectMapper.php +++ b/src/Mapper/CastingObjectMapper.php @@ -69,6 +69,12 @@ protected function cast($obj, $propertyName, $type) return; } + // if value is an object and we're not being asked to cast to an array then leave it as an object. this is + // desirable in most situations as it exposes bugs in your validation workflow. + if ((true === is_object($obj)) && ('array' !== $type)) { + return $obj; + } + switch ($type) { case 'integer': $value = is_numeric($value) ? (int) $value : null; @@ -95,6 +101,10 @@ protected function cast($obj, $propertyName, $type) case 'string': $value = (string) $value; break; + + case 'array': + $value = (array) $value; + break; } $obj->{$propertyName} = $value;