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


PHP ORM\PersistentCollection类代码示例

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


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


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