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


PHP EntityManager::persist方法代码示例

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


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

示例1: getOrCreateUser

 /**
  * {@inheritDoc}
  */
 public function getOrCreateUser($email, $googleId)
 {
     if ($this->isConfiguredDomain($email)) {
         $user = $this->userFinder->findUserByGoogleSignInData($email, $googleId);
         if (!$user instanceof $this->userClass) {
             //User not present in database, create new one
             $user = new $this->userClass();
             $user->setUsername($email);
             $user->setEmail($email);
             $user->setPlainPassword($googleId . $email . time());
             $user->setEnabled(true);
             $user->setLocked(false);
             $user->setAdminLocale('en');
             $user->setPasswordChanged(true);
         }
         foreach ($this->getAccessLevels($email) as $accessLevel) {
             $user->addRole($accessLevel);
         }
         $user->setGoogleId($googleId);
         // Persist
         $this->em->persist($user);
         $this->em->flush();
     }
     return isset($user) ? $user : null;
 }
开发者ID:bakie,项目名称:KunstmaanBundlesCMS,代码行数:28,代码来源:OAuthUserCreator.php

示例2: testReverseTransform

 public function testReverseTransform()
 {
     $transformer = $this->createTransformer();
     $tag = new Tag("name");
     $this->em->persist($tag);
     $this->em->flush();
     $this->assertSame($tag, $transformer->reverseTransform(1, null));
 }
开发者ID:notbrain,项目名称:symfony,代码行数:8,代码来源:EntityToIDTransformerTest.php

示例3: insert

 public function insert(Entity\AvaliadorArea $avaliadorArea)
 {
     try {
         $this->em->persist($avaliadorArea);
         $this->em->flush();
     } catch (Exception $ex) {
         $this->CI->log->write_log('error', $ex->getMessage() . ' - avaliador_area_dao::insert ');
     }
 }
开发者ID:jeanlopes,项目名称:mostra-ifrs-poa,代码行数:9,代码来源:avaliador_area_dao.php

示例4: persist

 protected function persist(array $entities)
 {
     foreach ($entities as $entity) {
         $this->em->persist($entity);
     }
     $this->em->flush();
     // no clear, because entities managed by the choice field must
     // be managed!
 }
开发者ID:rooster,项目名称:symfony,代码行数:9,代码来源:EntityChoiceFieldTest.php

示例5: save

 /**
  * Save schema
  *
  * @param SchemaInterface $schema
  *
  * @return SchemaInterface
  */
 public function save(SchemaInterface $schema)
 {
     foreach ($schema->getAttributes() as $attribute) {
         $attribute->setSchema($schema);
         $this->em->persist($attribute);
     }
     $this->em->persist($schema);
     $this->em->flush();
     return $schema;
 }
开发者ID:leonverschuren,项目名称:Cms,代码行数:17,代码来源:SchemaManager.php

示例6: save

 /**
  * Save template
  *
  * @param TemplateInterface $template
  *
  * @return TemplateInterface
  */
 public function save(TemplateInterface $template)
 {
     foreach ($template->getAttributes() as $attribute) {
         $attribute->setTemplate($template);
         $this->em->persist($attribute);
     }
     $this->em->persist($template);
     $this->em->flush();
     return $template;
 }
开发者ID:NickyBeunder,项目名称:EavBundle,代码行数:17,代码来源:TemplateManager.php

示例7: createTagCollection

 public function createTagCollection()
 {
     $tags = new ArrayCollection();
     $tags->add(new Tag("foo"));
     $tags->add(new Tag("bar"));
     foreach ($tags as $tag) {
         $this->em->persist($tag);
     }
     $this->em->flush();
     $this->em->clear();
     return $tags;
 }
开发者ID:notbrain,项目名称:symfony,代码行数:12,代码来源:CollectionToChoiceTransformerTest.php

示例8: onKernelRequest

 /**
  * Method actually invoked upon dispatching an event "kernel.response"
  *
  * @param FilterResponseEvent $event
  *
  * @return void
  */
 public function onKernelRequest(GetResponseEvent $event)
 {
     if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
         return;
     }
     $token = $this->securityContext->getToken();
     if ($token instanceof UsernamePasswordToken and $token->isAuthenticated()) {
         $user = $token->getUser();
         $user->setLastActive(new \DateTime(date('Y-m-d H:i:s', time())));
         $this->entityManager->persist($user);
         $this->entityManager->flush();
     }
 }
开发者ID:thebuggl-org,项目名称:tests-buggl,代码行数:20,代码来源:LastActiveFilterListener.php

示例9: migrateData

 /**
  * Migrate data to plugin database from core table
  *
  * @param EntityManager   $em
  * @param OutputInterface $output
  *
  * @return void
  */
 public function migrateData($em, $output)
 {
     $rsm = new ResultSetMapping();
     $rsm->addEntityResult('Newscoop\\CommunityTickerBundle\\Entity\\CommunityTickerEvent', 'e');
     $rsm->addFieldResult('e', 'id', 'id');
     $rsm->addFieldResult('e', 'event', 'event');
     $rsm->addFieldResult('e', 'params', 'params');
     $rsm->addFieldResult('e', 'created', 'created');
     $rsm->addJoinedEntityResult('Newscoop\\Entity\\User', 'u', 'e', 'user');
     $rsm->addFieldResult('u', 'Id', 'id');
     $query = $em->createNativeQuery('SELECT e.id, e.event, e.params, e.created, u.Id FROM community_ticker_event e ' . 'LEFT JOIN liveuser_users u ON u.id = e.user_id', $rsm);
     $events = $query->getArrayResult();
     foreach ($events as $key => $event) {
         $user = $em->getRepository('Newscoop\\Entity\\User')->findOneBy(array('id' => $event['user']['id']));
         $existingEvent = $em->getRepository('Newscoop\\CommunityTickerBundle\\Entity\\CommunityTickerEvent')->findOneBy(array('created' => $event['created'], 'params' => $event['params']));
         if (!$existingEvent) {
             $newEvent = new CommunityTickerEvent();
             $newEvent->setEvent($event['event']);
             $newEvent->setParams($event['params'] != '[]' ? json_decode($event['params'], true) : array());
             $newEvent->setCreated($event['created']);
             $newEvent->setIsActive(true);
             if ($user) {
                 $newEvent->setUser($user);
             }
             $em->persist($newEvent);
         }
     }
     $em->flush();
     $output->writeln('<info>Data migrated to plugin table!</info>');
     $output->writeln('<info>Removing old table...</info>');
 }
开发者ID:sourcefabric,项目名称:newscoop,代码行数:39,代码来源:MigrateTablesCommand.php

示例10: testPaginator

 public function testPaginator()
 {
     $reader = $this->getAuditReader();
     $query = $reader->paginateRevisionsQuery();
     $paginatorAdapter = new \ZF2EntityAudit\Paginator\DbalAdapter($query);
     $paginator = new \Zend\Paginator\Paginator($paginatorAdapter);
     for ($i = 0; $i < 20; $i++) {
         $writer = new Writer("tawfek" . rand());
         $article = new Article("title", "text", $writer);
         $this->em->persist($writer);
         $this->em->persist($article);
     }
     $this->em->flush();
     $this->assertEquals($reader->countRevisions(), "1");
     $this->assertEquals($paginator->count(), "1");
     for ($i = 0; $i < 20; $i++) {
         $writer = new Writer("tawfek" . rand());
         $article = new Article("title", "text", $writer);
         $this->em->persist($writer);
         $this->em->persist($article);
         $this->em->flush();
     }
     // its 21 because (20 flushes + 1 flush as bluk flush in line 330 )
     $this->assertEquals($reader->countRevisions(), "21");
     $this->assertEquals($paginator->getAdapter()->count(), "21");
     $this->assertEquals(count($paginator->getAdapter()->getItems(1, 12)), "12");
 }
开发者ID:tawfekov,项目名称:zf2entityaudit,代码行数:27,代码来源:AuditTest.php

示例11: updateFreeSearchField

 /**
  * method invoked everytime an event is dispatched(guide updates)
  * @param  EguideEvent $event
  */
 public function updateFreeSearchField(EguideEvent $event)
 {
     $eguide = $event->getEguide();
     $keywords = array();
     /**
      * needs improvement
      * @var string
      */
     $categories = $eguide->getCategories();
     foreach ($categories as $category) {
         $categoryName = strtolower($category->getName());
         $keywords[] = 'activity:' . $categoryName;
     }
     $country = strtolower($eguide->getCountry()->getName());
     $locations = $eguide->getLocations();
     foreach ($locations as $location) {
         $address = 'location:' . $location->getAddress();
         $keywords[] = $address;
     }
     $keywords[] = $country;
     $keywords = implode(" ", $keywords);
     $eguide->setFreeSearch($keywords);
     $this->entityManager->persist($eguide);
     $this->entityManager->flush();
 }
开发者ID:thebuggl-org,项目名称:tests-buggl,代码行数:29,代码来源:FreeSearchEventListener.php

示例12: save

 /**
  * @param BlockInterface $block
  *
  * @return BlockManager
  */
 public function save(BlockInterface $block)
 {
     $block->setRootVersion($this->getNewVersion($block));
     $this->em->persist($block);
     $this->em->flush($block);
     return $this;
 }
开发者ID:RobertjanSchipper,项目名称:Cms,代码行数:12,代码来源:BlockManager.php

示例13: saveThread

 /**
  * Saves a thread
  *
  * @param ThreadInterface $thread
  * @param Boolean $andFlush Whether to flush the changes (default true)
  */
 public function saveThread(ThreadInterface $thread, $andFlush = true)
 {
     $this->denormalize($thread);
     $this->em->persist($thread);
     if ($andFlush) {
         $this->em->flush();
     }
 }
开发者ID:sketchmedia,项目名称:FOSMessageBundle,代码行数:14,代码来源:ThreadManager.php

示例14: saveMessage

 /**
  * Saves a message
  *
  * @param MessageInterface $message
  * @param Boolean $andFlush Whether to flush the changes (default true)
  */
 public function saveMessage(MessageInterface $message, $andFlush = true)
 {
     $this->denormalize($message);
     $this->em->persist($message);
     if ($andFlush) {
         $this->em->flush();
     }
 }
开发者ID:sketchmedia,项目名称:FOSMessageBundle,代码行数:14,代码来源:MessageManager.php

示例15: testActivityUniqueness

 /**
  * Make sure activities cannot have the same activityId per spec
  */
 public function testActivityUniqueness()
 {
     $activity = $this->activityService->denormalize(json_encode($this->getActivityData()));
     $this->em->persist($activity);
     $this->em->flush();
     $newActivity = clone $activity;
     $constraintViolationList = $this->validator->validate($newActivity);
     $this->assertEquals($constraintViolationList->count(), 1);
     $this->assertEquals($constraintViolationList->get(0)->getInvalidValue(), $activity->getActivityId());
 }
开发者ID:pr0coder,项目名称:Inkstand,代码行数:13,代码来源:ActivityServiceTest.php


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