1
0
Fork 0
mirror of synced 2025-04-20 01:21:01 +00:00

fallback to array casting for internal objects

This commit is contained in:
Pavel 2020-07-28 22:09:54 +03:00
parent f08978c567
commit 102f16cb9e
2 changed files with 16 additions and 2 deletions

View file

@ -41,6 +41,16 @@ class EntityStrategy implements DeserializeStrategyInterface
$reflection = new \ReflectionClass($type);
$instance = new $type();
if (!$reflection->isUserDefined()) {
if (is_iterable($value)) {
foreach ($value as $field => $content) {
$instance->$field = $content;
}
}
return $instance;
}
foreach ($reflection->getProperties() as $property) {
static::deserializeProperty($instance, $property, $value);
}

View file

@ -36,9 +36,13 @@ class EntityStrategy implements SerializeStrategyInterface
public function serialize($value)
{
$result = [];
$ref = new \ReflectionClass(get_class($value));
$reflection = new \ReflectionClass(get_class($value));
foreach ($ref->getProperties() as $property) {
if (!$reflection->isUserDefined()) {
return (array) $value;
}
foreach ($reflection->getProperties() as $property) {
static::serializeProperty($value, $property, $result);
}