Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
iainmckay committed Jan 25, 2017
1 parent c07d025 commit d240035
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Mapper/CastingObjectMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit d240035

Please sign in to comment.