• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP ORM\PersistentCollection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getValidUserApi

 /**
  * Get valid UserApi for given token
  *
  * @param TokenInterface       $token
  * @param PersistentCollection $secrets
  * @param User                 $user
  *
  * @return bool|UserApi
  */
 protected function getValidUserApi(TokenInterface $token, PersistentCollection $secrets, User $user)
 {
     $currentIteration = 0;
     $nonce = $token->getAttribute('nonce');
     $secretsCount = $secrets->count();
     /** @var UserApi $userApi */
     foreach ($secrets as $userApi) {
         $currentIteration++;
         $isSecretValid = $this->validateDigest($token->getAttribute('digest'), $nonce, $token->getAttribute('created'), $userApi->getApiKey(), $this->getSalt($user));
         if ($isSecretValid && !$userApi->getUser()->getOrganizations()->contains($userApi->getOrganization())) {
             throw new BadCredentialsException('Wrong API key.');
         }
         if ($isSecretValid && !$userApi->getOrganization()->isEnabled()) {
             throw new BadCredentialsException('Organization is not active.');
         }
         // delete nonce from cache because user have another api keys
         if (!$isSecretValid && $secretsCount !== $currentIteration) {
             $this->getNonceCache()->delete($nonce);
         }
         if ($isSecretValid) {
             return $userApi;
         }
     }
     return false;
 }
开发者ID:xamin123,项目名称:platform,代码行数:34,代码来源:WsseAuthProvider.php


示例2: update

 /**
  * {@inheritdoc}
  */
 public function update(PersistentCollection $collection)
 {
     if ($collection->isDirty() && $collection->getSnapshot()) {
         throw CacheException::updateReadOnlyCollection(ClassUtils::getClass($collection->getOwner()), $this->association['fieldName']);
     }
     parent::update($collection);
 }
开发者ID:AdactiveSAS,项目名称:doctrine2,代码行数:10,代码来源:ReadOnlyCachedCollectionPersister.php


示例3: 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


示例4: transform

 /**
  * Transforms an ArrayCollection Object to a single Object.
  *
  * @param \Doctrine\ORM\PersistentCollection $values
  *
  * @return Object
  */
 public function transform($values)
 {
     if (null === $values || !$values instanceof Collection) {
         return null;
     }
     return $values->first();
 }
开发者ID:Opifer,项目名称:Cms,代码行数:14,代码来源:CollectionToObjectTransformer.php


示例5: clearPreviousCollection

 /**
  * Resets previous photo collection
  *
  * @param PersistentCollection $collection
  */
 protected function clearPreviousCollection(PersistentCollection $collection)
 {
     if ($collection->count()) {
         foreach ($collection as $item) {
             $collection->removeElement($item);
         }
     }
 }
开发者ID:raizeta,项目名称:WellCommerce,代码行数:13,代码来源:ProductPhotoCollectionToArrayTransformer.php


示例6: postBind

 /**
  * Form event - adds entities to uow to be delete
  * 
  * @param DataEvent $event
  */
 public function postBind(DataEvent $event)
 {
     $collection = $event->getData();
     if ($collection instanceof PersistentCollection) {
         foreach ($collection->getDeleteDiff() as $entity) {
             $this->om->remove($entity);
         }
     }
 }
开发者ID:firano,项目名称:form-bundle,代码行数:14,代码来源:MultiSelectSortableSubscriber.php


示例7: getCollection

 /**
  * @param array $items
  *
  * @return PersistentCollection
  */
 protected function getCollection(array $items = [])
 {
     /** @var \PHPUnit_Framework_MockObject_MockObject|EntityManager $em */
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     /** @var \PHPUnit_Framework_MockObject_MockObject|ClassMetadata $metadata */
     $metadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $collection = new PersistentCollection($em, $metadata, new ArrayCollection($items));
     $collection->takeSnapshot();
     return $collection;
 }
开发者ID:antrampa,项目名称:crm,代码行数:15,代码来源:CategoriesValidatorTest.php


示例8: numberComputersAndNumberEnabled

 public function numberComputersAndNumberEnabled(PersistentCollection $computers)
 {
     $nbComputersEnabled = 0;
     foreach ($computers as $computer) {
         if ($computer->isEnabled()) {
             $nbComputersEnabled++;
         }
     }
     return sprintf("%d computers (%d enabled)", $computers->count(), $nbComputersEnabled);
 }
开发者ID:GegrLmtte,项目名称:Formation-Symfony,代码行数:10,代码来源:ComputerExtension.php


示例9: getReferenceIds

 /**
  * @param \Doctrine\ORM\PersistentCollection $collection
  * @return array
  */
 public static function getReferenceIds($collection)
 {
     if ($collection) {
         return $collection->map(function ($obj) {
             /** @var \User\Entity\Resource $obj */
             return $obj->getId();
         })->toArray();
     } else {
         return null;
     }
 }
开发者ID:papertask,项目名称:papertask,代码行数:15,代码来源:Func.php


示例10: testShouldNotScheduleDeletionOnClonedInstances

 public function testShouldNotScheduleDeletionOnClonedInstances()
 {
     $class = $this->_em->getClassMetadata('Doctrine\\Tests\\Models\\ECommerce\\ECommerceProduct');
     $product = new ECommerceProduct();
     $category = new ECommerceCategory();
     $collection = new PersistentCollection($this->_em, $class, new ArrayCollection(array($category)));
     $collection->setOwner($product, $class->associationMappings['categories']);
     $uow = $this->_em->getUnitOfWork();
     $clonedCollection = clone $collection;
     $clonedCollection->clear();
     $this->assertEquals(0, count($uow->getScheduledCollectionDeletions()));
 }
开发者ID:selimcr,项目名称:servigases,代码行数:12,代码来源:DDC2074Test.php


示例11: 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


示例12: transform

 /**
  * Transforms an ArrayCollection Object to a single Object.
  *
  * @param \Doctrine\ORM\PersistentCollection $value
  *
  * @return Object
  */
 public function transform($value)
 {
     if (null === $value || !$value instanceof Collection) {
         return '';
     }
     $string = '';
     foreach ($value as $item) {
         $string .= $item->getId();
         if ($value->last() != $item) {
             $string .= ',';
         }
     }
     return $string;
 }
开发者ID:Opifer,项目名称:Cms,代码行数:21,代码来源:CollectionToStringTransformer.php


示例13: postSetDataProvider

 /**
  * @return array
  */
 public function postSetDataProvider()
 {
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $meta = $this->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
     $existing = (object) ['$existing' => true];
     $removed = (object) ['$removed' => true];
     $added = (object) ['$added' => true];
     $collectionWithElements = new ArrayCollection([$added]);
     $cleanCollection = new PersistentCollection($em, $meta, new ArrayCollection());
     $dirtyCollection = new PersistentCollection($em, $meta, new ArrayCollection([$existing, $removed]));
     $dirtyCollection->takeSnapshot();
     $dirtyCollection->removeElement($removed);
     $dirtyCollection->add($added);
     return ['Initialization with empty value should not be broken' => ['$data' => null, '$expectedAddedData' => [], '$expectedRemovedData' => []], 'Empty collection given should set nothing' => ['$data' => new ArrayCollection(), '$expectedAddedData' => [], '$expectedRemovedData' => []], 'Array collection with elements given, should be set to added' => ['$data' => $collectionWithElements, '$expectedAddedData' => [$added], '$expectedRemovedData' => []], 'Clean persistent collection given, should set nothing' => ['$data' => $cleanCollection, '$expectedAddedData' => [], '$expectedRemovedData' => []], 'Persistent collection given, should set from diffs' => ['$data' => $dirtyCollection, '$expectedAddedData' => [$added], '$expectedRemovedData' => [$removed]]];
 }
开发者ID:Maksold,项目名称:platform,代码行数:18,代码来源:MultipleEntitySubscriberTest.php


示例14: testHandleLoggable

 public function testHandleLoggable()
 {
     $loggableCollectionClass = new LoggableCollectionClass();
     $loggableCollectionClass->setName('testCollectionName');
     $collection = new PersistentCollection($this->em, get_class($loggableCollectionClass), array($loggableCollectionClass));
     $collection->setDirty(true);
     $this->loggableClass->setCollection($collection);
     $this->em->persist($this->loggableClass);
     //log with out user
     $this->loggableManager->handleLoggable($this->em);
     //log with user
     $this->loggableManager->setUsername('testUser');
     $this->loggableManager->handleLoggable($this->em);
     //log delete
     $this->em->remove($this->loggableClass);
     $this->loggableManager->handleLoggable($this->em);
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:17,代码来源:LoggableManagerTest.php


示例15: getMontantCompte

 public function getMontantCompte(PersistentCollection $transactions)
 {
     $total = 0;
     ### PENSER A METTRE LES TRANSACTIONS EN ORDRE DE DATE
     foreach (array_reverse($transactions->toArray(), true) as $key => $tra) {
         $type = $tra->getType();
         if ($type == "deb") {
             $total -= $tra->getMontant();
         } elseif ($type == "cre") {
             $total += $tra->getMontant();
         } else {
             // $type == "aju" && $type == "ini"
             $total = $tra->getMontant();
         }
     }
     return $total;
 }
开发者ID:TheBaptiste42,项目名称:BabaGestion,代码行数:17,代码来源:AccountController.php


示例16: update

 /**
  * {@inheritdoc}
  */
 public function update(PersistentCollection $collection)
 {
     $isInitialized = $collection->isInitialized();
     $isDirty = $collection->isDirty();
     if (!$isInitialized && !$isDirty) {
         return;
     }
     $ownerId = $this->uow->getEntityIdentifier($collection->getOwner());
     $key = new CollectionCacheKey($this->sourceEntity->rootEntityName, $this->association['fieldName'], $ownerId);
     // Invalidate non initialized collections OR ordered collection
     if ($isDirty && !$isInitialized || isset($this->association['orderBy'])) {
         $this->persister->update($collection);
         $this->queuedCache['delete'][spl_object_hash($collection)] = $key;
         return;
     }
     $this->persister->update($collection);
     $this->queuedCache['update'][spl_object_hash($collection)] = ['key' => $key, 'list' => $collection];
 }
开发者ID:AdactiveSAS,项目名称:doctrine2,代码行数:21,代码来源:NonStrictReadWriteCachedCollectionPersister.php


示例17: 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


示例18: loadCacheEntry

 /**
  * {@inheritdoc}
  */
 public function loadCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key, CollectionCacheEntry $entry, PersistentCollection $collection)
 {
     $assoc = $metadata->associationMappings[$key->association];
     $targetPersister = $this->uow->getEntityPersister($assoc['targetEntity']);
     $targetRegion = $targetPersister->getCacheRegion();
     $list = array();
     foreach ($entry->identifiers as $index => $identifier) {
         $entityEntry = $targetRegion->get(new EntityCacheKey($assoc['targetEntity'], $identifier));
         if ($entityEntry === null) {
             return null;
         }
         $list[$index] = $this->uow->createEntity($entityEntry->class, $entityEntry->data, self::$hints);
     }
     array_walk($list, function ($entity, $index) use($collection) {
         $collection->hydrateSet($index, $entity);
     });
     return $list;
 }
开发者ID:svobodni,项目名称:web,代码行数:21,代码来源:DefaultCollectionHydrator.php


示例19: loadCacheEntry

 /**
  * {@inheritdoc}
  */
 public function loadCacheEntry(ClassMetadata $metadata, CollectionCacheKey $key, CollectionCacheEntry $entry, PersistentCollection $collection)
 {
     $assoc = $metadata->associationMappings[$key->association];
     /* @var $targetPersister \Doctrine\ORM\Cache\Persister\CachedPersister */
     $targetPersister = $this->uow->getEntityPersister($assoc['targetEntity']);
     $targetRegion = $targetPersister->getCacheRegion();
     $list = [];
     $entityEntries = $targetRegion->getMultiple($entry);
     if ($entityEntries === null) {
         return null;
     }
     /* @var $entityEntries \Doctrine\ORM\Cache\EntityCacheEntry[] */
     foreach ($entityEntries as $index => $entityEntry) {
         $list[$index] = $this->uow->createEntity($entityEntry->class, $entityEntry->resolveAssociationEntries($this->em), self::$hints);
     }
     array_walk($list, function ($entity, $index) use($collection) {
         $collection->hydrateSet($index, $entity);
     });
     $this->uow->hydrationComplete();
     return $list;
 }
开发者ID:AdactiveSAS,项目名称:doctrine2,代码行数:24,代码来源:DefaultCollectionHydrator.php


示例20: buildSnapshotValue

 /**
  * @param PersistentCollection $coll
  *
  * @return string|null
  */
 protected function buildSnapshotValue(PersistentCollection $coll)
 {
     if ($coll->isEmpty()) {
         return null;
     }
     $ids = [];
     /** @var AbstractEnumValue $item */
     foreach ($coll as $item) {
         $ids[] = $item->getId();
     }
     sort($ids);
     $snapshot = implode(',', $ids);
     if (strlen($snapshot) > ExtendHelper::MAX_ENUM_SNAPSHOT_LENGTH) {
         $snapshot = substr($snapshot, 0, ExtendHelper::MAX_ENUM_SNAPSHOT_LENGTH);
         $lastDelim = strrpos($snapshot, ',');
         if (ExtendHelper::MAX_ENUM_SNAPSHOT_LENGTH - $lastDelim - 1 < 3) {
             $lastDelim = strrpos($snapshot, ',', -(strlen($snapshot) - $lastDelim + 1));
         }
         $snapshot = substr($snapshot, 0, $lastDelim + 1) . '...';
     }
     return $snapshot;
 }
开发者ID:Maksold,项目名称:platform,代码行数:27,代码来源:MultiEnumManager.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP ORM\Query类代码示例发布时间:2022-05-23
下一篇:
PHP ORM\OptimisticLockException类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap