本文整理匯總了PHP中Doctrine\ORM\PersistentCollection::matching方法的典型用法代碼示例。如果您正苦於以下問題:PHP PersistentCollection::matching方法的具體用法?PHP PersistentCollection::matching怎麽用?PHP PersistentCollection::matching使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\ORM\PersistentCollection
的用法示例。
在下文中一共展示了PersistentCollection::matching方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: sortRental
public function sortRental(PersistentCollection $rentals, $limit = 10)
{
$criteria = Criteria::create()->orderBy(['startAt' => Criteria::DESC])->setMaxResults($limit);
return $rentals->matching($criteria);
}
示例2: validateOrder
/**
* Check that collection is in right order.
*
* For increasing collection values must be in ascending order.
* For decreasing collection value must be in descending order.
*
* @param PersistentCollection $value
* @param CategoriesConstraint $constraint
*/
protected function validateOrder(PersistentCollection $value, CategoriesConstraint $constraint)
{
if ($value->isEmpty()) {
return;
}
$orderedByIndex = $value->matching(new Criteria(null, ['categoryIndex' => Criteria::ASC]));
$isIncreasing = $this->isIncreasing($orderedByIndex);
if ($isIncreasing) {
$criteria = Criteria::ASC;
} else {
$criteria = Criteria::DESC;
}
$orderedByValue = $value->matching(new Criteria(null, ['minValue' => $criteria]));
if ($orderedByValue->toArray() !== $orderedByIndex->toArray()) {
$this->context->addViolationAt($constraint->getType(), $constraint->message, ['%order%' => $criteria]);
return;
}
if (!$isIncreasing) {
return;
}
$invalidItems = $orderedByValue->filter(function (RFMMetricCategory $category) {
$maxValue = $category->getMaxValue();
if (!$maxValue) {
return false;
}
return $category->getMinValue() >= $maxValue;
});
if (!$invalidItems->isEmpty()) {
$this->context->addViolationAt($constraint->getType(), $constraint->message, ['%order%' => $criteria]);
}
}