public static function newFromDatamapperObject(EntityContract $entity, $lastObjectId = null, $lastEloquentModel = null)
    {
        // directly get private properties if entity extends the datamapper entity class (fast!)
        if ($entity instanceof \ProAI\Datamapper\Support\Entity) {
            return $entity->toEloquentObject($lastObjectId, $lastEloquentModel);
        }

        // get private properties via reflection (slow!)
        $class = get_mapped_model(get_class($entity));

        $eloquentModel = new $class;

        $reflectionObject = new ReflectionObject($entity);

        $mapping = $eloquentModel->getMapping();

        // attributes
        foreach ($mapping['attributes'] as $attribute => $column) {
            if (! $eloquentModel->isAutomaticallyUpdatedDate($column)) {
                // get property
                $property = $eloquentModel->getProperty(
                    $reflectionObject,
                    $entity,
                    $attribute
                );

                // set attribute
                $eloquentModel->setAttribute($column, $property);
            }
        }

        // embeddeds
        foreach ($mapping['embeddeds'] as $name => $embedded) {
            $embeddedObject = $eloquentModel->getProperty($reflectionObject, $entity, $name);


            if (! empty($embeddedObject)) {
                $embeddedReflectionObject = new ReflectionObject($embeddedObject);

                foreach ($embedded['attributes'] as $attribute => $column) {
                    // get property
                    $property = $eloquentModel->getProperty(
                        $embeddedReflectionObject,
                        $embeddedObject,
                        $attribute
                    );

                    // set attribute
                    $eloquentModel->setAttribute($column, $property);
                }
            }
        }

        // relations
        foreach ($mapping['relations'] as $name => $relation) {
            $relationObject = $eloquentModel->getProperty(
                $reflectionObject,
                $entity,
                $name
            );

            if (! empty($relationObject) && ! $relationObject instanceof \ProAI\Datamapper\Contracts\Proxy) {
                // set relation
                if ($relationObject instanceof \ProAI\Datamapper\Support\Collection) {
                    $value = EloquentCollection::newFromDatamapperObject($relationObject, $this, $eloquentModel);
                } elseif (spl_object_hash($relationObject) == $lastObjectId) {
                    $value = $lastEloquentModel;
                } else {
                    $value = EloquentModel::newFromDatamapperObject($relationObject, spl_object_hash($this), $eloquentModel);
                }
                
                $eloquentModel->setRelation($name, $value);
            }
        }

        return $eloquentModel;
    }
public static function newFromDatamapperObject(EntityContract $entity, $lastObjectId = null, $lastEloquentModel = null)
    {
        // directly get private properties if entity extends the datamapper entity class (fast!)
        if ($entity instanceof \ProAI\Datamapper\Support\Entity) {
            return $entity->toEloquentObject($lastObjectId, $lastEloquentModel);
        }

        // get private properties via reflection (slow!)
        $class = get_mapped_model(get_class($entity));

        $eloquentModel = new $class;

        $reflectionObject = new ReflectionObject($entity);

        $mapping = $eloquentModel->getMapping();

        // attributes
        foreach ($mapping['attributes'] as $attribute => $column) {
            if (! $eloquentModel->isAutomaticallyUpdatedDate($column)) {
                // get property
                $property = $eloquentModel->getProperty(
                    $reflectionObject,
                    $entity,
                    $attribute
                );

                // set attribute
                $eloquentModel->setAttribute($column, $property);
            }
        }

        // embeddeds
        foreach ($mapping['embeddeds'] as $name => $embedded) {
            $embeddedObject = $eloquentModel->getProperty($reflectionObject, $entity, $name);


            if (! empty($embeddedObject)) {
                $embeddedReflectionObject = new ReflectionObject($embeddedObject);

                foreach ($embedded['attributes'] as $attribute => $column) {
                    // get property
                    $property = $eloquentModel->getProperty(
                        $embeddedReflectionObject,
                        $embeddedObject,
                        $attribute
                    );

                    // set attribute
                    $eloquentModel->setAttribute($column, $property);
                }
            }
        }

        // relations
        foreach ($mapping['relations'] as $name => $relation) {
            $relationObject = $eloquentModel->getProperty(
                $reflectionObject,
                $entity,
                $name
            );

            if (! empty($relationObject) && ! $relationObject instanceof \ProAI\Datamapper\Contracts\Proxy) {
                // set relation
                if ($relationObject instanceof \ProAI\Datamapper\Support\Collection) {
                    $value = EloquentCollection::newFromDatamapperObject($relationObject, $this, $eloquentModel);
                } elseif (spl_object_hash($relationObject) == $lastObjectId) {
                    $value = $lastEloquentModel;
                } else {
                    $value = EloquentModel::newFromDatamapperObject($relationObject, spl_object_hash($this), $eloquentModel);
                }
                
                $eloquentModel->setRelation($name, $value);
            }
        }

        return $eloquentModel;
    }
public static function newFromDatamapperObject ( EntityContract $ entity , $ lastObjectId = null , $ lastEloquentModel = null ) { // directly get private properties if entity extends the datamapper entity class (fast!) if ( $ entity instanceof \ ProAI \ Datamapper \ Support \ Entity ) { return $ entity -> toEloquentObject ( $ lastObjectId , $ lastEloquentModel ) ; } // get private properties via reflection (slow!) $ class = get_mapped_model ( get_class ( $ entity ) ) ; $ eloquentModel = new $ class ; $ reflectionObject = new ReflectionObject ( $ entity ) ; $ mapping = $ eloquentModel -> getMapping ( ) ; // attributes foreach ( $ mapping [ 'attributes' ] as $ attribute => $ column ) { if ( ! $ eloquentModel -> isAutomaticallyUpdatedDate ( $ column ) ) { // get property $ property = $ eloquentModel -> getProperty ( $ reflectionObject , $ entity , $ attribute ) ; // set attribute $ eloquentModel -> setAttribute ( $ column , $ property ) ; } } // embeddeds foreach ( $ mapping [ 'embeddeds' ] as $ name => $ embedded ) { $ embeddedObject = $ eloquentModel -> getProperty ( $ reflectionObject , $ entity , $ name ) ; if ( ! empty ( $ embeddedObject ) ) { $ embeddedReflectionObject = new ReflectionObject ( $ embeddedObject ) ; foreach ( $ embedded [ 'attributes' ] as $ attribute => $ column ) { // get property $ property = $ eloquentModel -> getProperty ( $ embeddedReflectionObject , $ embeddedObject , $ attribute ) ; // set attribute $ eloquentModel -> setAttribute ( $ column , $ property ) ; } } } // relations foreach ( $ mapping [ 'relations' ] as $ name => $ relation ) { $ relationObject = $ eloquentModel -> getProperty ( $ reflectionObject , $ entity , $ name ) ; if ( ! empty ( $ relationObject ) && ! $ relationObject instanceof \ ProAI \ Datamapper \ Contracts \ Proxy ) { // set relation if ( $ relationObject instanceof \ ProAI \ Datamapper \ Support \ Collection ) { $ value = EloquentCollection :: newFromDatamapperObject ( $ relationObject , $ this , $ eloquentModel ) ; } elseif ( spl_object_hash ( $ relationObject ) == $ lastObjectId ) { $ value = $ lastEloquentModel ; } else { $ value = EloquentModel :: newFromDatamapperObject ( $ relationObject , spl_object_hash ( $ this ) , $ eloquentModel ) ; } $ eloquentModel -> setRelation ( $ name , $ value ) ; } } return $ eloquentModel ; }
Convert model to plain old php object.

@param \ProAI\Datamapper\Contracts\Entity $entity
@param string $lastObjectId
@param \ProAI\Datamapper\Eloquent\Model $lastEloquentModel
@return \ProAI\Datamapper\Eloquent\Model
Convert model to plain old php object .