當前位置: 首頁>>代碼示例>>PHP>>正文


PHP EntityManager::getUnitOfWork方法代碼示例

本文整理匯總了PHP中Doctrine\ORM\EntityManager::getUnitOfWork方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityManager::getUnitOfWork方法的具體用法?PHP EntityManager::getUnitOfWork怎麽用?PHP EntityManager::getUnitOfWork使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\ORM\EntityManager的用法示例。


在下文中一共展示了EntityManager::getUnitOfWork方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: validate

 /**
  * Checks if the passed value is valid.
  *
  * @param mixed      $value      The value that should be validated
  * @param Constraint $constraint The constraint for the validation
  *
  * @api
  */
 public function validate($value, Constraint $constraint)
 {
     if (!$value instanceof Node) {
         $this->context->addViolation('Attempt to validate non Node entity');
         return;
     }
     $uow = $this->entityManager->getUnitOfWork();
     $originalData = $uow->getOriginalEntityData($value);
     // If we've been given a custom path, then don't use nonConflict in route path generation
     $hasCustomPath = strlen($value->getPath());
     $route = $this->routeBuilder->build($value, !$hasCustomPath);
     $routeName = $this->routeBuilder->buildRouteName($route->getPath());
     if (is_array($originalData) && count($originalData)) {
         if ($originalData['path'] !== $value->getPath()) {
             $existingRoute = $this->entityManager->getRepository('CmfRoutingBundle:Route')->findOneByName($routeName);
             if ($existingRoute instanceof Route) {
                 $this->context->buildViolation("A page at path '{$route->getPath()}' already exists")->atPath('path')->addViolation();
                 return;
             }
         } elseif ($value->getRoute() instanceof Route && $value->getRoute()->getName() !== $routeName) {
             $existingRoute = $this->entityManager->getRepository('CmfRoutingBundle:Route')->findOneByName($routeName);
             if ($existingRoute instanceof Route) {
                 $this->context->buildViolation("A page at path '{$route->getPath()}' already exists")->atPath('path')->addViolation();
                 return;
             }
         }
     }
 }
開發者ID:gravity-cms,項目名稱:cms-bundle,代碼行數:36,代碼來源:RoutableValidator.php

示例2: testORMCreate

 /**
  * @group orm
  */
 public function testORMCreate()
 {
     // unix dir
     $manager = new FileManager($this->ormStorage, $this->rootDir);
     $file = $manager->create('myDomain.en.yml', '/test/root/dir/src/Project/CoolBundle/Resources/translations');
     $this->assertEquals(ORMUnitOfWork::STATE_MANAGED, $this->em->getUnitOfWork()->getEntityState($file));
     $this->assertEquals('myDomain', $file->getDomain());
     $this->assertEquals('en', $file->getLocale());
     $this->assertEquals('yml', $file->getExtention());
     $this->assertEquals('myDomain.en.yml', $file->getName());
     $this->assertEquals('../src/Project/CoolBundle/Resources/translations', $file->getPath());
     $file = $manager->create('messages.fr.xliff', '/test/root/dir/app/Resources/translations', true);
     $this->assertEquals(ORMUnitOfWork::STATE_MANAGED, $this->em->getUnitOfWork()->getEntityState($file));
     $this->assertEquals('messages', $file->getDomain());
     $this->assertEquals('fr', $file->getLocale());
     $this->assertEquals('xliff', $file->getExtention());
     $this->assertEquals('messages.fr.xliff', $file->getName());
     $this->assertEquals('Resources/translations', $file->getPath());
     // window dir
     $manager = new FileManager($this->ormStorage, 'C:\\test\\root\\dir\\app');
     $file = $manager->create('myDomain.en.yml', 'C:\\test\\root\\dir\\src\\Project\\CoolBundle\\Resources\\translations');
     $this->assertEquals(ORMUnitOfWork::STATE_MANAGED, $this->em->getUnitOfWork()->getEntityState($file));
     $this->assertEquals('myDomain', $file->getDomain());
     $this->assertEquals('en', $file->getLocale());
     $this->assertEquals('yml', $file->getExtention());
     $this->assertEquals('myDomain.en.yml', $file->getName());
     $this->assertEquals('..\\src\\Project\\CoolBundle\\Resources\\translations', $file->getPath());
     $file = $manager->create('messages.fr.xliff', 'C:\\test\\root\\dir\\app\\Resources\\translations', true);
     $this->assertEquals(ORMUnitOfWork::STATE_MANAGED, $this->em->getUnitOfWork()->getEntityState($file));
     $this->assertEquals('messages', $file->getDomain());
     $this->assertEquals('fr', $file->getLocale());
     $this->assertEquals('xliff', $file->getExtention());
     $this->assertEquals('messages.fr.xliff', $file->getName());
     $this->assertEquals('Resources\\translations', $file->getPath());
 }
開發者ID:aitboudad,項目名稱:LexikTranslationBundle,代碼行數:38,代碼來源:FileManagerTest.php

示例3: load

 /**
  * {@inheritdoc}
  */
 public function load(ClassMetadata $meta, Component $component, $entity)
 {
     if (!$component instanceof BaseControl) {
         return FALSE;
     }
     if ($meta->hasField($name = $component->getOption(self::FIELD_NAME, $component->getName()))) {
         $component->setValue($this->accessor->getValue($entity, $name));
         return TRUE;
     }
     if (!$meta->hasAssociation($name)) {
         return FALSE;
     }
     /** @var SelectBox|RadioList $component */
     if (($component instanceof SelectBox || $component instanceof RadioList) && !count($component->getItems()) && !$component->getOption(self::FIELD_NOT_LOAD, false)) {
         if (!($nameKey = $component->getOption(self::ITEMS_TITLE, FALSE))) {
             $path = $component->lookupPath('Nette\\Application\\UI\\Form');
             throw new Kdyby\DoctrineForms\InvalidStateException('Either specify items for ' . $path . ' yourself, or set the option Kdyby\\DoctrineForms\\IComponentMapper::ITEMS_TITLE ' . 'to choose field that will be used as title');
         }
         $criteria = $component->getOption(self::ITEMS_FILTER, array());
         $orderBy = $component->getOption(self::ITEMS_ORDER, array());
         $related = $this->relatedMetadata($entity, $name);
         $items = $this->findPairs($related, $criteria, $orderBy, $nameKey);
         $component->setItems($items);
     }
     if ($relation = $this->accessor->getValue($entity, $name)) {
         $UoW = $this->em->getUnitOfWork();
         $component->setValue($UoW->getSingleIdentifierValue($relation));
     }
     return TRUE;
 }
開發者ID:kuba1999,項目名稱:DoctrineForms,代碼行數:33,代碼來源:TextControl.php

示例4: generate

 /**
  * Returns the identifier assigned to the given entity.
  *
  * @param object $entity
  * @return mixed
  * @override
  */
 public function generate(EntityManager $em, $entity)
 {
     $class = $em->getClassMetadata(get_class($entity));
     $identifier = array();
     if ($class->isIdentifierComposite) {
         $idFields = $class->getIdentifierFieldNames();
         foreach ($idFields as $idField) {
             $value = $class->getReflectionProperty($idField)->getValue($entity);
             if (isset($value)) {
                 if (is_object($value)) {
                     // NOTE: Single Columns as associated identifiers only allowed - this constraint it is enforced.
                     $identifier[$idField] = current($em->getUnitOfWork()->getEntityIdentifier($value));
                 } else {
                     $identifier[$idField] = $value;
                 }
             } else {
                 throw ORMException::entityMissingAssignedId($entity);
             }
         }
     } else {
         $idField = $class->identifier[0];
         $value = $class->reflFields[$idField]->getValue($entity);
         if (isset($value)) {
             if (is_object($value)) {
                 // NOTE: Single Columns as associated identifiers only allowed - this constraint it is enforced.
                 $identifier[$idField] = current($em->getUnitOfWork()->getEntityIdentifier($value));
             } else {
                 $identifier[$idField] = $value;
             }
         } else {
             throw ORMException::entityMissingAssignedId($entity);
         }
     }
     return $identifier;
 }
開發者ID:faridos,項目名稱:ServerGroveLiveChat,代碼行數:42,代碼來源:AssignedGenerator.php

示例5: init

 /**
  * @param OnFlushEventArgs $e
  */
 private function init(OnFlushEventArgs $e)
 {
     $this->em = $e->getEntityManager();
     $this->uow = $this->em->getUnitOfWork();
     $roundRepo = $this->em->getRepository('AppBundle:Round');
     /* @var $roundRepo \Bml\AppBundle\Entity\RoundRepository */
     $this->round = $roundRepo->findCurrent();
 }
開發者ID:RinWorld,項目名稱:Ponzi-1,代碼行數:11,代碼來源:RoundListener.php

示例6: onFlush

 /**
  * @param OnFlushEventArgs $event
  */
 public function onFlush(OnFlushEventArgs $event)
 {
     $this->em = $event->getEntityManager();
     $this->uow = $this->em->getUnitOfWork();
     foreach ($this->uow->getScheduledEntityInsertions() as $entity) {
         if ($entity instanceof Ticket) {
             $this->startAutoReply($entity);
         }
     }
 }
開發者ID:northdakota,項目名稱:diamantedesk-application,代碼行數:13,代碼來源:ArticleAutoReplyServiceImpl.php

示例7: onFlush

 /**
  * On flush
  *
  * @param OnFlushEventArgs $args
  */
 public function onFlush(OnFlushEventArgs $args)
 {
     $this->manager = $args->getEntityManager();
     $this->uow = $this->manager->getUnitOfWork();
     foreach ($this->uow->getScheduledEntityUpdates() as $entity) {
         $this->preUpdate($entity);
     }
     foreach ($this->uow->getScheduledEntityDeletions() as $entity) {
         $this->preRemove($entity);
     }
 }
開發者ID:ashutosh-srijan,項目名稱:findit_akeneo,代碼行數:16,代碼來源:UserPreferencesSubscriber.php

示例8: pack

 /**
  * {@inheritdoc}
  */
 public function pack($object)
 {
     $uow = $this->em->getUnitOfWork();
     if (!$uow->isInIdentityMap($object)) {
         return null;
     }
     $identity = $uow->getEntityIdentifier($object);
     if (count($identity) == 0) {
         return null;
     }
     return new ObjectSignature($this->getClass($object), $identity);
 }
開發者ID:brick,項目名稱:brick,代碼行數:15,代碼來源:DoctrineObjectPacker.php

示例9: preUpdate

 public function preUpdate(LifecycleEventArgs $lifecycleEventArgs)
 {
     $entity = $lifecycleEventArgs->getEntity();
     $this->entityManager = $lifecycleEventArgs->getEntityManager();
     if (!$entity instanceof UrlInterface) {
         return;
     }
     $changeSet = $this->entityManager->getUnitOfWork()->getEntityChangeSet($entity);
     if (isset($changeSet['url'])) {
         $url = $this->findFreeUrl($entity, String::toUrl($entity->getUrl()));
         $entity->setUrl($url);
     }
 }
開發者ID:w3build,項目名稱:entity-listeners-bundle,代碼行數:13,代碼來源:UrlListener.php

示例10: save

 /**
  * Savely persist Doctrine 2 Entity information
  *
  * @param ezcWorkflowExecution $execution
  * @param string $variableName
  * @param  $value
  */
 public function save(ezcWorkflowExecution $execution, $variableName, $value)
 {
     if (!is_object($value)) {
         return null;
     }
     if (!$this->em->contains($value)) {
         throw new \ezcWorkflowExecutionException("Entity '" . get_class($value) . "' at variable " . $variableName . " has to be managed by the EntityManager.");
     }
     $entityData = array(get_class($value), $this->em->getUnitOfWork()->getEntityIdentifier($value));
     $entityDetailsVariable = $variableName . "_dc2entity";
     $execution->setVariable($entityDetailsVariable, $entityData);
     $execution->setVariable($variableName, null);
 }
開發者ID:beberlei,項目名稱:Doctrine-Workflow,代碼行數:20,代碼來源:EntityManagerHandler.php

示例11: testUpdateUsesTypeValuesSQL

 public function testUpdateUsesTypeValuesSQL()
 {
     $child = new CustomTypeChild();
     $parent = new CustomTypeParent();
     $parent->customInteger = 1;
     $parent->child = $child;
     $this->_em->getUnitOfWork()->registerManaged($parent, array('id' => 1), array('customInteger' => 0, 'child' => null));
     $this->_em->getUnitOfWork()->registerManaged($child, array('id' => 1), array());
     $this->_em->getUnitOfWork()->propertyChanged($parent, 'customInteger', 0, 1);
     $this->_em->getUnitOfWork()->propertyChanged($parent, 'child', null, $child);
     $this->_persister->update($parent);
     $executeUpdates = $this->_em->getConnection()->getExecuteUpdates();
     $this->assertEquals('UPDATE customtype_parents SET customInteger = ABS(?), child_id = ? WHERE id = ?', $executeUpdates[0]['query']);
 }
開發者ID:selimcr,項目名稱:servigases,代碼行數:14,代碼來源:BasicEntityPersisterTypeValueSqlTest.php

示例12: validate

 /**
  * Validate the property
  *
  * @param Locale     $entity
  * @param Constraint $constraint
  */
 public function validate($entity, Constraint $constraint)
 {
     $originalData = $this->em->getUnitOfWork()->getOriginalEntityData($entity);
     $accessor = PropertyAccess::createPropertyAccessor();
     foreach ($constraint->properties as $property) {
         $originalValue = $accessor->getValue($originalData, sprintf('[%s]', $property));
         if (null !== $originalValue) {
             $newValue = $accessor->getValue($entity, $property);
             if ($originalValue !== $newValue) {
                 $this->context->addViolationAt($property, $constraint->message);
             }
         }
     }
 }
開發者ID:javiersantos,項目名稱:pim-community-dev,代碼行數:20,代碼來源:ImmutableValidator.php

示例13: onSiteStateException

 public function onSiteStateException(SiteStateExceptionEvent $event)
 {
     $state = $event->getSite()->getSiteState();
     $exception = $event->getException();
     if ($exception instanceof ProtocolException) {
         $state->markLastFailedContactAt(new \DateTime(), $exception->getLevel(), $exception->getType(), $exception->getCode(), $exception->getContext());
     } else {
         return;
     }
     if ($this->em->getUnitOfWork()->isInIdentityMap($state) && !$this->em->getUnitOfWork()->isScheduledForInsert($state)) {
         $this->em->persist($state);
         $this->em->flush();
     }
 }
開發者ID:Briareos,項目名稱:Undine,代碼行數:14,代碼來源:SiteStateResultListener.php

示例14: makeSnapshot

 /**
  * @param $entity
  * @param \Doctrine\ORM\EntityManager $em
  */
 private function makeSnapshot($entity, \Doctrine\ORM\EntityManager $em)
 {
     $resourceVersion = new ResourceVersion($entity);
     $class = $em->getClassMetadata(get_class($resourceVersion));
     $em->persist($resourceVersion);
     $em->getUnitOfWork()->computeChangeSet($class, $resourceVersion);
 }
開發者ID:rapemer,項目名稱:init-cms-bundle,代碼行數:11,代碼來源:VersionListener.php

示例15: isRuleChanged

 /**
  * @param BadgeRule[]|\Doctrine\Common\Collections\ArrayCollection $newRules
  * @param BadgeRule[]|\Doctrine\Common\Collections\ArrayCollection $originalRules
  *
  * @return bool
  */
 public function isRuleChanged($newRules, $originalRules)
 {
     $isRulesChanged = false;
     $unitOfWork = $this->entityManager->getUnitOfWork();
     $unitOfWork->computeChangeSets();
     foreach ($newRules as $newRule) {
         // Check if there are new rules
         if (null === $newRule->getId()) {
             $isRulesChanged = true;
         } else {
             // Check if existed rules have been changed
             $changeSet = $unitOfWork->getEntityChangeSet($newRule);
             if (0 < count($changeSet)) {
                 $isRulesChanged = true;
             }
             // Remove rule from original if they were not deleted
             if ($originalRules->contains($newRule)) {
                 $originalRules->removeElement($newRule);
             }
         }
     }
     // Check if they are deleted rules (those who are not in the new but in the originals)
     if (0 < count($originalRules)) {
         $isRulesChanged = true;
     }
     return $isRulesChanged;
 }
開發者ID:claroline,項目名稱:distribution,代碼行數:33,代碼來源:BadgeManager.php


注:本文中的Doctrine\ORM\EntityManager::getUnitOfWork方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。