remove() public method

public remove ( $id )
Esempio n. 1
0
 /** @inheritdoc */
 public function doRemove(IEntity $entity)
 {
     $this->detach($entity);
     if (!$entity->isPersisted()) {
         return;
     }
     $this->mapper->remove($entity);
     $this->identityMap->remove($entity->getPersistedId());
     $this->entitiesToFlush[1][] = $entity;
     $this->doFireEvent($entity, 'onAfterRemove');
 }
Esempio n. 2
0
 /** @inheritdoc */
 public function remove($entity, $recursive = FALSE)
 {
     $entity = $entity instanceof IEntity ? $entity : $this->getById($entity);
     $this->identityMap->check($entity);
     if (isset($this->isProcessing[spl_object_hash($entity)])) {
         return $entity;
     }
     $this->isProcessing[spl_object_hash($entity)] = TRUE;
     $this->fireEvent($entity, 'onBeforeRemove');
     foreach ($entity->getMetadata()->getProperties() as $property) {
         if ($property->relationship !== NULL) {
             if (in_array($property->relationship->type, [PropertyRelationshipMetadata::MANY_HAS_ONE, PropertyRelationshipMetadata::ONE_HAS_ONE, PropertyRelationshipMetadata::ONE_HAS_ONE_DIRECTED])) {
                 $entity->getProperty($property->name)->set(NULL, TRUE);
             } elseif ($property->relationship->type === PropertyRelationshipMetadata::MANY_HAS_MANY) {
                 $entity->getValue($property->name)->set([]);
             } else {
                 $reverseRepository = $this->model->getRepository($property->relationship->repository);
                 $reverseProperty = $reverseRepository->getEntityMetadata()->getProperty($property->relationship->property);
                 if ($reverseProperty->isNullable || !$recursive) {
                     $entity->getValue($property->name)->set([]);
                 } else {
                     foreach ($entity->getValue($property->name) as $reverseEntity) {
                         $reverseRepository->remove($reverseEntity, $recursive);
                     }
                 }
             }
         }
     }
     if ($entity->isPersisted()) {
         $this->mapper->remove($entity);
         $this->identityMap->remove($entity->getPersistedId());
         $this->entitiesToFlush[1][] = $entity;
     }
     $this->detach($entity);
     $this->fireEvent($entity, 'onAfterRemove');
     unset($this->isProcessing[spl_object_hash($entity)]);
     return $entity;
 }
Esempio n. 3
0
 public function remove($entity)
 {
     $entity = $entity instanceof IEntity ? $entity : $this->getById($entity);
     $this->identityMap->check($entity);
     foreach ($entity->getMetadata()->getProperties() as $property) {
         if ($property->relationshipType) {
             if (in_array($property->relationshipType, [PropertyMetadata::RELATIONSHIP_MANY_HAS_ONE, PropertyMetadata::RELATIONSHIP_ONE_HAS_ONE, PropertyMetadata::RELATIONSHIP_ONE_HAS_ONE_DIRECTED])) {
                 $entity->getProperty($property->name)->set(NULL, TRUE);
             } else {
                 $entity->getValue($property->name)->set([]);
             }
         }
     }
     if ($entity->isPersisted() || $entity->getRepository(FALSE)) {
         $entity->fireEvent('onBeforeRemove');
         if ($entity->isPersisted()) {
             $this->mapper->remove($entity);
             $this->identityMap->remove($entity->getPersistedId());
         }
         $this->identityMap->detach($entity);
         $entity->fireEvent('onAfterRemove');
     }
     return $entity;
 }