本文整理汇总了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;
}
示例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);
}
示例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());
}
示例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();
}
示例5: clearPreviousCollection
/**
* Resets previous photo collection
*
* @param PersistentCollection $collection
*/
protected function clearPreviousCollection(PersistentCollection $collection)
{
if ($collection->count()) {
foreach ($collection as $item) {
$collection->removeElement($item);
}
}
}
示例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);
}
}
}
示例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;
}
示例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);
}
示例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;
}
}
示例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()));
}
示例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);
}
示例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;
}
示例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]]];
}
示例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);
}
示例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;
}