当前位置: 首页>>代码示例>>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;未经允许,请勿转载。