$value) { if (! static::propertyIsBranchSpecific($key)) { if (is_resource($value)) { $value = stream_get_contents($value); } if ($value !== null && static::propertyIsEncodedArray($key)) { $value = Json::decode($value); } if ($value !== null && static::propertyIsRelatedSet($key)) { // TODO: We might want to combine them (current VS branched) $value = Json::decode($value); } if ($value !== null && static::propertyIsEncodedDictionary($key)) { $value = Json::decode($value); } if ($value !== null) { $normalized[$key] = $value; } } } static::flattenEncodedDicationaries($row); if (isset($row['set_null'])) { foreach (Json::decode($row['set_null']) as $property) { $normalized[$property] = null; } } foreach (self::BRANCH_BOOLEANS as $key) { if ($row[$key] === 'y') { $row[$key] = true; } elseif ($row[$key] === 'n') { $row[$key] = false; } else { throw new \RuntimeException(sprintf( "Boolean DB property expected, got '%s' for '%s'", $row[$key], $key )); } } return $normalized; } public static function flattenProperty(array &$properties, $property) { // TODO: dots in varnames -> throw or escape? if (isset($properties[$property])) { foreach ((array) $properties[$property] as $key => $value) { $properties["$property.$key"] = $value; } unset($properties[$property]); } } }