コード例 #1
0
ファイル: EntityUpdater.php プロジェクト: iPublikuj/doctrine
 /**
  * {@inheritdoc}
  */
 public function update(Utils\ArrayHash $values, $entity)
 {
     if (!$entity instanceof Entities\IEntity) {
         $entity = $this->entityRepository->find($entity);
     }
     if (!$entity) {
         throw new Exceptions\InvalidArgumentException('Entity not found.');
     }
     $this->processHooks($this->beforeUpdate, [$entity, $values]);
     $this->entityMapper->fillEntity($values, $entity, FALSE);
     $entityManager = $this->managerRegistry->getManagerForClass(get_class($entity));
     $entityManager->persist($entity);
     $this->processHooks($this->afterUpdate, [$entity, $values]);
     if ($this->getFlush() === TRUE) {
         $entityManager->flush();
     }
     return $entity;
 }
コード例 #2
0
ファイル: EntityCreator.php プロジェクト: iPublikuj/doctrine
 /**
  * {@inheritdoc}
  */
 public function create(Utils\ArrayHash $values, Entities\IEntity $entity = NULL)
 {
     if (!$entity instanceof Entities\IEntity) {
         $entityName = $this->entityRepository->getClassName();
         $entity = $this->managerRegistry->getManagerForClass($entityName)->getClassMetadata($entityName)->newInstance();
     }
     if (!$entity || !$entity instanceof Entities\IEntity) {
         throw new Exceptions\InvalidArgumentException('Entity could not be created.');
     }
     $this->processHooks($this->beforeCreate, [$entity, $values]);
     $this->entityMapper->fillEntity($values, $entity, TRUE);
     $entityManager = $this->managerRegistry->getManagerForClass(get_class($entity));
     $entityManager->persist($entity);
     $this->processHooks($this->afterCreate, [$entity, $values]);
     if ($this->getFlush() === TRUE) {
         $entityManager->flush();
     }
     return $entity;
 }