當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。