當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Collection::filter方法代碼示例

本文整理匯總了PHP中Doctrine\Common\Collections\Collection::filter方法的典型用法代碼示例。如果您正苦於以下問題:PHP Collection::filter方法的具體用法?PHP Collection::filter怎麽用?PHP Collection::filter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\Common\Collections\Collection的用法示例。


在下文中一共展示了Collection::filter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getAdjustments

 /**
  * {@inheritdoc}
  */
 public function getAdjustments($type = null)
 {
     if (null === $type) {
         return $this->adjustments;
     }
     return $this->adjustments->filter(function (AdjustmentInterface $adjustment) use($type) {
         return $type === $adjustment->getType();
     });
 }
開發者ID:sylius,項目名稱:order,代碼行數:12,代碼來源:OrderItemUnit.php

示例2: removeProduct

 public function removeProduct(UuidIdentity $id)
 {
     $element = $this->lineItems->filter(function (LineItem $lineItem) use($id) {
         return $lineItem->getProduct()->getId()->getValue() === $id->getValue();
     })->first();
     if ($element) {
         $this->lineItems->removeElement($element);
     }
     return $this;
 }
開發者ID:igaponov,項目名稱:shop,代碼行數:10,代碼來源:Cart.php

示例3: testFilter

 public function testFilter()
 {
     $this->_coll->add(1);
     $this->_coll->add("foo");
     $this->_coll->add(3);
     $res = $this->_coll->filter(function ($e) {
         return is_numeric($e);
     });
     $this->assertEquals(array(0 => 1, 2 => 3), $res->toArray());
 }
開發者ID:TuxCoffeeCorner,項目名稱:tcc,代碼行數:10,代碼來源:CollectionTest.php

示例4: filterDeleted

 /**
  * @param Collection $collection
  *
  * @return ArrayCollection
  */
 private function filterDeleted(Collection $collection) : ArrayCollection
 {
     // getValues => reset keys
     return new ArrayCollection($collection->filter(function ($entity) {
         return !$entity instanceof SoftDeletableInterface || $entity->isDeleted() === false;
     })->getValues());
 }
開發者ID:staspiv,項目名稱:rest-bundle,代碼行數:12,代碼來源:SoftDeletableTrait.php

示例5: findEndBeforeNow

 /**
  * {@inheritdoc}
  */
 public function findEndBeforeNow()
 {
     $now = new \DateTime();
     return array_values($this->taskCollection->filter(function (TaskInterface $task) use($now) {
         return $task->getLastExecution() === null || $task->getLastExecution() > $now;
     })->toArray());
 }
開發者ID:php-task,項目名稱:php-task,代碼行數:10,代碼來源:ArrayTaskRepository.php

示例6: findScheduled

 /**
  * {@inheritdoc}
  */
 public function findScheduled()
 {
     $dateTime = new \DateTime();
     return $this->taskExecutionCollection->filter(function (TaskExecutionInterface $execution) use($dateTime) {
         return $execution->getStatus() === TaskStatus::PLANNED && $execution->getScheduleTime() < $dateTime;
     });
 }
開發者ID:php-task,項目名稱:php-task,代碼行數:10,代碼來源:ArrayTaskExecutionRepository.php

示例7: getAttributesByType

 /**
  * @param string $type
  * @return Collection|Attribute[]
  */
 public function getAttributesByType($type)
 {
     return $this->attributes->filter(function ($attribute) use($type) {
         /** @var Attribute $attribute */
         return $attribute->getType() == $type;
     });
 }
開發者ID:ramunasd,項目名稱:platform,代碼行數:11,代碼來源:AttributeManager.php

示例8: filterCurrentItems

 /**
  * Filters a collection to get only current items
  *
  * @param Collection $collection
  *
  * @return Collection
  */
 protected function filterCurrentItems(Collection $collection)
 {
     $endDate = new DateTime();
     $format = $this->configuration->getGroupByDateFormat();
     $identifier = $endDate->format($format);
     return $collection->filter(function (ReportRow $row) use($identifier) {
         return $row->getIdentifier() === $identifier;
     });
 }
開發者ID:Newman101,項目名稱:WellCommerce,代碼行數:16,代碼來源:SalesSummaryCalculator.php

示例9: getTaxons

 /**
  * {@inheritdoc}
  */
 public function getTaxons($taxonomy = null)
 {
     if (null !== $taxonomy) {
         return $this->taxons->filter(function (BaseTaxonInterface $taxon) use($taxonomy) {
             return $taxonomy === strtolower($taxon->getTaxonomy()->getName());
         });
     }
     return $this->taxons;
 }
開發者ID:sidibea,項目名稱:Sylius,代碼行數:12,代碼來源:Product.php

示例10: getLastPayment

 /**
  * {@inheritdoc}
  */
 public function getLastPayment($state = BasePaymentInterface::STATE_NEW)
 {
     if ($this->payments->isEmpty()) {
         return false;
     }
     return $this->payments->filter(function (BasePaymentInterface $payment) use($state) {
         return $payment->getState() === $state;
     })->last();
 }
開發者ID:vikey89,項目名稱:Sylius,代碼行數:12,代碼來源:Order.php

示例11: getTaxons

 /**
  * {@inheritdoc}
  */
 public function getTaxons($rootTaxonCode = null)
 {
     if (null !== $rootTaxonCode) {
         return $this->taxons->filter(function (BaseTaxonInterface $taxon) use($rootTaxonCode) {
             return $rootTaxonCode === strtolower($taxon->getRoot()->getCode());
         });
     }
     return $this->taxons;
 }
開發者ID:origammi,項目名稱:Sylius,代碼行數:12,代碼來源:Product.php

示例12: persist

 /**
  * @param EntityManager $em The entity manager
  */
 public function persist(EntityManager $em)
 {
     foreach ($this->mediaSet->filter(function (PageMedia $item) {
         return (bool) $item->getMedia();
     }) as $item) {
         $em->persist($item);
     }
     foreach ($this->toDelete as $item) {
         $callback = function ($key, PageMedia $element) use($item) {
             /** @noinspection PhpExpressionResultUnusedInspection */
             $key;
             return $element->getType() === $item->getType() && $element->getMedia();
         };
         if (false === $this->mediaSet->exists($callback)) {
             $em->remove($item);
         }
     }
 }
開發者ID:syzygypl,項目名稱:page-media-set-bundle,代碼行數:21,代碼來源:FormWidget.php

示例13: getDefaultTitle

 /**
  * @return LocalizedFallbackValue
  */
 public function getDefaultTitle()
 {
     $titles = $this->titles->filter(function (LocalizedFallbackValue $title) {
         return null === $title->getLocale();
     });
     if ($titles->count() != 1) {
         throw new \LogicException('There must be only one default title');
     }
     return $titles->first();
 }
開發者ID:hafeez3000,項目名稱:orocommerce,代碼行數:13,代碼來源:Category.php

示例14: getLastPayment

 /**
  * @param string|null $state
  *
  * @return BasePaymentInterface|null
  */
 public function getLastPayment($state = null)
 {
     if ($this->payments->isEmpty()) {
         return null;
     }
     $payment = $this->payments->filter(function (BasePaymentInterface $payment) use($state) {
         return null === $state || $payment->getState() === $state;
     })->last();
     return $payment !== false ? $payment : null;
 }
開發者ID:NeverResponse,項目名稱:Sylius,代碼行數:15,代碼來源:Order.php

示例15: getLastNewPayment

 /**
  * {@inheritdoc}
  */
 public function getLastNewPayment()
 {
     if ($this->payments->isEmpty()) {
         return null;
     }
     $payment = $this->payments->filter(function (BasePaymentInterface $payment) {
         return $payment->getState() === BasePaymentInterface::STATE_NEW;
     })->last();
     return $payment !== false ? $payment : null;
 }
開發者ID:sylius,項目名稱:core,代碼行數:13,代碼來源:Order.php


注:本文中的Doctrine\Common\Collections\Collection::filter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。