Esempio n. 1
0
 /**
  * Schedules an entity for insertion into the database.
  * If the entity already has an identifier, it will be added to the identity map.
  *
  * @param object $entity The entity to schedule for insertion.
  *
  * @return void
  *
  * @throws ORMInvalidArgumentException
  * @throws \InvalidArgumentException
  */
 public function scheduleForInsert($entity)
 {
     $oid = spl_object_hash($entity);
     if (isset($this->entityUpdates[$oid])) {
         throw new InvalidArgumentException("Dirty entity can not be scheduled for insertion.");
     }
     if (isset($this->entityDeletions[$oid])) {
         throw ORMInvalidArgumentException::scheduleInsertForRemovedEntity($entity);
     }
     if (isset($this->originalEntityData[$oid]) && !isset($this->entityInsertions[$oid])) {
         throw ORMInvalidArgumentException::scheduleInsertForManagedEntity($entity);
     }
     if (isset($this->entityInsertions[$oid])) {
         throw ORMInvalidArgumentException::scheduleInsertTwice($entity);
     }
     $this->entityInsertions[$oid] = $entity;
     if (isset($this->entityIdentifiers[$oid])) {
         $this->addToIdentityMap($entity);
     }
     if ($entity instanceof NotifyPropertyChanged) {
         $entity->addPropertyChangedListener($this);
     }
 }