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


PHP PersistentCollection::setInitialized方法代码示例

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


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

示例1: testCanBePutInLazyLoadingMode

 public function testCanBePutInLazyLoadingMode()
 {
     $class = $this->_emMock->getClassMetadata('Doctrine\\Tests\\Models\\ECommerce\\ECommerceProduct');
     $collection = new PersistentCollection($this->_emMock, $class, new ArrayCollection());
     $collection->setInitialized(false);
     $this->assertFalse($collection->isInitialized());
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:7,代码来源:PersistentCollectionTest.php

示例2: testQueriesAssociationToLoadItself

 public function testQueriesAssociationToLoadItself()
 {
     $class = $this->_emMock->getClassMetadata('Doctrine\\Tests\\Models\\ECommerce\\ECommerceProduct');
     $collection = new PersistentCollection($this->_emMock, $class, new ArrayCollection());
     $collection->setInitialized(false);
     $association = $this->getMock('Doctrine\\ORM\\Mapping\\OneToManyMapping', array('load'), array(), '', false, false, false);
     $association->targetEntityName = 'Doctrine\\Tests\\Models\\ECommerce\\ECommerceFeature';
     $product = new ECommerceProduct();
     $association->expects($this->once())->method('load')->with($product, $this->isInstanceOf($collection), $this->isInstanceOf($this->_emMock));
     $collection->setOwner($product, $association);
     count($collection);
 }
开发者ID:jacques-sounvi,项目名称:addressbook,代码行数:12,代码来源:PersistentCollectionTest.php

示例3: setProductPersistentCollection

 /**
  * Prepare a lazy loadable PersistentCollection
  * on the entity to get Products.
  * The entity must have a "products" property defined
  *
  * @param object        $entity        The entity related to the products
  * @param array         $assoc         Association properties
  * @param EntityManager $entityManager Entity manager
  */
 protected function setProductPersistentCollection($entity, $assoc, EntityManager $entityManager)
 {
     $targetEntity = $this->productClass;
     $productsCollection = new PersistentCollection($entityManager, $targetEntity, new ArrayCollection());
     $assoc['fieldName'] = 'products';
     $assoc['targetEntity'] = $targetEntity;
     $assoc['type'] = ClassMetadata::MANY_TO_MANY;
     $assoc['inversedBy'] = '';
     $assoc['isOwningSide'] = false;
     $assoc['sourceEntity'] = get_class($entity);
     $assoc['orphanRemoval'] = false;
     $productsCollection->setOwner($entity, $assoc);
     $productsCollection->setInitialized(false);
     $entityMetadata = $entityManager->getClassMetadata(get_class($entity));
     $productsReflProp = $entityMetadata->reflClass->getProperty('products');
     $productsReflProp->setAccessible(true);
     $productsReflProp->setValue($entity, $productsCollection);
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:27,代码来源:InjectProductReferenceSubscriber.php

示例4: get

 /**
  * {@inheritdoc}
  */
 public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = array())
 {
     if (!($key->cacheMode & Cache::MODE_GET)) {
         return null;
     }
     $entry = $this->region->get($key);
     if (!$entry instanceof QueryCacheEntry) {
         return null;
     }
     if (!$this->validator->isValid($key, $entry)) {
         $this->region->evict($key);
         return null;
     }
     $result = array();
     $entityName = reset($rsm->aliasMap);
     $hasRelation = !empty($rsm->relationMap);
     $persister = $this->uow->getEntityPersister($entityName);
     $region = $persister->getCacheRegion();
     $regionName = $region->getName();
     // @TODO - move to cache hydration component
     foreach ($entry->result as $index => $entry) {
         if (($entityEntry = $region->get($entityKey = new EntityCacheKey($entityName, $entry['identifier']))) === null) {
             if ($this->cacheLogger !== null) {
                 $this->cacheLogger->entityCacheMiss($regionName, $entityKey);
             }
             return null;
         }
         if ($this->cacheLogger !== null) {
             $this->cacheLogger->entityCacheHit($regionName, $entityKey);
         }
         if (!$hasRelation) {
             $result[$index] = $this->uow->createEntity($entityEntry->class, $entityEntry->resolveAssociationEntries($this->em), self::$hints);
             continue;
         }
         $data = $entityEntry->data;
         foreach ($entry['associations'] as $name => $assoc) {
             $assocPersister = $this->uow->getEntityPersister($assoc['targetEntity']);
             $assocRegion = $assocPersister->getCacheRegion();
             if ($assoc['type'] & ClassMetadata::TO_ONE) {
                 if (($assocEntry = $assocRegion->get($assocKey = new EntityCacheKey($assoc['targetEntity'], $assoc['identifier']))) === null) {
                     if ($this->cacheLogger !== null) {
                         $this->cacheLogger->entityCacheMiss($assocRegion->getName(), $assocKey);
                     }
                     $this->uow->hydrationComplete();
                     return null;
                 }
                 $data[$name] = $this->uow->createEntity($assocEntry->class, $assocEntry->resolveAssociationEntries($this->em), self::$hints);
                 if ($this->cacheLogger !== null) {
                     $this->cacheLogger->entityCacheHit($assocRegion->getName(), $assocKey);
                 }
                 continue;
             }
             if (!isset($assoc['list']) || empty($assoc['list'])) {
                 continue;
             }
             $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
             $collection = new PersistentCollection($this->em, $targetClass, new ArrayCollection());
             foreach ($assoc['list'] as $assocIndex => $assocId) {
                 if (($assocEntry = $assocRegion->get($assocKey = new EntityCacheKey($assoc['targetEntity'], $assocId))) === null) {
                     if ($this->cacheLogger !== null) {
                         $this->cacheLogger->entityCacheMiss($assocRegion->getName(), $assocKey);
                     }
                     $this->uow->hydrationComplete();
                     return null;
                 }
                 $element = $this->uow->createEntity($assocEntry->class, $assocEntry->resolveAssociationEntries($this->em), self::$hints);
                 $collection->hydrateSet($assocIndex, $element);
                 if ($this->cacheLogger !== null) {
                     $this->cacheLogger->entityCacheHit($assocRegion->getName(), $assocKey);
                 }
             }
             $data[$name] = $collection;
             $collection->setInitialized(true);
         }
         $result[$index] = $this->uow->createEntity($entityEntry->class, $data, self::$hints);
     }
     $this->uow->hydrationComplete();
     return $result;
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:82,代码来源:DefaultQueryCache.php

示例5: createEntity

 /**
  * INTERNAL:
  * Creates an entity. Used for reconstitution of persistent entities.
  *
  * @ignore
  *
  * @param string $className The name of the entity class.
  * @param array  $data      The data for the entity.
  * @param array  $hints     Any hints to account for during reconstitution/lookup of the entity.
  *
  * @return object The managed entity instance.
  *
  * @internal Highly performance-sensitive method.
  *
  * @todo Rename: getOrCreateEntity
  */
 public function createEntity($className, array $data, &$hints = array())
 {
     $class = $this->em->getClassMetadata($className);
     //$isReadOnly = isset($hints[Query::HINT_READ_ONLY]);
     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 {
         $id = isset($class->associationMappings[$class->identifier[0]]) ? $data[$class->associationMappings[$class->identifier[0]]['joinColumns'][0]['name']] : $data[$class->identifier[0]];
         $id = array($class->identifier[0] => $id);
     }
     $idHash = implode(' ', $id);
     if (isset($this->identityMap[$class->rootEntityName][$idHash])) {
         $entity = $this->identityMap[$class->rootEntityName][$idHash];
         $oid = spl_object_hash($entity);
         if (isset($hints[Query::HINT_REFRESH]) && isset($hints[Query::HINT_REFRESH_ENTITY]) && ($unmanagedProxy = $hints[Query::HINT_REFRESH_ENTITY]) !== $entity && $unmanagedProxy instanceof Proxy && $this->isIdentifierEquals($unmanagedProxy, $entity)) {
             // DDC-1238 - we have a managed instance, but it isn't the provided one.
             // Therefore we clear its identifier. Also, we must re-fetch metadata since the
             // refreshed object may be anything
             foreach ($class->identifier as $fieldName) {
                 $class->reflFields[$fieldName]->setValue($unmanagedProxy, null);
             }
             return $unmanagedProxy;
         }
         if ($entity instanceof Proxy && !$entity->__isInitialized()) {
             $entity->__setInitialized(true);
             $overrideLocalValues = true;
             if ($entity instanceof NotifyPropertyChanged) {
                 $entity->addPropertyChangedListener($this);
             }
         } else {
             $overrideLocalValues = isset($hints[Query::HINT_REFRESH]);
             // If only a specific entity is set to refresh, check that it's the one
             if (isset($hints[Query::HINT_REFRESH_ENTITY])) {
                 $overrideLocalValues = $hints[Query::HINT_REFRESH_ENTITY] === $entity;
             }
         }
         if ($overrideLocalValues) {
             // inject ObjectManager upon refresh.
             if ($entity instanceof ObjectManagerAware) {
                 $entity->injectObjectManager($this->em, $class);
             }
             $this->originalEntityData[$oid] = $data;
         }
     } else {
         $entity = $this->newInstance($class);
         $oid = spl_object_hash($entity);
         $this->entityIdentifiers[$oid] = $id;
         $this->entityStates[$oid] = self::STATE_MANAGED;
         $this->originalEntityData[$oid] = $data;
         $this->identityMap[$class->rootEntityName][$idHash] = $entity;
         if ($entity instanceof NotifyPropertyChanged) {
             $entity->addPropertyChangedListener($this);
         }
         $overrideLocalValues = true;
     }
     if (!$overrideLocalValues) {
         return $entity;
     }
     foreach ($data as $field => $value) {
         if (isset($class->fieldMappings[$field])) {
             $class->reflFields[$field]->setValue($entity, $value);
         }
     }
     // Loading the entity right here, if its in the eager loading map get rid of it there.
     unset($this->eagerLoadingEntities[$class->rootEntityName][$idHash]);
     if (isset($this->eagerLoadingEntities[$class->rootEntityName]) && !$this->eagerLoadingEntities[$class->rootEntityName]) {
         unset($this->eagerLoadingEntities[$class->rootEntityName]);
     }
     // Properly initialize any unfetched associations, if partial objects are not allowed.
     if (isset($hints[Query::HINT_FORCE_PARTIAL_LOAD])) {
         return $entity;
     }
     foreach ($class->associationMappings as $field => $assoc) {
         // Check if the association is not among the fetch-joined associations already.
         if (isset($hints['fetchAlias']) && isset($hints['fetched'][$hints['fetchAlias']][$field])) {
             continue;
         }
         $targetClass = $this->em->getClassMetadata($assoc['targetEntity']);
         switch (true) {
             case $assoc['type'] & ClassMetadata::TO_ONE:
                 if (!$assoc['isOwningSide']) {
//.........这里部分代码省略.........
开发者ID:josercl,项目名称:forum,代码行数:101,代码来源:UnitOfWork.php

示例6: _doMerge

 /**
  * Executes a merge operation on an entity.
  *
  * @param object $entity
  * @param array $visited
  * @return object The managed copy of the entity.
  * @throws OptimisticLockException If the entity uses optimistic locking through a version
  *         attribute and the version check against the managed copy fails.
  * @throws InvalidArgumentException If the entity instance is NEW.
  */
 private function _doMerge($entity, array &$visited, $prevManagedCopy = null, $assoc = null)
 {
     $class = $this->_em->getClassMetadata(get_class($entity));
     $id = $class->getIdentifierValues($entity);
     if (!$id) {
         throw new \InvalidArgumentException('New entity detected during merge.' . ' Persist the new entity before merging.');
     }
     // MANAGED entities are ignored by the merge operation
     if ($this->getEntityState($entity, self::STATE_DETACHED) == self::STATE_MANAGED) {
         $managedCopy = $entity;
     } else {
         // Try to look the entity up in the identity map.
         $managedCopy = $this->tryGetById($id, $class->rootEntityName);
         if ($managedCopy) {
             // We have the entity in-memory already, just make sure its not removed.
             if ($this->getEntityState($managedCopy) == self::STATE_REMOVED) {
                 throw new \InvalidArgumentException('Removed entity detected during merge.' . ' Can not merge with a removed entity.');
             }
         } else {
             // We need to fetch the managed copy in order to merge.
             $managedCopy = $this->_em->find($class->name, $id);
         }
         if ($managedCopy === null) {
             throw new \InvalidArgumentException('New entity detected during merge.' . ' Persist the new entity before merging.');
         }
         if ($class->isVersioned) {
             $managedCopyVersion = $class->reflFields[$class->versionField]->getValue($managedCopy);
             $entityVersion = $class->reflFields[$class->versionField]->getValue($entity);
             // Throw exception if versions dont match.
             if ($managedCopyVersion != $entityVersion) {
                 throw OptimisticLockException::lockFailed();
             }
         }
         // Merge state of $entity into existing (managed) entity
         foreach ($class->reflFields as $name => $prop) {
             if (!isset($class->associationMappings[$name])) {
                 $prop->setValue($managedCopy, $prop->getValue($entity));
             } else {
                 $assoc2 = $class->associationMappings[$name];
                 if ($assoc2->isOneToOne()) {
                     if (!$assoc2->isCascadeMerge) {
                         $other = $class->reflFields[$name]->getValue($entity);
                         //TODO: Just $prop->getValue($entity)?
                         if ($other !== null) {
                             $targetClass = $this->_em->getClassMetadata($assoc2->targetEntityName);
                             $id = $targetClass->getIdentifierValues($other);
                             $proxy = $this->_em->getProxyFactory()->getProxy($assoc2->targetEntityName, $id);
                             $prop->setValue($managedCopy, $proxy);
                             $this->registerManaged($proxy, $id, array());
                         }
                     }
                 } else {
                     $coll = new PersistentCollection($this->_em, $this->_em->getClassMetadata($assoc2->targetEntityName), new ArrayCollection());
                     $coll->setOwner($managedCopy, $assoc2);
                     $coll->setInitialized($assoc2->isCascadeMerge);
                     $prop->setValue($managedCopy, $coll);
                 }
             }
             if ($class->isChangeTrackingNotify()) {
                 //TODO: put changed fields in changeset...?
             }
         }
         if ($class->isChangeTrackingDeferredExplicit()) {
             //TODO: Mark $managedCopy for dirty check...? ($this->_scheduledForDirtyCheck)
         }
     }
     if ($prevManagedCopy !== null) {
         $assocField = $assoc->sourceFieldName;
         $prevClass = $this->_em->getClassMetadata(get_class($prevManagedCopy));
         if ($assoc->isOneToOne()) {
             $prevClass->reflFields[$assocField]->setValue($prevManagedCopy, $managedCopy);
             //TODO: What about back-reference if bidirectional?
         } else {
             $prevClass->reflFields[$assocField]->getValue($prevManagedCopy)->unwrap()->add($managedCopy);
             if ($assoc->isOneToMany()) {
                 $class->reflFields[$assoc->mappedBy]->setValue($managedCopy, $prevManagedCopy);
             }
         }
     }
     $this->_cascadeMerge($entity, $managedCopy, $visited);
     return $managedCopy;
 }
开发者ID:sentact,项目名称:vendor-doctrine2,代码行数:92,代码来源:UnitOfWork.php


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