public function cloneEntity($deep = true)
    {
        $copy = $this->getRepository()->getEntity();
        $properties = $this->getEntityDescription()->getProperty();
        $data = array();

        foreach ($properties as $property) {
            if ($property->isUnique()) {
                continue;
            }

            if ($property === $this->getEntityDescription()->getIdentityProperty()) {
                continue;
            }

            $name = $property->getName();

            if ($property->isAttribute()) {
                $copy->set($name, $property->isScalar() ? $this->get($name) : clone $this->get($name));
            } elseif ($property->isRelationship()) {
                //if it's a belongs to then set the value in the
                //copy as  the original
                if ($property->isManyToOne()) {
                    $copy->set($name, $this->get($name));
                }
                //copy the one to one
                elseif ($deep && $property->isOneToOne()) {
                    if (isset($this->$name)) {
                        $copy->set($name, $this->get($name)->cloneEntity($deep));
                    }
                }
                //copy the one to many
                elseif ($deep && $property->isOneToMany() && !$property->isManyToMany()) {
                    $copy->set($name, $this->get($name)->cloneEntity($deep));
                }
            }
        }

        return $copy;
    }
public function cloneEntity($deep = true)
    {
        $copy = $this->getRepository()->getEntity();
        $properties = $this->getEntityDescription()->getProperty();
        $data = array();

        foreach ($properties as $property) {
            if ($property->isUnique()) {
                continue;
            }

            if ($property === $this->getEntityDescription()->getIdentityProperty()) {
                continue;
            }

            $name = $property->getName();

            if ($property->isAttribute()) {
                $copy->set($name, $property->isScalar() ? $this->get($name) : clone $this->get($name));
            } elseif ($property->isRelationship()) {
                //if it's a belongs to then set the value in the
                //copy as  the original
                if ($property->isManyToOne()) {
                    $copy->set($name, $this->get($name));
                }
                //copy the one to one
                elseif ($deep && $property->isOneToOne()) {
                    if (isset($this->$name)) {
                        $copy->set($name, $this->get($name)->cloneEntity($deep));
                    }
                }
                //copy the one to many
                elseif ($deep && $property->isOneToMany() && !$property->isManyToMany()) {
                    $copy->set($name, $this->get($name)->cloneEntity($deep));
                }
            }
        }

        return $copy;
    }
public function cloneEntity ( $ deep = true ) { $ copy = $ this -> getRepository ( ) -> getEntity ( ) ; $ properties = $ this -> getEntityDescription ( ) -> getProperty ( ) ; $ data = array ( ) ; foreach ( $ properties as $ property ) { if ( $ property -> isUnique ( ) ) { continue ; } if ( $ property === $ this -> getEntityDescription ( ) -> getIdentityProperty ( ) ) { continue ; } $ name = $ property -> getName ( ) ; if ( $ property -> isAttribute ( ) ) { $ copy -> set ( $ name , $ property -> isScalar ( ) ? $ this -> get ( $ name ) : clone $ this -> get ( $ name ) ) ; } elseif ( $ property -> isRelationship ( ) ) { //if it's a belongs to then set the value in the //copy as  the original if ( $ property -> isManyToOne ( ) ) { $ copy -> set ( $ name , $ this -> get ( $ name ) ) ; } //copy the one to one elseif ( $ deep && $ property -> isOneToOne ( ) ) { if ( isset ( $ this -> $ name ) ) { $ copy -> set ( $ name , $ this -> get ( $ name ) -> cloneEntity ( $ deep ) ) ; } } //copy the one to many elseif ( $ deep && $ property -> isOneToMany ( ) && ! $ property -> isManyToMany ( ) ) { $ copy -> set ( $ name , $ this -> get ( $ name ) -> cloneEntity ( $ deep ) ) ; } } } return $ copy ; }
Make a clone of the entity with it's attributes. The unique properties are
not copied. If deep copy is selected, then this method tries to replicate
all the ony-to-many relationships as well.

@param bool $deep Flag to determine to whether to deep copy.

@return AnDomainEntityAbstract
Make a clone of the entity with it s attributes . The unique properties are not copied . If deep copy is selected then this method tries to replicate all the ony - to - many relationships as well .