• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP ORM\UnitOfWork类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Doctrine\ORM\UnitOfWork的典型用法代码示例。如果您正苦于以下问题:PHP UnitOfWork类的具体用法?PHP UnitOfWork怎么用?PHP UnitOfWork使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1:

 function it_clears_the_import_cache(DoctrineCache $doctrineCache, EntityManager $entityManager, UnitOfWork $uow)
 {
     $this->setNonClearableEntities(['NonClearable']);
     $uow->getIdentityMap()->willReturn(['NonClearable' => [], 'Clearable' => []]);
     $entityManager->clear('Clearable')->shouldBeCalled();
     $doctrineCache->clear(['NonClearable'])->shouldBeCalled();
     $this->clear();
 }
开发者ID:javiersantos,项目名称:pim-community-dev,代码行数:8,代码来源:CacheClearerSpec.php


示例2: testRetrieveUserTracker

 public function testRetrieveUserTracker()
 {
     $user = new User();
     $tracker = $this->tracker();
     $this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->unitOfWork));
     $this->unitOfWork->expects($this->once())->method('getEntityPersister')->with(self::CLASS_NAME)->will($this->returnValue($this->entityPersister));
     $this->entityPersister->expects($this->once())->method('load')->with(['user' => $user], null, null, [], 0, 1, null)->will($this->returnValue($tracker));
     $this->repository->retrieveUserTracker($user);
 }
开发者ID:vdrizheruk,项目名称:OroCrmTimeLapBundle,代码行数:9,代码来源:DoctrineTimeTrackingRecordRepositoryTest.php


示例3: isValidEntityState

 /**
  * Check if entity is in a valid state for operations.
  *
  * @param object $entity
  *
  * @return bool
  */
 protected function isValidEntityState($entity)
 {
     $entityState = $this->uow->getEntityState($entity, UnitOfWork::STATE_NEW);
     if ($entityState === UnitOfWork::STATE_NEW) {
         return false;
     }
     // If Entity is scheduled for inclusion, it is not in this collection.
     // We can assure that because it would have return true before on array check
     return !($entityState === UnitOfWork::STATE_MANAGED && $this->uow->isScheduledForInsert($entity));
 }
开发者ID:StoshSeb,项目名称:doctrine2,代码行数:17,代码来源:AbstractCollectionPersister.php


示例4: thatApiUserRetrievesByUsername

 /**
  * @test
  */
 public function thatApiUserRetrievesByUsername()
 {
     $email = '[email protected]';
     $apiUser = $this->getApiUser();
     $this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->unitOfWork));
     $this->unitOfWork->expects($this->once())->method('getEntityPersister')->with($this->equalTo(self::DUMMY_CLASS_NAME))->will($this->returnValue($this->entityPersister));
     $this->entityPersister->expects($this->once())->method('load')->with($this->equalTo(array('email' => $email)), $this->equalTo(null), $this->equalTo(null), array(), $this->equalTo(0), $this->equalTo(1), $this->equalTo(null))->will($this->returnValue($apiUser));
     $retrievedApiUser = $this->repository->findOneBy(array('email' => $email));
     $this->assertNotNull($retrievedApiUser);
     $this->assertEquals($apiUser, $retrievedApiUser);
 }
开发者ID:gitter-badger,项目名称:diamantedesk-application,代码行数:14,代码来源:DoctrineApiUserRepositoryTest.php


示例5: testFindAllByTicket

 public function testFindAllByTicket()
 {
     $messageReference = $this->getMessageReference();
     $ticket = $messageReference->getTicket();
     $references = array($messageReference);
     $this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->unitOfWork));
     $this->unitOfWork->expects($this->once())->method('getEntityPersister')->with($this->equalTo(self::DUMMY_CLASS_NAME))->will($this->returnValue($this->entityPersister));
     $this->entityPersister->expects($this->once())->method('loadAll')->with($this->equalTo(array('ticket' => $ticket)), null, null, null)->will($this->returnValue($references));
     $result = $this->repository->findAllByTicket($ticket);
     $this->assertEquals($references, $result);
 }
开发者ID:northdakota,项目名称:DiamanteDeskBundle,代码行数:11,代码来源:DoctrineMessageReferenceRepositoryTest.php


示例6: thatBranchEmailConfigurationRetrievesByBranchId

 /**
  * @test
  */
 public function thatBranchEmailConfigurationRetrievesByBranchId()
 {
     $branchId = 1;
     $branchEmailConfiguration = $this->getBranchEmailConfiguartion();
     $this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->unitOfWork));
     $this->unitOfWork->expects($this->once())->method('getEntityPersister')->with($this->equalTo(self::DUMMY_CLASS_NAME))->will($this->returnValue($this->entityPersister));
     $this->entityPersister->expects($this->once())->method('load')->with($this->equalTo(array('branchId' => $branchId)), $this->equalTo(null), $this->equalTo(null), array(), $this->equalTo(0), $this->equalTo(1), $this->equalTo(null))->will($this->returnValue($branchEmailConfiguration));
     $retrievedBranchEmailConfiguration = $this->repository->findOneBy(array('branchId' => $branchId));
     $this->assertNotNull($retrievedBranchEmailConfiguration);
     $this->assertEquals($branchEmailConfiguration, $retrievedBranchEmailConfiguration);
 }
开发者ID:northdakota,项目名称:DiamanteDeskBundle,代码行数:14,代码来源:DoctrineBranchEmailConfigurationRepositoryTest.php


示例7: getChangeSet

 /**
  * Get an array describing the changes.
  *
  * @param UnitOfWork $unitOfWork
  * @param TermOfUse  $entity
  * @param string     $action
  *
  * @return array
  */
 protected function getChangeSet(UnitOfWork $unitOfWork, TermOfUse $entity, $action)
 {
     switch ($action) {
         case 'create':
             return array('id' => array(null, $entity->getId()), 'weight' => array(null, $entity->getWeight()), 'keyCode' => array(null, $entity->getKeyCode()), 'langCode' => array(null, $entity->getLangCode()), 'content' => array(null, $entity->getContent()), 'created' => array(null, $entity->getCreated()), 'updated' => array(null, $entity->getUpdated()));
         case 'update':
             return $unitOfWork->getEntityChangeSet($entity);
         case 'delete':
             return array('id' => array($entity->getId(), null), 'weight' => array($entity->getWeight(), null), 'keyCode' => array($entity->getKeyCode(), null), 'langCode' => array($entity->getLangCode(), null), 'content' => array($entity->getContent(), null), 'created' => array($entity->getCreated(), null), 'updated' => array($entity->getUpdated(), null));
     }
 }
开发者ID:ubermichael,项目名称:pkppln-php,代码行数:20,代码来源:TermsOfUseListener.php


示例8: processInsertionOrUpdateEntity

 /**
  * @param $emailField
  * @param mixed $entity
  * @param EmailOwnerInterface $owner
  * @param EntityManager $em
  * @param UnitOfWork $uow
  */
 protected function processInsertionOrUpdateEntity($emailField, $entity, EmailOwnerInterface $owner, EntityManager $em, UnitOfWork $uow)
 {
     if (!empty($emailField)) {
         foreach ($uow->getEntityChangeSet($entity) as $field => $vals) {
             if ($field === $emailField) {
                 list($oldValue, $newValue) = $vals;
                 if ($newValue !== $oldValue) {
                     $this->bindEmailAddress($em, $owner, $newValue, $oldValue);
                 }
             }
         }
     }
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:20,代码来源:EmailOwnerManager.php


示例9: setUp

 public function setUp()
 {
     $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $this->uow = $this->getMockBuilder('Doctrine\\ORM\\UnitOfWork')->disableOriginalConstructor()->getMock();
     $this->persister = $this->getMockBuilder('Doctrine\\ORM\\Persisters\\BasicEntityPersister')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->any())->method('getUnitOfWork')->will($this->returnValue($this->uow));
     $this->uow->expects($this->any())->method('getEntityPersister')->with('stdClass')->will($this->returnValue($this->persister));
     $this->entity = new stdClass();
     $metadata = new ClassMetadata('stdClass');
     $metadata->fieldMappings = array('property' => 'property');
     $metadata->identifier = array('id');
     $this->repository = new EntityRepository($this->em, $metadata);
 }
开发者ID:lstrojny,项目名称:doctrine-fun,代码行数:13,代码来源:EntityRepositoryTest.php


示例10: createCalendar

 /**
  * @param EntityManager $em
  * @param UnitOfWork    $uow
  * @param User          $entity
  * @param Organization  $organization
  */
 protected function createCalendar($em, $uow, $entity, $organization)
 {
     // create a default calendar for assigned organization
     $calendar = new Calendar();
     $calendar->setOwner($entity);
     $calendar->setOrganization($organization);
     // connect the calendar to itself
     $calendarConnection = new CalendarConnection($calendar);
     $calendar->addConnection($calendarConnection);
     $em->persist($calendar);
     $em->persist($calendarConnection);
     $uow->computeChangeSet($this->getClassMetadata($calendar, $em), $calendar);
     $uow->computeChangeSet($this->getClassMetadata($calendarConnection, $em), $calendarConnection);
 }
开发者ID:xamin123,项目名称:platform,代码行数:20,代码来源:EntityListener.php


示例11: thatGetsAll

 /**
  * @test
  */
 public function thatGetsAll()
 {
     $entities = array(new EntityStub(), new EntityStub());
     $this->em->expects($this->once())->method('getUnitOfWork')->will($this->returnValue($this->unitOfWork));
     $this->unitOfWork->expects($this->once())->method('getEntityPersister')->with($this->equalTo(self::CLASS_NAME))->will($this->returnValue($this->entityPersister));
     $this->entityPersister->expects($this->once())->method('loadAll')->with($this->equalTo(array()), $this->equalTo(null), $this->equalTo(null), $this->equalTo(null))->will($this->returnValue($entities));
     $retrievedEntities = $this->repository->getAll();
     $this->assertEquals($entities, $retrievedEntities);
 }
开发者ID:gitter-badger,项目名称:diamantedesk-application,代码行数:12,代码来源:DoctrineGenericRepositoryTest.php


示例12: collectUpdates

 /**
  * Collect updated activities
  *
  * @param UnitOfWork $uof
  */
 protected function collectUpdates(UnitOfWork $uof)
 {
     $entities = $uof->getScheduledEntityUpdates();
     foreach ($entities as $hash => $entity) {
         if ($this->activityListManager->isSupportedEntity($entity) && empty($this->updatedEntities[$hash])) {
             $this->updatedEntities[$hash] = $entity;
         }
     }
     $updatedCollections = array_merge($uof->getScheduledCollectionUpdates(), $uof->getScheduledCollectionDeletions());
     foreach ($updatedCollections as $hash => $collection) {
         /** @var $collection PersistentCollection */
         $ownerEntity = $collection->getOwner();
         $entityHash = spl_object_hash($ownerEntity);
         if ($this->activityListManager->isSupportedEntity($ownerEntity) && $this->doctrineHelper->getSingleEntityIdentifier($ownerEntity) !== null && empty($this->updatedEntities[$entityHash])) {
             $this->updatedEntities[$entityHash] = $ownerEntity;
         }
     }
 }
开发者ID:nmallare,项目名称:platform,代码行数:23,代码来源:ActivityListListener.php


示例13: serialize

 /**
  * Serialize data of WorkflowItem
  *
  * @param WorkflowItem $workflowItem
  * @param UnitOfWork $uow
  */
 protected function serialize(WorkflowItem $workflowItem, UnitOfWork $uow)
 {
     if ($workflowItem->getData()->isModified()) {
         $oldValue = $workflowItem->getSerializedData();
         $this->serializer->setWorkflowName($workflowItem->getWorkflowName());
         $serializedData = $this->serializer->serialize($workflowItem->getData(), $this->format);
         $workflowItem->setSerializedData($serializedData);
         $uow->propertyChanged($workflowItem, 'serializedData', $oldValue, $serializedData);
     }
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:16,代码来源:WorkflowDataSerializeSubscriber.php


示例14: flattenIdentifier

 /**
  * convert foreign identifiers into scalar foreign key values to avoid object to string conversion failures.
  *
  * @param ClassMetadata $class
  * @param array         $id
  *
  * @return array
  */
 public function flattenIdentifier(ClassMetadata $class, array $id)
 {
     $flatId = array();
     foreach ($class->identifier as $field) {
         if (isset($class->associationMappings[$field]) && isset($id[$field]) && is_object($id[$field])) {
             /* @var $targetClassMetadata ClassMetadata */
             $targetClassMetadata = $this->metadataFactory->getMetadataFor($class->associationMappings[$field]['targetEntity']);
             if ($this->unitOfWork->isInIdentityMap($id[$field])) {
                 $associatedId = $this->flattenIdentifier($targetClassMetadata, $this->unitOfWork->getEntityIdentifier($id[$field]));
             } else {
                 $associatedId = $this->flattenIdentifier($targetClassMetadata, $targetClassMetadata->getIdentifierValues($id[$field]));
             }
             $flatId[$field] = implode(' ', $associatedId);
         } elseif (isset($class->associationMappings[$field])) {
             $associatedId = array();
             foreach ($class->associationMappings[$field]['joinColumns'] as $joinColumn) {
                 $associatedId[] = $id[$joinColumn['name']];
             }
             $flatId[$field] = implode(' ', $associatedId);
         } else {
             $flatId[$field] = $id[$field];
         }
     }
     return $flatId;
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:33,代码来源:IdentifierFlattener.php


示例15: testSourceModified

 public function testSourceModified()
 {
     $changeset = ['datetimeLastVisited' => [null, new \DateTime()], 'data' => [null, ['foo' => 'bar']]];
     $this->uow->expects($this->once())->method('getEntityChangeSet')->will($this->returnValue($changeset));
     $listener = new SourceModificationListenerMock($this->sourceProcessor, $this->queueManager);
     $this->assertTrue($listener->visibleIsSourceModified(new SourceMock(12345), $this->uow));
 }
开发者ID:mvanduijker,项目名称:FMIoBundle,代码行数:7,代码来源:SourceModificationListenerTest.php


示例16: onFlush

 public function onFlush(OnFlushEventArgs $e)
 {
     $this->init($e);
     foreach ($this->uow->getScheduledEntityInsertions() as $entity) {
         if ($entity instanceof RoundedEntityInterface) {
             $entity->setRound($this->round);
             $this->uow->recomputeSingleEntityChangeSet($this->em->getClassMetadata(get_class($entity)), $entity);
         }
     }
     //$this->uow->computeChangeSets();
 }
开发者ID:RinWorld,项目名称:Ponzi-1,代码行数:11,代码来源:RoundListener.php


示例17: transform

 /**
  * @param Object $entity
  * @return string
  */
 public function transform($entity)
 {
     if (null === $entity || '' === $entity) {
         return 'null';
     }
     if (!is_object($entity)) {
         throw new UnexpectedTypeException($entity, 'object');
     }
     if (!$this->unitOfWork->isInIdentityMap($entity)) {
         throw new InvalidArgumentException('Entities passed to the choice field must be managed');
     }
     return $entity->getId();
 }
开发者ID:GrossumUA,项目名称:ExtendedFormTypeBundle,代码行数:17,代码来源:EntityToIdTransformer.php


示例18: flattenIdentifier

 /**
  * convert foreign identifiers into scalar foreign key values to avoid object to string conversion failures.
  *
  * @param \Doctrine\ORM\Mapping\ClassMetadata $class
  * @param array $id
  * @return array
  */
 public function flattenIdentifier(ClassMetadata $class, array $id)
 {
     $flatId = array();
     foreach ($id as $idField => $idValue) {
         if (isset($class->associationMappings[$idField]) && is_object($idValue)) {
             $targetClassMetadata = $this->metadataFactory->getMetadataFor($class->associationMappings[$idField]['targetEntity']);
             $associatedId = $this->unitOfWork->getEntityIdentifier($idValue);
             $flatId[$idField] = $associatedId[$targetClassMetadata->identifier[0]];
         } else {
             $flatId[$idField] = $idValue;
         }
     }
     return $flatId;
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:21,代码来源:IdentifierFlattener.php


示例19: deleteOnRelationalModification

 /**
  * Deletes an entity if it is in relation to another entity
  *
  * Doctrine is obviously unable to entities detached from the relational entity when merging the relational entity,
  * so this had to be implemented.
  *
  * @param object $relationalEntity
  * @param string $fieldName
  * @param ClassMetadata $metadata
  * @param boolean $recomputeChangeSet
  */
 public function deleteOnRelationalModification($relationalEntity, $fieldName, ClassMetadata $metadata, $recomputeChangeSet = true)
 {
     if ($recomputeChangeSet) {
         $this->unitOfWork->computeChangeSet($metadata, $relationalEntity);
     }
     $changeSet = $this->unitOfWork->getEntityChangeSet($relationalEntity);
     if (!isset($changeSet[$fieldName])) {
         return;
     }
     $orgValue = $changeSet[$fieldName][0];
     if (null !== $orgValue && $this->entityManager->contains($orgValue)) {
         $this->entityManager->remove($orgValue);
     }
 }
开发者ID:thesoftwarefactoryuk,项目名称:SenNetwork,代码行数:25,代码来源:EnhancedCascadingPersister.php


示例20: startAutoReply

 /**
  * @param Ticket $ticket
  */
 protected function startAutoReply(Ticket $ticket)
 {
     $ticketText = $ticket->getSubject() . ' ' . $ticket->getDescription();
     $repository = $this->registry->getManager()->getRepository('DiamanteDeskBundle:Article');
     $results = [];
     /** @var Article $article */
     foreach ($repository->findByStatus(1) as $article) {
         $articleText = $article->getTitle() . ' ' . $article->getContent();
         $results[$article->getId()] = $this->compare($ticketText, $articleText);
     }
     $maxResult = max($results);
     /**
      * TODO: should be configured by admin
      */
     if ($maxResult < 3) {
         return;
     }
     $articleId = array_search(max($results), $results);
     /**
      * TODO: should be extracted from previous call of $repository->getAll()
      */
     $article = $repository->find($articleId);
     /**
      * TODO: should be extracted from configuration???
      */
     $user = User::fromString('oro_1');
     $content = $this->getAutoReplayNoticeHtml() . $article->getContent();
     $comment = new Comment($content, $ticket, $user, false);
     $this->registry->getManager()->persist($comment);
     $this->uow->computeChangeSet($this->em->getClassMetadata($comment->getClassName()), $comment);
     /**
      * TODO: should be executed workflowEven?
      */
 }
开发者ID:northdakota,项目名称:diamantedesk-application,代码行数:37,代码来源:ArticleAutoReplyServiceImpl.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Event\LifecycleEventArgs类代码示例发布时间:2022-05-23
下一篇:
PHP ORM\TransactionRequiredException类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap