当前位置: 首页>>代码示例>>PHP>>正文


PHP EntityManager::persist方法代码示例

本文整理汇总了PHP中Kdyby\Doctrine\EntityManager::persist方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::persist方法的具体用法?PHP EntityManager::persist怎么用?PHP EntityManager::persist使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Kdyby\Doctrine\EntityManager的用法示例。


在下文中一共展示了EntityManager::persist方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: processImage

 /**
  * @param FileUpload $file
  * @return Image
  * @throws NotImageUploadedException
  * @throws FileSizeException
  * @throws DBALException
  * @throws InvalidStateException
  */
 public function processImage(FileUpload $file)
 {
     if (!$file->isImage()) {
         throw new NotImageUploadedException();
     }
     if (\filesize($file->getTemporaryFile()) > Image::MAX_FILE_SIZE) {
         throw new FileSizeException();
     }
     try {
         $this->em->beginTransaction();
         $image = new Image($file);
         $this->em->persist($image)->flush();
         $file->move($this->composeImageLocation($image));
         $this->em->commit();
     } catch (InvalidStateException $is) {
         $this->em->rollback();
         $this->em->close();
         $this->logger->addError('Error occurs while moving temp. image file to new location.');
         throw $is;
     } catch (DBALException $e) {
         $this->em->rollback();
         $this->em->close();
         $this->logger->addError('Image error');
         // todo err message
         throw $e;
     }
     return $image;
 }
开发者ID:blitzik,项目名称:CMS,代码行数:36,代码来源:ImagesUploader.php

示例2: sendMessage

 /**
  * @param SentMessage $message
  * @param array $recipients
  * @return ReceivedMessage[]
  * @throws \Exception
  */
 public function sendMessage(SentMessage $message, array $recipients)
 {
     $receivedMessages = [];
     try {
         $this->em->beginTransaction();
         $this->em->persist($message);
         foreach ($recipients as $recipient) {
             if (!$recipient instanceof User) {
                 throw new InvalidArgumentException('Argument $recipients can only contains instances of ' . User::class);
             }
             $m = $receivedMessages[$recipient->getId()] = new ReceivedMessage($message, $recipient);
             $this->em->persist($m);
             //if (count($receivedMessages) % 5 === 0) { // todo
             //    $this->em->flush();
             //    $this->em->clear();
             //}
         }
         $this->em->flush();
         $this->em->commit();
     } catch (\Exception $e) {
         $this->em->rollback();
         $this->em->close();
         $this->onError('Message sending failed.', $e, self::class);
         throw $e;
     }
     return $receivedMessages;
 }
开发者ID:blitzik,项目名称:vycetky-doctrine,代码行数:33,代码来源:MessagesWriter.php

示例3: linkUrls

 /**
  * @param Url $oldUrl
  * @param Url $newUrl
  * @return void
  * @throws \Exception
  */
 public function linkUrls(Url $oldUrl, Url $newUrl)
 {
     if ($oldUrl->getId() === null or $newUrl->getId() === null) {
         throw new UrlNotPersistedException();
     }
     try {
         $this->em->beginTransaction();
         $alreadyRedirectedUrls = $this->findByActualUrl($oldUrl->getId());
         /** @var Url $url */
         foreach ($alreadyRedirectedUrls as $url) {
             $url->setRedirectTo($newUrl);
             $this->em->persist($url);
             $this->cache->clean([Cache::TAGS => [$url->getCacheKey()]]);
         }
         $oldUrl->setRedirectTo($newUrl);
         $this->em->persist($oldUrl);
         $this->cache->clean([Cache::TAGS => [$oldUrl->getCacheKey()]]);
         $this->em->flush();
         $this->em->commit();
     } catch (\Exception $e) {
         $this->em->rollback();
         $this->em->close();
         throw $e;
     }
 }
开发者ID:blitzik,项目名称:CMS,代码行数:31,代码来源:UrlLinker.php

示例4: save

 /**
  * @param array $values
  * @return Comment
  * @throws ActionFailedException
  */
 public function save(array $values)
 {
     $numberOfComments = $this->getNumberOfComments($values['page']);
     $repliesReferences = $this->findRepliesReferences($values['text']);
     try {
         $this->em->beginTransaction();
         // no replies references found
         if (empty($repliesReferences)) {
             $comment = new Comment($values['author'], $this->texy->process($values['text']), $values['page'], $numberOfComments + 1, $this->request->getRemoteAddress());
             $this->em->persist($comment)->flush();
             $this->em->commit();
             return $comment;
         }
         $commentsToReply = $this->findCommentsToReply($values['page'], $repliesReferences);
         $values['text'] = $this->replaceReplyReferencesByAuthors($values['text'], $commentsToReply);
         $comment = new Comment($values['author'], $this->texy->process($values['text']), $values['page'], $numberOfComments + 1);
         $this->em->persist($comment);
         /** @var Comment $comment */
         foreach ($commentsToReply as $commentToReply) {
             $commentToReply->addReaction($comment);
             $this->em->persist($commentToReply);
         }
         $this->em->flush();
         $this->em->commit();
     } catch (\Exception $e) {
         $this->em->rollback();
         $this->em->close();
         throw new ActionFailedException();
     }
     return $comment;
 }
开发者ID:blitzik,项目名称:CMS,代码行数:36,代码来源:CommentPersister.php

示例5: assignAlbums

 /**
  * @param User $user
  * @param array $albums
  */
 public function assignAlbums(User $user, array $albums)
 {
     $user->albums->clear();
     $user->setAlbums($albums);
     $this->em->persist($user);
     $this->em->flush();
 }
开发者ID:peterkrejci,项目名称:music-collection,代码行数:11,代码来源:UserModel.php

示例6: save

 public function save($entity, $immediately = true)
 {
     $this->em->persist($entity);
     if ($immediately) {
         $this->em->flush();
     }
 }
开发者ID:Thoronir42,项目名称:G-archive,代码行数:7,代码来源:BaseService.php

示例7: switchEntities

 /**
  * @param $entity1
  * @param $entity2
  */
 private function switchEntities($entity1, $entity2)
 {
     $x = $entity1->priority;
     $entity1->priority = $entity2->priority;
     $entity2->priority = $x;
     $this->entityManager->persist($entity1, $entity2);
     $this->entityManager->flush();
 }
开发者ID:Kotys,项目名称:eventor.io,代码行数:12,代码来源:Sorter.php

示例8: addDefinition

 /**
  * @param Privilege $privilege
  * @param Role $role
  * @return $this
  */
 public function addDefinition(Privilege $privilege, Role $role)
 {
     $accessDefinition = new AccessDefinition($this->resource, $privilege);
     $this->em->persist($accessDefinition);
     $permission = new Permission($role, $this->resource, $privilege);
     $this->em->persist($permission);
     return $this;
 }
开发者ID:blitzik,项目名称:CMS,代码行数:13,代码来源:AuthorizationRulesGenerator.php

示例9: logDb

 private function logDb($message, $status = NULL, $consumerTitle = NULL)
 {
     $log = new RmqLogConsumer();
     $log->consumerTitle = $consumerTitle;
     $log->message = $message;
     $log->status = $status;
     $this->em->persist($log);
     $this->em->flush();
 }
开发者ID:miloshavlicek,项目名称:rabbit-mq-consumer,代码行数:9,代码来源:Log.php

示例10: addGenre

 public function addGenre(string $name)
 {
     if ($this->genreExists($name)) {
         return;
     }
     $genre = new Genre($name);
     $this->entityManager->persist($genre);
     $this->entityManager->flush($genre);
 }
开发者ID:ParalelniPolis,项目名称:bitcoinJukebox,代码行数:9,代码来源:GenresManager.php

示例11: saveSearch

 /**
  * @param string $searchString
  * @return Search
  */
 public function saveSearch($searchString)
 {
     if ($search = $this->search(Strings::webalize($searchString))) {
         return $search;
     }
     $search = new Search($searchString);
     $this->entityManager->persist($search);
     $this->entityManager->flush($search);
     return $search;
 }
开发者ID:stekycz,项目名称:dwarf-search,代码行数:14,代码来源:SearchManager.php

示例12: saveUser

 /**
  * @param User $user
  * @return User
  * @throws \Exception
  */
 public function saveUser(User $user)
 {
     try {
         $this->em->persist($user)->flush();
         return $user;
     } catch (\Exception $e) {
         $this->onError(sprintf('Saving of user "%s" #id(%s) failed', $user->username, $user->getId()), $e, self::class);
         throw $e;
     }
 }
开发者ID:blitzik,项目名称:vycetky-doctrine,代码行数:15,代码来源:UsersWriter.php

示例13: delete

 /**
  * @param $albumId
  */
 public function delete($albumId)
 {
     /**
      * @var Album $album
      */
     $album = $this->albumDao->find($albumId);
     $album->delete();
     $this->em->persist($album);
     $this->em->flush();
 }
开发者ID:peterkrejci,项目名称:music-collection,代码行数:13,代码来源:AlbumModel.php

示例14: saveListing

 /**
  * @param Listing $listing
  * @return Listing
  * @throws \Exception
  */
 public function saveListing(Listing $listing)
 {
     try {
         $this->em->persist($listing)->flush();
         return $listing;
     } catch (\Exception $e) {
         $this->onCritical('Saving of Listing failed. [saveListing]', $e, self::class);
         throw $e;
     }
 }
开发者ID:blitzik,项目名称:vycetky-doctrine,代码行数:15,代码来源:ListingsWriter.php

示例15: update

 public function update($entityClass, array $items)
 {
     $position = 1;
     foreach ($items as $id) {
         $entity = $this->em->find($entityClass, $id);
         $entity->setPosition($position * 10);
         $this->em->persist($entity);
         $position++;
     }
     $this->em->flush();
 }
开发者ID:lexinek,项目名称:doctrine-behaviors,代码行数:11,代码来源:Organiser.php


注:本文中的Kdyby\Doctrine\EntityManager::persist方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。