本文整理汇总了PHP中Doctrine\Common\Collections\Collection::matching方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::matching方法的具体用法?PHP Collection::matching怎么用?PHP Collection::matching使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Collections\Collection
的用法示例。
在下文中一共展示了Collection::matching方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sort
/**
* Sort existing value collection utility.
*
* @param Collection $values
* @param string $sortKey
* @return Collection
*/
public static function sort(Collection $values, $sortKey)
{
$criteria = new Criteria();
switch ($sortKey) {
case self::BY_ALPHA_ASC:
$criteria->orderBy(array('value' => Criteria::ASC));
break;
case self::BY_ALPHA_DESC:
$criteria->orderBy(array('value' => Criteria::DESC));
break;
case self::BY_ID_ASC:
$criteria->orderBy(array('id' => Criteria::ASC));
break;
case self::BY_ID_DESC:
$criteria->orderBy(array('id' => Criteria::DESC));
break;
case self::BY_NUMBER:
default:
$criteria->orderBy(array('order' => Criteria::ASC));
break;
}
return $values->matching($criteria);
}
示例2: findData
/**
* Finds a data entity
*
* @param string $key
*
* @return object|null
*/
protected function findData($key)
{
$criteria = Criteria::create()->where(Criteria::expr()->eq('key', $key));
$result = $this->data->matching($criteria);
if (is_array($result)) {
$result = reset($result);
return $result;
}
}
示例3: testMatchingSlice
/**
* @group DDC-1637
*/
public function testMatchingSlice()
{
$this->fillMatchingFixture();
$col = $this->_coll->matching(new Criteria(null, null, 1, 1));
$this->assertInstanceOf('Doctrine\\Common\\Collections\\Collection', $col);
$this->assertNotSame($col, $this->_coll);
$this->assertEquals(1, count($col));
$this->assertEquals('baz', $col[0]->foo);
}
示例4: getFilteredCollection
/**
* @return Collection
*/
private function getFilteredCollection()
{
return $this->data_source->matching($this->criteria);
}
示例5: getPriceListCurrencyByCode
/**
* @param string $currency
* @return PriceListCurrency
*/
public function getPriceListCurrencyByCode($currency)
{
$criteria = Criteria::create()->where(Criteria::expr()->eq('currency', $currency));
return $this->currencies->matching($criteria)->first();
}
示例6: matching
/**
* Selects all elements from a selectable that match the expression and
* return a new collection containing these elements.
*
* @param \Doctrine\Common\Collections\Criteria $criteria
*
* @return Collection
*
* @throws \RuntimeException
*/
public function matching(Criteria $criteria)
{
if ($this->isDirty) {
$this->initialize();
}
if ($this->initialized) {
return $this->coll->matching($criteria);
}
if ($this->association['type'] === ClassMetadata::MANY_TO_MANY) {
$persister = $this->em->getUnitOfWork()->getCollectionPersister($this->association);
return new ArrayCollection($persister->loadCriteria($this, $criteria));
}
$builder = Criteria::expr();
$ownerExpression = $builder->eq($this->backRefFieldName, $this->owner);
$expression = $criteria->getWhereExpression();
$expression = $expression ? $builder->andX($expression, $ownerExpression) : $ownerExpression;
$criteria->where($expression);
$persister = $this->em->getUnitOfWork()->getEntityPersister($this->association['targetEntity']);
return $this->association['fetch'] === ClassMetadataInfo::FETCH_EXTRA_LAZY ? new LazyCriteriaCollection($persister, $criteria) : new ArrayCollection($persister->loadCriteria($criteria));
}
示例7: matching
/**
* Select all elements from a selectable that match the expression and
* return a new collection containing these elements.
*
* @param \Doctrine\Common\Collections\Criteria $criteria
* @return Collection
*/
public function matching(Criteria $criteria)
{
if ($this->isDirty) {
$this->initialize();
}
if ($this->initialized) {
return $this->coll->matching($criteria);
}
if ($this->association['type'] !== ClassMetadata::ONE_TO_MANY) {
throw new \RuntimeException("Matching Criteria on PersistentCollection only works on OneToMany assocations at the moment.");
}
$id = $this->em->getClassMetadata(get_class($this->owner))->getSingleIdReflectionProperty()->getValue($this->owner);
$builder = Criteria::expr();
$ownerExpression = $builder->eq($this->backRefFieldName, $id);
$expression = $criteria->getWhereExpression();
$expression = $expression ? $builder->andX($expression, $ownerExpression) : $ownerExpression;
$criteria->where($expression);
$persister = $this->em->getUnitOfWork()->getEntityPersister($this->association['targetEntity']);
return new ArrayCollection($persister->loadCriteria($criteria));
}
示例8: hasPermission
/**
* {@inheritDoc}
*/
public function hasPermission($permission)
{
$criteria = Criteria::create()->where(Criteria::expr()->eq('name', (string) $permission));
$result = $this->permissions->matching($criteria);
return count($result) > 0;
}
示例9: getParameters
/**
* @return ParameterInterface[]
*/
public function getParameters()
{
return $this->parameters->matching(Criteria::create()->where(Criteria::expr()->isNull('parent')));
}
示例10: getProductsCountChecked
public function getProductsCountChecked()
{
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('checked', true));
return $this->products->matching($criteria)->count();
}
示例11: getActiveChildren
/**
* @return Collection
*/
public function getActiveChildren()
{
$criteria = Criteria::create()->where(Criteria::expr()->eq("isActive", true));
$result = $this->children->matching($criteria);
return $result;
}
示例12: getAcceptedReviews
/**
* {@inheritdoc}
*/
public function getAcceptedReviews()
{
$criteria = Criteria::create()->where(Criteria::expr()->eq('status', ReviewInterface::STATUS_ACCEPTED));
return $this->reviews->matching($criteria);
}
示例13: getLatestActivities
public function getLatestActivities($type = Activity::ACTIVITY_TYPE_COMMIT)
{
if (!in_array($type, array(Activity::ACTIVITY_TYPE_COMMIT, Activity::ACTIVITY_TYPE_RECOMMEND, Activity::ACTIVITY_TYPE_TRAVIS_BUILD))) {
throw new \InvalidArgumentException();
}
$criteria = Criteria::create()->where(Criteria::expr()->eq('type', $type))->orderBy(array("createdAt" => "DESC"))->setFirstResult(0)->setMaxResults(30);
return $this->activities->matching($criteria);
}
示例14: getCurrentRegistrationStatus
/**
*
* @return RegistrationStatus
*/
public function getCurrentRegistrationStatus()
{
$criteria = Criteria::create()->where(Criteria::expr()->eq("isCurrent", true))->setMaxResults(1);
$result = $this->registrationStatus->matching($criteria);
return $result->toArray()[0];
}
示例15: getEpisodes
/**
* @return Episode[]
*/
public function getEpisodes()
{
$criteria = Criteria::create();
$criteria->orderBy(['number' => Criteria::ASC]);
return $this->episodes->matching($criteria)->toArray();
}