Пример #1
0
 /**
  * @param string $association
  * @param object $associatedEntity
  */
 public function removeFromCollection($association, $associatedEntity)
 {
     $this->initializeEntity();
     $this->verifyToManyAssociation($association);
     $this->verifyAssociatedEntity($association, $associatedEntity);
     if ($method = $this->getCustomManipulateMethod($association, 'remove')) {
         call_user_func_array([$this->entity, $method], [$associatedEntity]);
         return;
     }
     $methods = [];
     $methods[] = 'remove' . $association;
     if ($this->tryCallMethods($methods, [$associatedEntity])) {
         return;
     }
     $collection = $this->getCollectionFromAssociation($association);
     if ($collection->contains($associatedEntity)) {
         $collection->removeElement($associatedEntity);
     }
     $this->setRawValue($association, $collection);
     $associationMapping = $this->getAssociationMapping($association);
     if (($inversed = $associationMapping['mappedBy']) || ($inversed = $associationMapping['inversedBy'])) {
         $wrapper = $this->entityWrapper->wrap($associatedEntity);
         $wrapper->setRawValue($inversed, NULL);
     }
 }
Пример #2
0
 /**
  * @param mixed
  * @param object
  * @param string load or save
  */
 protected function handle($components, $entity, $operation)
 {
     $this->entities[] = $entity;
     $wrappedEntity = $this->entityWrapper->wrap($entity);
     foreach ($this->iterable($components) as $component) {
         if ($this->shouldSkip($component)) {
             continue;
         }
         $this->handler->{$operation}($wrappedEntity, $component, $this);
     }
 }