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


PHP EntityManagerInterface::getUnitOfWork方法代码示例

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


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

示例1: putCollectionCacheEntry

 /**
  * @param string $className
  * @param string $association
  * @param array $ownerIdentifier
  * @param array $data
  */
 private function putCollectionCacheEntry($className, $association, array $ownerIdentifier, array $data)
 {
     $metadata = $this->em->getClassMetadata($className);
     $cacheKey = new CollectionCacheKey($metadata->name, $association, $ownerIdentifier);
     $cacheEntry = new CollectionCacheEntry($data);
     $persister = $this->em->getUnitOfWork()->getCollectionPersister($metadata->getAssociationMapping($association));
     $persister->getCacheRegion()->put($cacheKey, $cacheEntry);
 }
开发者ID:selimcr,项目名称:servigases,代码行数:14,代码来源:DefaultCacheTest.php

示例2: hasGameAlreadyStarted

 /**
  * @param Game $game
  * @return bool
  */
 protected function hasGameAlreadyStarted(Game $game)
 {
     $unitOfWork = $this->entityManager->getUnitOfWork();
     $changes = $unitOfWork->getEntityChangeSet($game);
     $changeFieldKey = sprintf('user%dShips', $game->getPlayerNumber());
     // old ships if changed, or current ships
     $playerShipsBeforeChanges = isset($changes[$changeFieldKey]) ? $changes[$changeFieldKey][0] : $game->getPlayerShips();
     // game started if ships already set
     return count($playerShipsBeforeChanges) > 0;
 }
开发者ID:jlekowski,项目名称:battleships-api,代码行数:14,代码来源:OnlyBeforeStartValidator.php

示例3: testCreateOriginalEntityIdentity

 public function testCreateOriginalEntityIdentity()
 {
     $gallery = new Gallery('Riverstreet 12');
     $gallery->addVisitor('Foo de Bar');
     $this->em->persist($gallery);
     $this->em->flush();
     $gallery->addVisitor('Bar Baz');
     $this->em->getUnitOfWork()->computeChangeSets();
     $this->em->flush();
     $original = $this->provider->createOriginalEntity($this->em, $gallery);
     self::assertSame($gallery->getId(), $original->getId());
 }
开发者ID:hostnet,项目名称:entity-tracker-component,代码行数:12,代码来源:EntityMutationMetadataProviderTest.php

示例4: setUpdatedAt

 /**
  * Set updated at to current DateTime when related entities updated
  * TODO: consider refactoring of this feature to make it applicable to all entities
  *
  * @param Contact $entity
  */
 protected function setUpdatedAt(Contact $entity)
 {
     /** @var UnitOfWork $uow */
     $uow = $this->manager->getUnitOfWork();
     $uow->computeChangeSets();
     $isEntityChanged = count($uow->getEntityChangeSet($entity)) > 0;
     $isRelationChanged = count($uow->getScheduledEntityUpdates()) > 0 || count($uow->getScheduledCollectionUpdates()) > 0 || count($uow->getScheduledCollectionDeletions()) > 0;
     if (false === $isEntityChanged && $isRelationChanged) {
         $entity->setUpdatedAt(new \DateTime('now', new \DateTimeZone('UTC')));
         $this->manager->persist($entity);
     }
 }
开发者ID:mehulsbhatt,项目名称:crm,代码行数:18,代码来源:ContactHandler.php

示例5: prepare

 private function prepare($data)
 {
     $metaDataClass = $this->entityManager->getClassMetadata(get_class($data));
     $assocFields = $metaDataClass->getAssociationMappings();
     foreach ($assocFields as $assoc) {
         $relatedEntities = $metaDataClass->reflFields[$assoc['fieldName']]->getValue($data);
         if ($relatedEntities instanceof Collection) {
             if ($relatedEntities === $metaDataClass->reflFields[$assoc['fieldName']]->getValue($data)) {
                 continue;
             }
             if ($relatedEntities instanceof PersistentCollection) {
                 // Unwrap so that foreach() does not initialize
                 $relatedEntities = $relatedEntities->unwrap();
             }
             foreach ($relatedEntities as $relatedEntity) {
                 $relatedEntitiesState = $this->entityManager->getUnitOfWork()->getEntityState($relatedEntities);
                 if ($relatedEntitiesState === UnitOfWork::STATE_DETACHED) {
                     $metaDataClass->setFieldValue($data, $assoc['fieldName'], $this->entityManager->merge($relatedEntity));
                 }
             }
         } else {
             if ($relatedEntities !== null) {
                 $relatedEntitiesState = $this->entityManager->getUnitOfWork()->getEntityState($relatedEntities);
                 if ($relatedEntitiesState === UnitOfWork::STATE_DETACHED) {
                     $metaDataClass->setFieldValue($data, $assoc['fieldName'], $this->entityManager->merge($relatedEntities));
                 }
             }
         }
     }
 }
开发者ID:pbrazhko,项目名称:form-wizard-bundle-for-symfony,代码行数:30,代码来源:WizardStorage.php

示例6: processParameterValue

 /**
  * Processes an individual parameter value.
  *
  * @param mixed $value
  *
  * @return array|string
  *
  * @throws \Doctrine\ORM\ORMInvalidArgumentException
  */
 public function processParameterValue($value)
 {
     if (is_scalar($value)) {
         return $value;
     }
     if ($value instanceof Collection) {
         $value = $value->toArray();
     }
     if (is_array($value)) {
         foreach ($value as $key => $paramValue) {
             $paramValue = $this->processParameterValue($paramValue);
             $value[$key] = is_array($paramValue) ? reset($paramValue) : $paramValue;
         }
         return $value;
     }
     if (is_object($value) && $this->_em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($value))) {
         $value = $this->_em->getUnitOfWork()->getSingleIdentifierValue($value);
         if ($value === null) {
             throw ORMInvalidArgumentException::invalidIdentifierBindingEntity();
         }
     }
     if ($value instanceof Mapping\ClassMetadata) {
         return $value->name;
     }
     return $value;
 }
开发者ID:AlexanderForks,项目名称:doctrine2,代码行数:35,代码来源:AbstractQuery.php

示例7: __construct

 /**
  * Initializes a new instance of a class derived from AbstractCollectionPersister.
  *
  * @param EntityManagerInterface $em
  */
 public function __construct(EntityManagerInterface $em)
 {
     $this->em = $em;
     $this->uow = $em->getUnitOfWork();
     $this->conn = $em->getConnection();
     $this->platform = $this->conn->getDatabasePlatform();
     $this->quoteStrategy = $em->getConfiguration()->getQuoteStrategy();
 }
开发者ID:Dren-x,项目名称:mobitnew,代码行数:13,代码来源:AbstractCollectionPersister.php

示例8: onFlushPage

 /**
  * Occur on nestednode.page.preupdate events and nestednode.section.preupdate.
  *
  * @access public
  *
  * @param Event $event
  */
 public function onFlushPage(Event $event)
 {
     $uow = $this->entityManager->getUnitOfWork();
     $page = $event->getTarget();
     if ($uow->isScheduledForInsert($page) && $page->getParent() !== null && $page->getState() < 4) {
         self::setSectionHasChildren($page->getParent()->getSection(), +1);
     }
 }
开发者ID:ReissClothing,项目名称:BackBee,代码行数:15,代码来源:PageListener.php

示例9: __construct

 /**
  * @param \Doctrine\ORM\EntityManagerInterface $em     The entity manager.
  * @param \Doctrine\ORM\Cache\Region           $region The query region.
  */
 public function __construct(EntityManagerInterface $em, Region $region)
 {
     $cacheConfig = $em->getConfiguration()->getSecondLevelCacheConfiguration();
     $this->em = $em;
     $this->region = $region;
     $this->uow = $em->getUnitOfWork();
     $this->cacheLogger = $cacheConfig->getCacheLogger();
     $this->validator = $cacheConfig->getQueryValidator();
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:13,代码来源:DefaultQueryCache.php

示例10: __construct

 /**
  * Initializes a new instance of the <tt>ProxyFactory</tt> class that is
  * connected to the given <tt>EntityManager</tt>.
  *
  * @param EntityManagerInterface $em           The EntityManager the new factory works for.
  * @param string                 $proxyDir     The directory to use for the proxy classes. It must exist.
  * @param string                 $proxyNs      The namespace to use for the proxy classes.
  * @param boolean|int            $autoGenerate The strategy for automatically generating proxy classes. Possible
  *                                             values are constants of Doctrine\Common\Proxy\AbstractProxyFactory.
  */
 public function __construct(EntityManagerInterface $em, $proxyDir, $proxyNs, $autoGenerate = AbstractProxyFactory::AUTOGENERATE_NEVER)
 {
     $proxyGenerator = new ProxyGenerator($proxyDir, $proxyNs);
     $proxyGenerator->setPlaceholder('baseProxyInterface', 'Doctrine\\ORM\\Proxy\\Proxy');
     parent::__construct($proxyGenerator, $em->getMetadataFactory(), $autoGenerate);
     $this->em = $em;
     $this->uow = $em->getUnitOfWork();
     $this->proxyNs = $proxyNs;
     $this->identifierFlattener = new IdentifierFlattener($this->uow, $em->getMetadataFactory());
 }
开发者ID:aschempp,项目名称:doctrine2,代码行数:20,代码来源:ProxyFactory.php

示例11: registerManaged

 /**
  * Register entity as managed in UnitOfWork.
  *
  * @param ClassMetadata $class
  * @param object        $entity
  * @param array         $data
  *
  * @return void
  *
  * @todo The "$id" generation is the same of UnitOfWork#createEntity. Remove this duplication somehow
  */
 protected function registerManaged(ClassMetadata $class, $entity, array $data)
 {
     if ($class->isIdentifierComposite) {
         $id = array();
         foreach ($class->identifier as $fieldName) {
             $id[$fieldName] = isset($class->associationMappings[$fieldName]) ? $data[$class->associationMappings[$fieldName]['joinColumns'][0]['name']] : $data[$fieldName];
         }
     } else {
         $fieldName = $class->identifier[0];
         $id = array($fieldName => isset($class->associationMappings[$fieldName]) ? $data[$class->associationMappings[$fieldName]['joinColumns'][0]['name']] : $data[$fieldName]);
     }
     $this->_em->getUnitOfWork()->registerManaged($entity, $id, $data);
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:24,代码来源:AbstractHydrator.php

示例12: dumpIdentityMap

 /**
  * Dumps the contents of the identity map into a stream.
  *
  * @param EntityManagerInterface $em
  *
  * @return void
  */
 public function dumpIdentityMap(EntityManagerInterface $em)
 {
     $uow = $em->getUnitOfWork();
     $identityMap = $uow->getIdentityMap();
     $fh = fopen($this->file, "x+");
     if (count($identityMap) == 0) {
         fwrite($fh, "Flush Operation [" . $this->context . "] - Empty identity map.\n");
         return;
     }
     fwrite($fh, "Flush Operation [" . $this->context . "] - Dumping identity map:\n");
     foreach ($identityMap as $className => $map) {
         fwrite($fh, "Class: " . $className . "\n");
         foreach ($map as $entity) {
             fwrite($fh, " Entity: " . $this->getIdString($entity, $uow) . " " . spl_object_hash($entity) . "\n");
             fwrite($fh, "  Associations:\n");
             $cm = $em->getClassMetadata($className);
             foreach ($cm->associationMappings as $field => $assoc) {
                 fwrite($fh, "   " . $field . " ");
                 $value = $cm->getFieldValue($entity, $field);
                 if ($assoc['type'] & ClassMetadata::TO_ONE) {
                     if ($value === null) {
                         fwrite($fh, " NULL\n");
                     } else {
                         if ($value instanceof Proxy && !$value->__isInitialized()) {
                             fwrite($fh, "[PROXY] ");
                         }
                         fwrite($fh, $this->getIdString($value, $uow) . " " . spl_object_hash($value) . "\n");
                     }
                 } else {
                     $initialized = !$value instanceof PersistentCollection || $value->isInitialized();
                     if ($value === null) {
                         fwrite($fh, " NULL\n");
                     } elseif ($initialized) {
                         fwrite($fh, "[INITIALIZED] " . $this->getType($value) . " " . count($value) . " elements\n");
                         foreach ($value as $obj) {
                             fwrite($fh, "    " . $this->getIdString($obj, $uow) . " " . spl_object_hash($obj) . "\n");
                         }
                     } else {
                         fwrite($fh, "[PROXY] " . $this->getType($value) . " unknown element size\n");
                         foreach ($value->unwrap() as $obj) {
                             fwrite($fh, "    " . $this->getIdString($obj, $uow) . " " . spl_object_hash($obj) . "\n");
                         }
                     }
                 }
             }
         }
     }
     fclose($fh);
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:56,代码来源:DebugUnitOfWorkListener.php

示例13: cleanUpEvent

 /**
  * Update all properties to ical requirements and apply changes to dependent attributes:
  * - set $dtStart and $dtEnd according to the selected values from $dateFrom, $timeFrom, $dateTo and $timeTo
  * - remove $recurrenceRule if it's $frequency is empty
  * - set $recurrenceRule's $byDay value to null if empty
  * - apply changed $dtStart values to $excludedDates
  * Must be executed on persisting the event. Should be called prior to any validation.
  *
  * @param Event $event
  */
 public function cleanUpEvent(Event $event)
 {
     if ($event->getDateFrom()) {
         //merge dates and times, apply noTime setting
         $event->setDtStart($event->getDateFrom());
         if (is_null($event->getTimeFrom())) {
             $event->getDtStart()->setTime(0, 0);
             $event->setTimeFrom(new \DateTime('1970-01-01'));
         } else {
             $event->getDtStart()->setTime($event->getTimeFrom()->format('H'), $event->getTimeFrom()->format('i'));
         }
     }
     if ($event->getDateTo()) {
         $event->setDtEnd(clone $event->getDateTo());
         if (is_null($event->getTimeTo())) {
             $event->getDtEnd()->setTime(0, 0);
             $event->setTimeTo(new \DateTime('1970-01-01'));
         } else {
             $event->getDtEnd()->setTime($event->getTimeTo()->format('H'), $event->getTimeTo()->format('i'));
         }
         if ($event->isNoTime()) {
             $event->getDtEnd()->add(new \DateInterval('P1D'));
         }
     }
     //do the following only if event is recurring
     if ($event->getRecurrenceRule()) {
         //remove recurring rule if empty and nullify "byDay" property if empty
         if ('' == $event->getRecurrenceRule()->getFreq()) {
             $this->em->remove($event->getRecurrenceRule());
             $event->removeRecurrenceRule();
         } elseif ('' == $event->getRecurrenceRule()->getByDay()) {
             $event->getRecurrenceRule()->setByDay(null);
         }
         //update excludeDates
         /** @var $entity \Xima\ICalBundle\Entity\Component\Event */
         $uow = $this->em->getUnitOfWork();
         $changeSet = $uow->getEntityChangeSet($event);
         if (isset($changeSet['dtStart']) && isset($changeSet['dtStart'][0])) {
             $interval = $changeSet['dtStart'][0]->diff($event->getDtStart());
             foreach ($event->getExDates() as $dateTime) {
                 $dateTime->add($interval);
             }
         }
     }
 }
开发者ID:xima-media,项目名称:ical-bundle,代码行数:55,代码来源:EventUtil.php

示例14: doInitialize

 /**
  * {@inheritdoc}
  */
 protected function doInitialize()
 {
     // Has NEW objects added through add(). Remember them.
     $newObjects = array();
     if ($this->isDirty) {
         $newObjects = $this->collection->toArray();
     }
     $this->collection->clear();
     $this->em->getUnitOfWork()->loadCollection($this);
     $this->takeSnapshot();
     // Reattach NEW objects added through add(), if any.
     if ($newObjects) {
         foreach ($newObjects as $obj) {
             $this->collection->add($obj);
         }
         $this->isDirty = true;
     }
 }
开发者ID:karvannan-thi,项目名称:doctrine2,代码行数:21,代码来源:PersistentCollection.php

示例15: matching

 /**
  * Selects all elements from a selectable that match the expression and
  * return a new collection containing these elements.
  *
  * @param \Doctrine\Common\Collections\Criteria $criteria
  *
  * @return Collection
  *
  * @throws \RuntimeException
  */
 public function matching(Criteria $criteria)
 {
     if ($this->isDirty) {
         $this->initialize();
     }
     if ($this->initialized) {
         return $this->collection->matching($criteria);
     }
     if ($this->association['type'] === ClassMetadata::MANY_TO_MANY) {
         $persister = $this->em->getUnitOfWork()->getCollectionPersister($this->association);
         return new ArrayCollection($persister->loadCriteria($this, $criteria));
     }
     $builder = Criteria::expr();
     $ownerExpression = $builder->eq($this->backRefFieldName, $this->owner);
     $expression = $criteria->getWhereExpression();
     $expression = $expression ? $builder->andX($expression, $ownerExpression) : $ownerExpression;
     $criteria = clone $criteria;
     $criteria->where($expression);
     $persister = $this->em->getUnitOfWork()->getEntityPersister($this->association['targetEntity']);
     return $this->association['fetch'] === ClassMetadataInfo::FETCH_EXTRA_LAZY ? new LazyCriteriaCollection($persister, $criteria) : new ArrayCollection($persister->loadCriteria($criteria));
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:31,代码来源:PersistentCollection.php


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