private function arrayToObject(array $data, FieldsAwareDefinitionInterface $definition)
    {
        $class = null;
        if ($definition instanceof ClassAwareDefinitionInterface) {
            $class = $definition->getClass();
        }

        //normalize data
        foreach ($data as $fieldName => &$value) {
            if (!$definition->hasField($fieldName)) {
                continue;
            }
            $fieldDefinition = $definition->getField($fieldName);
            $value = $this->normalizeValue($value, $fieldDefinition->getType());
        }
        unset($value);

        //instantiate object
        if (class_exists($class)) {
            $object = new $class();
        } else {
            $object = $data;
        }

        //populate object
        foreach ($data as $key => $value) {
            if (!$definition->hasField($key)) {
                continue;
            }
            $fieldDefinition = $definition->getField($key);

            if (\is_array($value) && $this->endpoint->hasType($fieldDefinition->getType())) {
                $childType = $this->endpoint->getType($fieldDefinition->getType());
                if ($childType instanceof FieldsAwareDefinitionInterface) {
                    $value = $this->arrayToObject($value, $childType);
                }
            }

            $this->setObjectValue($object, $fieldDefinition, $value);
        }

        return $object;
    }
private function arrayToObject(array $data, FieldsAwareDefinitionInterface $definition)
    {
        $class = null;
        if ($definition instanceof ClassAwareDefinitionInterface) {
            $class = $definition->getClass();
        }

        //normalize data
        foreach ($data as $fieldName => &$value) {
            if (!$definition->hasField($fieldName)) {
                continue;
            }
            $fieldDefinition = $definition->getField($fieldName);
            $value = $this->normalizeValue($value, $fieldDefinition->getType());
        }
        unset($value);

        //instantiate object
        if (class_exists($class)) {
            $object = new $class();
        } else {
            $object = $data;
        }

        //populate object
        foreach ($data as $key => $value) {
            if (!$definition->hasField($key)) {
                continue;
            }
            $fieldDefinition = $definition->getField($key);

            if (\is_array($value) && $this->endpoint->hasType($fieldDefinition->getType())) {
                $childType = $this->endpoint->getType($fieldDefinition->getType());
                if ($childType instanceof FieldsAwareDefinitionInterface) {
                    $value = $this->arrayToObject($value, $childType);
                }
            }

            $this->setObjectValue($object, $fieldDefinition, $value);
        }

        return $object;
    }
private function arrayToObject ( array $ data , FieldsAwareDefinitionInterface $ definition ) { $ class = null ; if ( $ definition instanceof ClassAwareDefinitionInterface ) { $ class = $ definition -> getClass ( ) ; } //normalize data foreach ( $ data as $ fieldName => & $ value ) { if ( ! $ definition -> hasField ( $ fieldName ) ) { continue ; } $ fieldDefinition = $ definition -> getField ( $ fieldName ) ; $ value = $ this -> normalizeValue ( $ value , $ fieldDefinition -> getType ( ) ) ; } unset ( $ value ) ; //instantiate object if ( class_exists ( $ class ) ) { $ object = new $ class ( ) ; } else { $ object = $ data ; } //populate object foreach ( $ data as $ key => $ value ) { if ( ! $ definition -> hasField ( $ key ) ) { continue ; } $ fieldDefinition = $ definition -> getField ( $ key ) ; if ( \ is_array ( $ value ) && $ this -> endpoint -> hasType ( $ fieldDefinition -> getType ( ) ) ) { $ childType = $ this -> endpoint -> getType ( $ fieldDefinition -> getType ( ) ) ; if ( $ childType instanceof FieldsAwareDefinitionInterface ) { $ value = $ this -> arrayToObject ( $ value , $ childType ) ; } } $ this -> setObjectValue ( $ object , $ fieldDefinition , $ value ) ; } return $ object ; }
Convert a array into object using given definition

@param array                          $data       data to populate the object
@param FieldsAwareDefinitionInterface $definition object definition

@return mixed
Convert a array into object using given definition