本文整理汇总了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]);
}
}