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


PHP ObjectManager::getUnitOfWork方法代码示例

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


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

示例1: persistEntities

 /**
  * Persists all entities managed by the repository and all cascading dependencies
  *
  * @return void
  */
 public function persistEntities()
 {
     foreach ($this->entityManager->getUnitOfWork()->getIdentityMap() as $className => $entities) {
         if ($className === $this->entityClassName) {
             foreach ($entities as $entityToPersist) {
                 $this->entityManager->flush($entityToPersist);
             }
             return;
         }
     }
 }
开发者ID:nlx-sascha,项目名称:flow-development-collection,代码行数:16,代码来源:ObjectPathMappingRepository.php

示例2: onChangeDecision

 /**
  * {@inheritDoc}
  */
 public function onChangeDecision(SluggableAdapter $ea, array &$config, $object, &$slug, &$needToChangeSlug)
 {
     $this->om = $ea->getObjectManager();
     $isInsert = $this->om->getUnitOfWork()->isScheduledForInsert($object);
     $this->usedOptions = $config['handlers'][get_called_class()];
     if (!isset($this->usedOptions['separator'])) {
         $this->usedOptions['separator'] = self::SEPARATOR;
     }
     if (!$isInsert && !$needToChangeSlug) {
         $changeSet = $ea->getObjectChangeSet($this->om->getUnitOfWork(), $object);
         if (isset($changeSet[$this->usedOptions['relationField']])) {
             $needToChangeSlug = true;
         }
     }
 }
开发者ID:esserj,项目名称:DoctrineExtensions,代码行数:18,代码来源:RelativeSlugHandler.php

示例3: onSlugCompletion

 /**
  * {@inheritDoc}
  */
 public function onSlugCompletion(SluggableAdapter $ea, array &$config, $object, &$slug)
 {
     if (!$this->isInsert) {
         $options = $this->getOptions($object);
         $wrapped = AbstractWrapper::wrapp($object, $this->om);
         $meta = $wrapped->getMetadata();
         $extConfig = $this->sluggable->getConfiguration($this->om, $meta->name);
         $config['useObjectClass'] = $extConfig['useObjectClass'];
         $target = $wrapped->getPropertyValue($config['slug']);
         $config['pathSeparator'] = $options['separator'];
         $ea->replaceRelative($object, $config, $target.$options['separator'], $slug);
         $uow = $this->om->getUnitOfWork();
         // update in memory objects
         foreach ($uow->getIdentityMap() as $className => $objects) {
             // for inheritance mapped classes, only root is always in the identity map
             if ($className !== $wrapped->getRootObjectName()) {
                 continue;
             }
             foreach ($objects as $object) {
                 if (property_exists($object, '__isInitialized__') && !$object->__isInitialized__) {
                     continue;
                 }
                 $oid = spl_object_hash($object);
                 $objectSlug = $meta->getReflectionProperty($config['slug'])->getValue($object);
                 if (preg_match("@^{$target}{$options['separator']}@smi", $objectSlug)) {
                     $objectSlug = str_replace($target, $slug, $objectSlug);
                     $meta->getReflectionProperty($config['slug'])->setValue($object, $objectSlug);
                     $ea->setOriginalObjectProperty($uow, $oid, $config['slug'], $objectSlug);
                 }
             }
         }
     }
 }
开发者ID:projectesIF,项目名称:Sirius,代码行数:36,代码来源:TreeSlugHandler.php

示例4: setTerm

 /**
  * @param $term
  * @throws \InvalidArgumentException
  * @return $this
  */
 public function setTerm($term = null)
 {
     $this->initialize();
     if (null === $term) {
         $this->entityTerm = null;
         return $this;
     }
     if (!$term instanceof Term) {
         throw new \InvalidArgumentException(sprintf('Expected instance of Term. "%s" given.', get_class($term)));
     }
     if ($this->em->getUnitOfWork()->getEntityState($term) == UnitOfWork::STATE_DETACHED) {
         $term = $this->em->merge($term);
     }
     if ($term->getVocabulary() !== $this->vocabulary) {
         throw new \InvalidArgumentException(sprintf('Term "%s" (#%d) does not belong in "%s" vocabulary.', $term->getName(), $term->getId(), $this->vocabulary->getName()));
     }
     if ($this->entityTerm && $this->entityTerm->getTerm() === $term) {
         return $this;
     }
     $className = $this->entityTerms->getClassName();
     $this->setDirty(true);
     $eTerm = new $className();
     /** @var $eTerm EntityTermInterface */
     $eTerm->setTerm($term);
     $this->entityTerm = $eTerm;
     return $this;
 }
开发者ID:activelamp,项目名称:taxonomy,代码行数:32,代码来源:SingularVocabularyField.php

示例5: hasUnpersistedChanges

 /**
  * Gives feedback if the persistence Manager has unpersisted changes.
  *
  * This is primarily used to inform the user if he tries to save
  * data in an unsafe request.
  *
  * @return boolean
  */
 public function hasUnpersistedChanges()
 {
     $unitOfWork = $this->entityManager->getUnitOfWork();
     if ($unitOfWork->getScheduledEntityInsertions() !== array() || $unitOfWork->getScheduledEntityUpdates() !== array() || $unitOfWork->getScheduledEntityDeletions() !== array() || $unitOfWork->getScheduledCollectionDeletions() !== array() || $unitOfWork->getScheduledCollectionUpdates() !== array()) {
         return TRUE;
     }
     return FALSE;
 }
开发者ID:animaltool,项目名称:webinterface,代码行数:16,代码来源:PersistenceManager.php

示例6: hasUnpersistedChanges

 /**
  * Gives feedback if the persistence Manager has unpersisted changes.
  *
  * This is primarily used to inform the user if he tries to save
  * data in an unsafe request.
  *
  * @return boolean
  */
 public function hasUnpersistedChanges()
 {
     $unitOfWork = $this->entityManager->getUnitOfWork();
     $unitOfWork->computeChangeSets();
     if ($unitOfWork->getScheduledEntityInsertions() !== [] || $unitOfWork->getScheduledEntityUpdates() !== [] || $unitOfWork->getScheduledEntityDeletions() !== [] || $unitOfWork->getScheduledCollectionDeletions() !== [] || $unitOfWork->getScheduledCollectionUpdates() !== []) {
         return true;
     }
     return false;
 }
开发者ID:neos,项目名称:flow-development-collection,代码行数:17,代码来源:PersistenceManager.php

示例7: onSlugCompletion

 /**
  * {@inheritDoc}
  */
 public function onSlugCompletion(SluggableAdapter $ea, array &$config, $object, &$slug)
 {
     $this->om = $ea->getObjectManager();
     $isInsert = $this->om->getUnitOfWork()->isScheduledForInsert($object);
     if (!$isInsert) {
         $options = $config['handlers'][get_called_class()];
         $wrapped = AbstractWrapper::wrapp($object, $this->om);
         $oldSlug = $wrapped->getPropertyValue($config['slug']);
         $mappedByConfig = $this->sluggable->getConfiguration($this->om, $options['relationClass']);
         if ($mappedByConfig) {
             $meta = $this->om->getClassMetadata($options['relationClass']);
             if (!$meta->isSingleValuedAssociation($options['mappedBy'])) {
                 throw new InvalidMappingException("Unable to find " . $wrapped->getMetadata()->name . " relation - [{$options['mappedBy']}] in class - {$meta->name}");
             }
             if (!isset($mappedByConfig['slugs'][$options['inverseSlugField']])) {
                 throw new InvalidMappingException("Unable to find slug field - [{$options['inverseSlugField']}] in class - {$meta->name}");
             }
             $mappedByConfig['slug'] = $mappedByConfig['slugs'][$options['inverseSlugField']]['slug'];
             $mappedByConfig['mappedBy'] = $options['mappedBy'];
             $ea->replaceInverseRelative($object, $mappedByConfig, $slug, $oldSlug);
             $uow = $this->om->getUnitOfWork();
             // update in memory objects
             foreach ($uow->getIdentityMap() as $className => $objects) {
                 // for inheritance mapped classes, only root is always in the identity map
                 if ($className !== $mappedByConfig['useObjectClass']) {
                     continue;
                 }
                 foreach ($objects as $object) {
                     if (property_exists($object, '__isInitialized__') && !$object->__isInitialized__) {
                         continue;
                     }
                     $oid = spl_object_hash($object);
                     $objectSlug = $meta->getReflectionProperty($mappedByConfig['slug'])->getValue($object);
                     if (preg_match("@^{$oldSlug}@smi", $objectSlug)) {
                         $objectSlug = str_replace($oldSlug, $slug, $objectSlug);
                         $meta->getReflectionProperty($mappedByConfig['slug'])->setValue($object, $objectSlug);
                         $ea->setOriginalObjectProperty($uow, $oid, $mappedByConfig['slug'], $objectSlug);
                     }
                 }
             }
         }
     }
 }
开发者ID:robertowest,项目名称:CuteFlow-V4,代码行数:46,代码来源:InversedRelativeSlugHandler.php

示例8: hasIdentifier

 /**
  * Checks if object has identifier already in unit of work.
  *
  * @param $reference
  *
  * @return bool
  */
 private function hasIdentifier($reference)
 {
     // in case if reference is set after flush, store its identity
     $uow = $this->manager->getUnitOfWork();
     if ($this->manager instanceof PhpcrDocumentManager) {
         return $uow->contains($reference);
     } else {
         return $uow->isInIdentityMap($reference);
     }
 }
开发者ID:zhangyuxiao,项目名称:qoros,代码行数:17,代码来源:ReferenceRepository.php

示例9: changed

 /**
  * Schedule update of the owner in the unit of work
  */
 private function changed()
 {
     if (null === $this->manager) {
         $this->manager = $this->registry->getManagerForClass(ClassUtils::getClass($this->owner));
     }
     $uow = $this->manager->getUnitOfWork();
     if (UnitOfWork::STATE_MANAGED === $uow->getDocumentState($this->owner) && !$uow->isScheduledForUpdate($this->owner)) {
         $uow->scheduleForUpdate($this->owner);
     }
 }
开发者ID:alexisfroger,项目名称:pim-community-dev,代码行数:13,代码来源:ReferencedCollection.php

示例10: sendEvent

 /**
  * send created event.
  *
  * @param $version
  */
 public function sendEvent($version)
 {
     $entityInsertions = $this->manager->getUnitOfWork()->getScheduledEntityInsertions();
     foreach ($entityInsertions as $entityInsertion) {
         $this->dispatchEvent($entityInsertion, Events::PRE_CREATE, $version);
     }
     $this->manager->getUnitOfWork()->computeChangeSets();
     $entityUpdateds = $this->manager->getUnitOfWork()->getScheduledEntityUpdates();
     foreach ($entityUpdateds as $entityUpdated) {
         $this->dispatchEvent($entityUpdated, Events::PRE_UPDATE, $version);
     }
 }
开发者ID:eliberty,项目名称:api-bundle,代码行数:17,代码来源:BaseHandler.php

示例11: onChangeDecision

 /**
  * {@inheritDoc}
  */
 public function onChangeDecision(SluggableAdapter $ea, $slugFieldConfig, $object, &$slug, &$needToChangeSlug)
 {
     $this->om = $ea->getObjectManager();
     $isInsert = $this->om->getUnitOfWork()->isScheduledForInsert($object);
     if (!$isInsert && !$needToChangeSlug) {
         $changeSet = $ea->getObjectChangeSet($this->om->getUnitOfWork(), $object);
         $options = $this->getOptions($object);
         if (isset($changeSet[$options['relationField']])) {
             $needToChangeSlug = true;
         }
     }
 }
开发者ID:projectesIF,项目名称:Sirius,代码行数:15,代码来源:RelativeSlugHandler.php

示例12: checkType

 /**
  * @param $element
  * @throws \InvalidArgumentException
  */
 protected function checkType($element)
 {
     if (!$element instanceof Term) {
         throw new \InvalidArgumentException(sprintf('Expected instance of %s. "%s" given.', __NAMESPACE__ . '\\Term', get_class($element)));
     }
     if ($this->em->getUnitOfWork()->getEntityState($element) == UnitOfWork::STATE_DETACHED) {
         $element = $this->em->merge($element);
     }
     if ($element->getVocabulary() !== $this->vocabulary) {
         throw new \InvalidArgumentException(sprintf('Term "%s" (#%d) does not belong in the "%s" vocabulary.', $element->getName(), $element->getId(), $this->vocabulary->getName()));
     }
 }
开发者ID:activelamp,项目名称:taxonomy,代码行数:16,代码来源:PluralVocabularyField.php

示例13: getReference

 /**
  * Loads an object using stored reference
  * named by $name
  *
  * @param string $name
  * @return object
  */
 public function getReference($name)
 {
     $reference = $this->references[$name];
     $meta = $this->manager->getClassMetadata(get_class($reference));
     $uow = $this->manager->getUnitOfWork();
     if (!$uow->isInIdentityMap($reference) && isset($this->identities[$name])) {
         $reference = $this->manager->getReference($meta->name, $this->identities[$name]);
         $this->references[$name] = $reference;
         // allready in identity map
     }
     return $reference;
 }
开发者ID:glaucosydow,项目名称:curso-zf2,代码行数:19,代码来源:ReferenceRepository.php

示例14: saveEntity

 /**
  * Save an entity
  *
  * @param object $node
  * @param boolean $andFlush
  */
 protected function saveEntity($entity, $andFlush = true)
 {
     if ($this->objectManager->getUnitOfWork()->getEntityState($entity) == \Doctrine\ORM\UnitOfWork::STATE_NEW) {
         return $this->createEntity($entity, $andFlush);
     } else {
         $em = $this->objectManager;
         $em->persist($entity);
         if ($andFlush) {
             $em->flush();
         }
     }
 }
开发者ID:geoffreytran,项目名称:zym,代码行数:18,代码来源:AbstractEntityManager.php

示例15: persistEntities

 /**
  * Persists all entities managed by the repository and all cascading dependencies
  *
  * @return void
  */
 public function persistEntities()
 {
     foreach ($this->entityManager->getUnitOfWork()->getIdentityMap() as $className => $entities) {
         if ($className === $this->entityClassName) {
             foreach ($entities as $entityToPersist) {
                 $this->entityManager->flush($entityToPersist);
             }
             $this->emitRepositoryObjectsPersisted();
             break;
         }
     }
 }
开发者ID:testbird,项目名称:neos-development-collection,代码行数:17,代码来源:NodeDataRepository.php


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