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


PHP ArrayCollection::filter方法代码示例

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


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

示例1: execute

 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var \Doctrine\ORM\EntityManager $em */
     $em = $this->getContainer()->get('doctrine.orm.default_entity_manager');
     $campaignRepo = $em->getRepository('VifeedCampaignBundle:Campaign');
     $campaigns = new ArrayCollection($campaignRepo->getActiveCampaigns());
     $hashes = [];
     foreach ($campaigns as $campaign) {
         /** @var Campaign $campaign */
         $hashes[] = $campaign->getHash();
     }
     $hashes = array_unique($hashes);
     $client = new \Google_Client();
     $client->setDeveloperKey($this->getContainer()->getParameter('google.api.key'));
     $youtube = new \Google_Service_YouTube($client);
     /* Опытным путём выяснилось, что ютуб принимает не больше 50 хешей за раз */
     $hash = 'TjvivnmWcn4';
     $request = $youtube->videos->listVideos('status', ['id' => $hash]);
     foreach ($request as $video) {
         /** @var \Google_Service_YouTube_Video $video */
         /** @var \Google_Service_YouTube_VideoStatistics $stats */
         $stats = $video->getStatistics();
         $hash = $video->getId();
         /* не исключается ситуация, что может быть несколько кампаний с одинаковым hash */
         $filteredCampaigns = $campaigns->filter(function (Campaign $campaign) use($hash) {
             return $campaign->getHash() == $hash;
         });
         foreach ($filteredCampaigns as $campaign) {
             $campaign->setSocialData('youtubeViewCount', $stats->getViewCount())->setSocialData('youtubeCommentCount', $stats->getCommentCount())->setSocialData('youtubeFavoriteCount', $stats->getFavoriteCount())->setSocialData('youtubeLikeCount', $stats->getLikeCount())->setSocialData('youtubeDislikeCount', $stats->getDislikeCount());
             $em->persist($campaign);
         }
     }
     $em->flush();
 }
开发者ID:bzis,项目名称:zomba,代码行数:37,代码来源:GetYouTubeDataCommand.php

示例2: getTaskByDescription

 /**
  * @param TaskDescription $description
  * @return mixed
  * @throws DomainException
  */
 public function getTaskByDescription(TaskDescription $description)
 {
     $tasksFound = $this->tasks->filter(function (Task $task) use($description) {
         return $description->equals($task->getDescription());
     });
     if ($tasksFound->isEmpty()) {
         throw new DomainException('Task ' . $description . ' does not exist in working day');
     }
     return $tasksFound->first();
 }
开发者ID:destebang,项目名称:taskreporter-1,代码行数:15,代码来源:WorkingDay.php

示例3: getOxfordItems

 /**
  * Return the last oxford comma eligible word
  * in the sentence
  *
  * @return ArrayCollection|Word[]
  */
 public function getOxfordItems()
 {
     $words = new ArrayCollection();
     $conjunctions = $this->words->filter(function (Word $word) {
         return $word instanceof Conjunction;
     });
     $conjunctions->map(function ($word) use($words) {
         if ($this->hasOxfordable($word)) {
             $index = $this->words->indexOf($word) - 1;
             $words->add($this->words->get($index));
         }
     });
     return $words;
 }
开发者ID:epfremmer,项目名称:PHP-Weekly-Issue28,代码行数:20,代码来源:Sentence.php

示例4: remove

 /**
  * @inheritdoc
  */
 public function remove(AmountInterface $amount)
 {
     if (!$this->has($amount)) {
         return $this;
     }
     $a = $this->find($amount);
     if ($a->getBase() > $amount->getBase()) {
         $a->removeBase($amount->getBase());
     } else {
         $this->amounts = $this->amounts->filter(function (AmountInterface $a) use($amount) {
             return !$a->equals($amount);
         });
     }
     return $this;
 }
开发者ID:ekyna,项目名称:commerce,代码行数:18,代码来源:Amounts.php

示例5: testConfigureSandboxNotCached

 /**
  * configureSanbox method with not cached scenario
  */
 public function testConfigureSandboxNotCached()
 {
     $entityClass = 'Oro\\Bundle\\UserBundle\\Entity\\User';
     $configIdMock = $this->getMockForAbstractClass('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\ConfigIdInterface');
     $configIdMock->expects($this->once())->method('getClassName')->will($this->returnValue($entityClass));
     $configuredData = array($entityClass => array('getsomecode'));
     $this->cache->expects($this->once())->method('fetch')->with($this->cacheKey)->will($this->returnValue(false));
     $this->cache->expects($this->once())->method('save')->with($this->cacheKey, serialize($configuredData));
     $configurableEntities = array($configIdMock);
     $this->configProvider->expects($this->once())->method('getIds')->will($this->returnValue($configurableEntities));
     $fieldsCollection = new ArrayCollection();
     $this->configProvider->expects($this->once())->method('filter')->will($this->returnCallback(function ($callback) use($fieldsCollection) {
         return $fieldsCollection->filter($callback);
     }));
     $field1Id = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\FieldConfigId')->disableOriginalConstructor()->getMock();
     $field1Id->expects($this->once())->method('getFieldName')->will($this->returnValue('someCode'));
     $field1 = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $field2 = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $field1->expects($this->once())->method('is')->with('available_in_template')->will($this->returnValue(true));
     $field1->expects($this->once())->method('getId')->will($this->returnValue($field1Id));
     $field2->expects($this->once())->method('is')->with('available_in_template')->will($this->returnValue(false));
     $fieldsCollection->add($field1);
     $fieldsCollection->add($field2);
     $this->getRendererInstance();
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:28,代码来源:EmailRendererTest.php

示例6: handleMembersUpdate

 /**
  * @param StaticSegment $staticSegment
  * @param string $segmentStateFilter
  * @param string $method
  * @param string $itemState
  * @param bool $deleteMember
  * @return array
  */
 public function handleMembersUpdate(StaticSegment $staticSegment, $segmentStateFilter, $method, $itemState, $deleteMember = false)
 {
     $itemsToWrite = [];
     $items = $staticSegment->getSegmentMembers()->filter(function (StaticSegmentMember $segmentMember) use($segmentStateFilter) {
         return $segmentMember->getState() === $segmentStateFilter;
     })->toArray();
     if (empty($items)) {
         return [];
     }
     $emails = array_map(function (StaticSegmentMember $segmentMember) {
         return $segmentMember->getMember()->getEmail();
     }, $items);
     $response = $this->transport->{$method}(['id' => $staticSegment->getSubscribersList()->getOriginId(), 'seg_id' => (int) $staticSegment->getOriginId(), 'batch' => array_map(function ($email) {
         return ['email' => $email];
     }, $emails), 'delete_member' => $deleteMember]);
     $this->handleResponse($response, function ($response, LoggerInterface $logger) use($staticSegment) {
         $logger->info(sprintf('Segment #%s [origin_id=%s] Members: [%s] add, [%s] error', $staticSegment->getId(), $staticSegment->getOriginId(), $response['success_count'], $response['error_count']));
     });
     $emailsWithErrors = $this->getArrayData($response, 'errors');
     /** @var StaticSegmentMember[]|ArrayCollection $items */
     $items = new ArrayCollection($items);
     $items->filter(function (StaticSegmentMember $segmentMember) use($emailsWithErrors) {
         return !in_array($segmentMember->getMember()->getEmail(), $emailsWithErrors, true);
     });
     foreach ($items as $item) {
         $item->setState($itemState);
         $this->logger->debug(sprintf('Member with id "%s" and email "%s" got "%s" state', $item->getMember()->getOriginId(), $item->getMember()->getEmail(), $itemState));
         $itemsToWrite[] = $item;
     }
     return $itemsToWrite;
 }
开发者ID:aculvi,项目名称:OroCRMMailChimpBundle,代码行数:39,代码来源:StaticSegmentExportWriter.php

示例7: getTokenForService

 /**
  * @param string $service
  * @return Hash|false
  */
 public function getTokenForService($service)
 {
     $token = $this->tokens->filter(function (Token $token) use($service) {
         return $token->getService() == $service;
     })->first();
     return $token ? $token->getToken() : false;
 }
开发者ID:martha-ci,项目名称:martha-core,代码行数:11,代码来源:User.php

示例8: getEditors

 /**
  * @return ArrayCollection
  */
 public function getEditors()
 {
     $editors = $this->users->filter(function (User $user) {
         return $user->isEditor();
     });
     return $editors;
 }
开发者ID:armandomeeuwenoord,项目名称:icup,代码行数:10,代码来源:Host.php

示例9: findBy

 /**
  * @param array $filters
  * @param int   $limit
  * @param int   $offset
  *
  * @return array
  */
 public function findBy(array $filters, $limit = null, $offset = 0)
 {
     $result = $this->result->filter(function ($item) use($filters) {
         // filter all non valid conditions
         foreach ($filters as $key => $value) {
             if (!array_key_exists($key, $item) || $item[$key] != $value) {
                 return false;
             }
         }
         return true;
     });
     if (empty($limit)) {
         return $result->toArray();
     }
     return $result->slice($offset, $limit);
 }
开发者ID:pixelfederation,项目名称:google-api-php-client,代码行数:23,代码来源:Result.php

示例10: getPermission

 /**
  * @param Permission|string $permission
  *
  * @return Permission|null
  */
 protected function getPermission($permission)
 {
     $name = $permission instanceof Permission ? $permission->getName() : $permission;
     return $this->permissions->filter(function (Permission $current) use($name) {
         return $current->getName() == $name;
     })->first();
 }
开发者ID:digbang,项目名称:security,代码行数:12,代码来源:PermissibleTrait.php

示例11: getPreliminaryGroup

 /**
  * @return Group
  */
 public function getPreliminaryGroup()
 {
     $gos = $this->grouporder->filter(function (GroupOrder $grouporder) {
         return $grouporder->getGroup()->getClassification() == Group::$PRE;
     });
     return $gos->count() == 1 ? $gos->first()->getGroup() : null;
 }
开发者ID:armandomeeuwenoord,项目名称:icup,代码行数:10,代码来源:Team.php

示例12: filter

 public function filter(Closure $p)
 {
     if (null === $this->entries) {
         $this->__load___();
     }
     return $this->entries->filter($p);
 }
开发者ID:luisbrito,项目名称:Phraseanet,代码行数:7,代码来源:AggregateEntryCollection.php

示例13: batchSubscribe

 /**
  * @param SubscribersList $subscribersList
  * @param array|ArrayCollection $items
  * @return array
  */
 protected function batchSubscribe(SubscribersList $subscribersList, array $items)
 {
     $itemsToWrite = [];
     $emails = array_map(function (Member $member) {
         return ['email' => ['email' => $member->getEmail()], 'merge_vars' => $member->getMergeVarValues()];
     }, $items);
     $response = $this->transport->batchSubscribe(['id' => $subscribersList->getOriginId(), 'batch' => $emails, 'double_optin' => false, 'update_existing' => true]);
     $this->handleResponse($response, function ($response, LoggerInterface $logger) use($subscribersList) {
         $logger->info(sprintf('List #%s [origin_id=%s]: [%s] add, [%s] update, [%s] error', $subscribersList->getId(), $subscribersList->getOriginId(), $response['add_count'], $response['update_count'], $response['error_count']));
     });
     $emailsAdded = $this->getArrayData($response, 'adds');
     $emailsUpdated = $this->getArrayData($response, 'updates');
     $items = new ArrayCollection($items);
     foreach (array_merge($emailsAdded, $emailsUpdated) as $emailData) {
         /** @var Member $member */
         $member = $items->filter(function (Member $member) use($emailData) {
             return $member->getEmail() === $emailData['email'];
         })->first();
         if ($member) {
             $member->setEuid($emailData['euid'])->setLeid($emailData['leid'])->setStatus(Member::STATUS_SUBSCRIBED);
             $itemsToWrite[] = $member;
             $this->logger->debug(sprintf('Member with data "%s" successfully processed', json_encode($emailData)));
         } else {
             $this->logger->warning(sprintf('A member with "%s" email was not found', $emailData['email']));
         }
     }
     return $itemsToWrite;
 }
开发者ID:aculvi,项目名称:OroCRMMailChimpBundle,代码行数:33,代码来源:MemberWriter.php

示例14: filterCases

 /**
  * @internal
  * @param string $caseFilter
  * @return ArrayCollection
  */
 protected function filterCases($caseFilter)
 {
     $this->initCases();
     return $this->cases->filter(function ($item) use($caseFilter) {
         return $item instanceof $caseFilter;
     });
 }
开发者ID:ministryofjustice,项目名称:opg-core-public-domain-model,代码行数:12,代码来源:HasCases.php

示例15: testGetTemplateVariables

 /**
  * @dataProvider fieldsDataProvider
  * @param $entityIsUser
  */
 public function testGetTemplateVariables($entityIsUser)
 {
     $configId1Mock = $this->getMockForAbstractClass('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\ConfigIdInterface');
     $configId1Mock->expects($this->once())->method('getClassName')->will($this->returnValue(get_class($this->user)));
     $configId2Mock = $this->getMockForAbstractClass('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\ConfigIdInterface');
     $configId2Mock->expects($this->once())->method('getClassName')->will($this->returnValue(self::TEST_ENTITY_NAME));
     $configId3Mock = $this->getMockForAbstractClass('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\ConfigIdInterface');
     $configId3Mock->expects($this->once())->method('getClassName')->will($this->returnValue(self::TEST_NOT_NEEDED_ENTITY_NAME));
     $configurableEntities = array($configId1Mock, $configId2Mock, $configId3Mock);
     $this->configProvider->expects($this->once())->method('getIds')->will($this->returnValue($configurableEntities));
     $field1Id = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\FieldConfigId')->disableOriginalConstructor()->getMock();
     $field1Id->expects($this->any())->method('getFieldName')->will($this->returnValue('someCode'));
     $field1 = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $field2 = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $field1->expects($this->any())->method('is')->with('available_in_template')->will($this->returnValue(true));
     $field1->expects($this->any())->method('getId')->will($this->returnValue($field1Id));
     $field2->expects($this->any())->method('is')->with('available_in_template')->will($this->returnValue(false));
     // fields for entity
     $fieldsCollection = new ArrayCollection();
     $this->configProvider->expects($this->at(1))->method('filter')->will($this->returnCallback(function ($callback) use($fieldsCollection) {
         return $fieldsCollection->filter($callback)->toArray();
     }));
     $fieldsCollection[] = $field1;
     $fieldsCollection[] = $field2;
     if (!$entityIsUser) {
         $field3Id = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\Id\\FieldConfigId')->disableOriginalConstructor()->getMock();
         $field3Id->expects($this->any())->method('getFieldName')->will($this->returnValue('someAnotherCode'));
         $field3 = clone $field1;
         $field3->expects($this->atLeastOnce())->method('is')->with('available_in_template')->will($this->returnValue(true));
         $field3->expects($this->atLeastOnce())->method('getId')->will($this->returnValue($field3Id));
         $this->configProvider->expects($this->at(2))->method('filter')->will($this->returnCallback(function ($callback) use($fieldsCollection, $field3) {
             $fieldsCollection[] = $field3;
             return $fieldsCollection->filter($callback)->toArray();
         }));
         $result = $this->provider->getTemplateVariables(self::TEST_ENTITY_NAME);
     } else {
         $result = $this->provider->getTemplateVariables(get_class($this->user));
     }
     $this->assertArrayHasKey('user', $result);
     $this->assertArrayHasKey('entity', $result);
     $this->assertInternalType('array', $result['user']);
     $this->assertInternalType('array', $result['entity']);
     if ($entityIsUser) {
         $this->assertEquals($result['user'], $result['entity']);
     }
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:50,代码来源:VariableProviderTest.php


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