本文整理匯總了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();
});
}
示例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;
}
示例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());
}
示例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());
}
示例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());
}
示例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;
});
}
示例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;
});
}
示例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;
});
}
示例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;
}
示例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();
}
示例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;
}
示例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);
}
}
}
示例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();
}
示例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;
}
示例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;
}