예제 #1
0
 /**
  * @param $object object
  */
 public function createDuplicate($object)
 {
     if ($this->dao->getObjectIdentifier($object)) {
         // duplicate @link Collection and Map properties values
         $class_name = get_class($object);
         $class = new Reflection_Class($class_name);
         /** @var $link Link_Annotation */
         $link = $class->getAnnotation('link');
         $exclude_properties = $link->value ? array_keys((new Reflection_Class($link->value))->getProperties([T_EXTENDS, T_USE])) : [];
         foreach ($class->accessProperties() as $property) {
             if (!$property->isStatic() && !in_array($property->name, $exclude_properties)) {
                 $property_link = $property->getAnnotation('link')->value;
                 // @link Collection : must disconnect objects
                 // @link Collection | Map : duplicate and remove reference to the parent id
                 if (in_array($property_link, [Link_Annotation::COLLECTION, Link_Annotation::MAP])) {
                     $elements = $property->getValue($object);
                     if ($property_link == Link_Annotation::COLLECTION) {
                         foreach ($elements as $element) {
                             $this->createDuplicate($element);
                         }
                     }
                     $this->removeCompositeFromComponents($elements, $class_name);
                 }
             }
         }
         // duplicate object
         $this->dao->disconnect($object);
         // after duplicate
         $this->onDuplicate($object, $class);
     }
 }