src/Valkyrja/ORM/Entity.php
public function fromArray(array $properties): void
    {
        // Iterate through the properties
        foreach ($properties as $property => $value) {
            // If the value is null or the property doesn't exist in this model
            if (null === $value || ! property_exists($this, $property)) {
                // Continue to the next property
                continue;
            }

            // Check if a type was set for this attribute
            $type = static::$propertyTypes[$property] ?? null;

            switch ($type) {
                // If the type is object and the property isn't already an object
                case PropertyType::OBJECT:
                    if (! \is_object($value)) {
                        $value = unserialize($value, true);
                    }

                    break;
                // If the type is array and the property isn't already an array
                case PropertyType::ARRAY:
                    if (! \is_array($value)) {
                        $value = json_decode($value, true);
                    }

                    break;
                default:
                    // Otherwise if a type was set and type is an array and the value is an array
                    // Then this should be an array of entities
                    if ($type !== null && \is_array($type) && \is_array($value)) {
                        // Iterate through the items
                        foreach ($value as &$item) {
                            // Create a new entity for each item
                            $item = new $type[0]($item);
                        }

                        // Unset the reference loop item
                        unset($item);
                    } // Otherwise if a type was set and the value isn't already of that type
                    elseif ($type !== null && ! ($value instanceof $type)) {
                        $value = new $type($value);
                    }
            }

            // Set the property
            $this->__set($property, $value);
        }
    }
public function fromArray(array $properties): void
    {
        // Iterate through the properties
        foreach ($properties as $property => $value) {
            // If the value is null or the property doesn't exist in this model
            if (null === $value || ! property_exists($this, $property)) {
                // Continue to the next property
                continue;
            }

            // Check if a type was set for this attribute
            $type = static::$propertyTypes[$property] ?? null;

            switch ($type) {
                // If the type is object and the property isn't already an object
                case PropertyType::OBJECT:
                    if (! \is_object($value)) {
                        $value = unserialize($value, true);
                    }

                    break;
                // If the type is array and the property isn't already an array
                case PropertyType::ARRAY:
                    if (! \is_array($value)) {
                        $value = json_decode($value, true);
                    }

                    break;
                default:
                    // Otherwise if a type was set and type is an array and the value is an array
                    // Then this should be an array of entities
                    if ($type !== null && \is_array($type) && \is_array($value)) {
                        // Iterate through the items
                        foreach ($value as &$item) {
                            // Create a new entity for each item
                            $item = new $type[0]($item);
                        }

                        // Unset the reference loop item
                        unset($item);
                    } // Otherwise if a type was set and the value isn't already of that type
                    elseif ($type !== null && ! ($value instanceof $type)) {
                        $value = new $type($value);
                    }
            }

            // Set the property
            $this->__set($property, $value);
        }
    }
Set properties from an array of properties.

@param array $properties

@return void