public function toDatamapperObject()
    {
        // directly set private properties if entity extends the datamapper entity class (fast!)
        if (is_subclass_of($this->class, '\ProAI\Datamapper\Support\Entity')) {
            $class = $this->class;

            return $class::newFromEloquentObject($this);
        }

        // set private properties via reflection (slow!)
        $reflectionClass = new ReflectionClass($this->class);

        $entity = $reflectionClass->newInstanceWithoutConstructor();

        // attributes
        foreach ($this->mapping['attributes'] as $attribute => $column) {
            $this->setProperty(
                $reflectionClass,
                $entity,
                $attribute,
                $this->attributes[$column]
            );
        }

        // embeddeds
        foreach ($this->mapping['embeddeds'] as $name => $embedded) {
            $embeddedReflectionClass = new ReflectionClass($embedded['class']);

            $embeddedObject = $embeddedReflectionClass->newInstanceWithoutConstructor();
            foreach ($embedded['attributes'] as $attribute => $column) {
                // set property
                $this->setProperty(
                    $embeddedReflectionClass,
                    $embeddedObject,
                    $attribute,
                    $this->attributes[$column]
                );
            }

            $this->setProperty(
                $reflectionClass,
                $entity,
                $name,
                $embeddedObject
            );
        }

        // relations
        foreach ($this->mapping['relations'] as $name => $relation) {
            // set relation object
            if (! empty($this->relations[$name])) {
                $relationObject = $this->relations[$name]->toDatamapperObject();
            } elseif (in_array($relation['type'], $this->manyRelations)) {
                $relationObject = new ProxyCollection;
            } else {
                $relationObject = new Proxy;
            }
            
            // set property
            $this->setProperty(
                $reflectionClass,
                $entity,
                $name,
                $relationObject
            );
        }

        return $entity;
    }
public function toDatamapperObject()
    {
        // directly set private properties if entity extends the datamapper entity class (fast!)
        if (is_subclass_of($this->class, '\ProAI\Datamapper\Support\Entity')) {
            $class = $this->class;

            return $class::newFromEloquentObject($this);
        }

        // set private properties via reflection (slow!)
        $reflectionClass = new ReflectionClass($this->class);

        $entity = $reflectionClass->newInstanceWithoutConstructor();

        // attributes
        foreach ($this->mapping['attributes'] as $attribute => $column) {
            $this->setProperty(
                $reflectionClass,
                $entity,
                $attribute,
                $this->attributes[$column]
            );
        }

        // embeddeds
        foreach ($this->mapping['embeddeds'] as $name => $embedded) {
            $embeddedReflectionClass = new ReflectionClass($embedded['class']);

            $embeddedObject = $embeddedReflectionClass->newInstanceWithoutConstructor();
            foreach ($embedded['attributes'] as $attribute => $column) {
                // set property
                $this->setProperty(
                    $embeddedReflectionClass,
                    $embeddedObject,
                    $attribute,
                    $this->attributes[$column]
                );
            }

            $this->setProperty(
                $reflectionClass,
                $entity,
                $name,
                $embeddedObject
            );
        }

        // relations
        foreach ($this->mapping['relations'] as $name => $relation) {
            // set relation object
            if (! empty($this->relations[$name])) {
                $relationObject = $this->relations[$name]->toDatamapperObject();
            } elseif (in_array($relation['type'], $this->manyRelations)) {
                $relationObject = new ProxyCollection;
            } else {
                $relationObject = new Proxy;
            }
            
            // set property
            $this->setProperty(
                $reflectionClass,
                $entity,
                $name,
                $relationObject
            );
        }

        return $entity;
    }
public function toDatamapperObject ( ) { // directly set private properties if entity extends the datamapper entity class (fast!) if ( is_subclass_of ( $ this -> class , '\ProAI\Datamapper\Support\Entity' ) ) { $ class = $ this -> class ; return $ class :: newFromEloquentObject ( $ this ) ; } // set private properties via reflection (slow!) $ reflectionClass = new ReflectionClass ( $ this -> class ) ; $ entity = $ reflectionClass -> newInstanceWithoutConstructor ( ) ; // attributes foreach ( $ this -> mapping [ 'attributes' ] as $ attribute => $ column ) { $ this -> setProperty ( $ reflectionClass , $ entity , $ attribute , $ this -> attributes [ $ column ] ) ; } // embeddeds foreach ( $ this -> mapping [ 'embeddeds' ] as $ name => $ embedded ) { $ embeddedReflectionClass = new ReflectionClass ( $ embedded [ 'class' ] ) ; $ embeddedObject = $ embeddedReflectionClass -> newInstanceWithoutConstructor ( ) ; foreach ( $ embedded [ 'attributes' ] as $ attribute => $ column ) { // set property $ this -> setProperty ( $ embeddedReflectionClass , $ embeddedObject , $ attribute , $ this -> attributes [ $ column ] ) ; } $ this -> setProperty ( $ reflectionClass , $ entity , $ name , $ embeddedObject ) ; } // relations foreach ( $ this -> mapping [ 'relations' ] as $ name => $ relation ) { // set relation object if ( ! empty ( $ this -> relations [ $ name ] ) ) { $ relationObject = $ this -> relations [ $ name ] -> toDatamapperObject ( ) ; } elseif ( in_array ( $ relation [ 'type' ] , $ this -> manyRelations ) ) { $ relationObject = new ProxyCollection ; } else { $ relationObject = new Proxy ; } // set property $ this -> setProperty ( $ reflectionClass , $ entity , $ name , $ relationObject ) ; } return $ entity ; }
Convert model to entity object.

@return object
Convert model to entity object .