protected function createDataObjectFrom($value, $className)
    {
        // If the value is already the correct object, return it unaltered
        if ($value instanceof $className) {
            return $value;
        }

        // Convert object to array so it can be used to set  attributes in the DataObject
        if ($value instanceof Arrayable) {

            $value = $value->toArray();

        }  elseif (is_object($value)) {

            $value = json_decode(json_encode($value), true);
        }

        // Make validation fail if value could not be converted to an array
        if ( ! is_array($value)) {
            return false;
        }


        // Build an instance of the DataObject
        $dataObjectClass = $className;

        try {

            $dataObject = new $dataObjectClass($value);

        } catch (Throwable $e) {

            throw new InvalidArgumentException($dataObjectClass . ' is not instantiable as a DataObject', 0, $e);
        }

        if ( ! ($dataObject instanceof DataObjectInterface)) {

            throw new InvalidArgumentException($dataObjectClass . ' is not a validatable DataObject');
        }

        return $dataObject;
    }
protected function createDataObjectFrom($value, $className)
    {
        // If the value is already the correct object, return it unaltered
        if ($value instanceof $className) {
            return $value;
        }

        // Convert object to array so it can be used to set  attributes in the DataObject
        if ($value instanceof Arrayable) {

            $value = $value->toArray();

        }  elseif (is_object($value)) {

            $value = json_decode(json_encode($value), true);
        }

        // Make validation fail if value could not be converted to an array
        if ( ! is_array($value)) {
            return false;
        }


        // Build an instance of the DataObject
        $dataObjectClass = $className;

        try {

            $dataObject = new $dataObjectClass($value);

        } catch (Throwable $e) {

            throw new InvalidArgumentException($dataObjectClass . ' is not instantiable as a DataObject', 0, $e);
        }

        if ( ! ($dataObject instanceof DataObjectInterface)) {

            throw new InvalidArgumentException($dataObjectClass . ' is not a validatable DataObject');
        }

        return $dataObject;
    }
protected function createDataObjectFrom ( $ value , $ className ) { // If the value is already the correct object, return it unaltered if ( $ value instanceof $ className ) { return $ value ; } // Convert object to array so it can be used to set  attributes in the DataObject if ( $ value instanceof Arrayable ) { $ value = $ value -> toArray ( ) ; } elseif ( is_object ( $ value ) ) { $ value = json_decode ( json_encode ( $ value ) , true ) ; } // Make validation fail if value could not be converted to an array if ( ! is_array ( $ value ) ) { return false ; } // Build an instance of the DataObject $ dataObjectClass = $ className ; try { $ dataObject = new $ dataObjectClass ( $ value ) ; } catch ( Throwable $ e ) { throw new InvalidArgumentException ( $ dataObjectClass . ' is not instantiable as a DataObject' , 0 , $ e ) ; } if ( ! ( $ dataObject instanceof DataObjectInterface ) ) { throw new InvalidArgumentException ( $ dataObjectClass . ' is not a validatable DataObject' ) ; } return $ dataObject ; }
Creates a DataObject with the given class name

@param mixed  $value
@param string $className DataObject class to instantiate
@return DataObjectInterface|bool
Creates a DataObject with the given class name