Add criteria to repository query or return criteria service.

@param CriteriaInterface|null $criteria

@throws InvalidCriteria

@return CriteriaService|$this
161921
public function criteria($criteria = null)
    {
        if (is_null($criteria)) {
            return $this->mediator->criteria();
        }

        if (!is_null($criteria) && !is_a($criteria, CriteriaInterface::class)) {
            throw new InvalidCriteria();
        }

        $this->mediator->criteria()->addCriteria($criteria);

        return $this;
    }
886864
public static function findOneByCriteria(array $criteria): ?self
    {
        try {
            list($columns, $values, $options) = static::parseCriteria($criteria);
        } catch (NoTagsException $e) {
            return null;
        }

        if (\count($columns) < 1) {
            return null;
        }

        return static::findOneBy($columns, $values, $options);
    }
1274783
public function createQuery(array $criteria = array())
    {
        $class = $this->documentClass.'Query';
        $query = new $class($this);
        $query->criteria($criteria);

        return $query;
    }
931597
public static function create($modelAlias = null, $criteria = null)
    {
        if ($criteria instanceof \AttributeType\Model\AttributeTypeI18nQuery) {
            return $criteria;
        }
        $query = new \AttributeType\Model\AttributeTypeI18nQuery();
        if (null !== $modelAlias) {
            $query->setModelAlias($modelAlias);
        }
        if ($criteria instanceof Criteria) {
            $query->mergeWith($criteria);
        }

        return $query;
    }
1366895
public static function create($modelAlias = null, $criteria = null)
    {
        if ($criteria instanceof UserCustomerRelationQuery) {
            return $criteria;
        }
        $query = new UserCustomerRelationQuery(null, null, $modelAlias);

        if ($criteria instanceof Criteria) {
            $query->mergeWith($criteria);
        }

        return $query;
    }
607128
protected function normalizeCriteria($criteria) {
		if ($criteria instanceof Criteria) {
			return $criteria->assemble();
		}
		
		if (is_array($criteria)) {
			return $criteria;
		}
		
		throw new Exceptions\InvalidCriteria('Invalid type of the criteria: "' . gettype($criteria) . '"');
	}
1351239
public function addAnd(AbstractCriterion $criterion)
    {
        $this->clauses[] = $criterion;
        $this->conjunctions[] = self::UND;

        return $this;
    }
123271
public function addSelectQuery(Criteria $subQueryCriteria, $alias = null)
    {
        if (null === $alias) {
            $alias = 'alias_' . ($subQueryCriteria->forgeSelectQueryAlias() + count($this->selectQueries));
        }
        $this->selectQueries[$alias] = $subQueryCriteria;

        return $this;
    }
511633
private function applyCriteriaToQueryBuilder(Criteria $criteria, QueryBuilder $qb, $prefix)
    {
        if ($criteria->getMode() === Criteria::MODE_OR) {
            $expr = $qb->expr()->orX();
        } else {
            $expr = $qb->expr()->andX();
        }
        foreach ($criteria as $criterium) {
            if ($criterium instanceof Criteria) {
                $expr->add(
                    $this->applyCriteriaToQueryBuilder($criterium, $qb, $prefix)
                );
            } else {
                $this->applyCriteriumToQueryBuilder($criterium, $qb, $expr, $prefix);
            }
        }

        return $expr;
    }
998311
public function append($operator, Criteria $criteria)
    {
        $this->children[] = new Node(self::TYPE_LEAF, $operator, $criteria);
        $this->mostRecentCriteria = $criteria;

        return $this;
    }
1207099
private function factoryCallableCriteria($criteria)
    {
        if (!$this->isCallable($criteria)) {
            $criteria = function ($element, $key) use ($criteria) {
                return $element->fetch($criteria);
            };
        }

        return $criteria;
    }
894972
public function matching(Criteria $criteria)
    {
        if ($this->isDirty) {
            $this->initialize();
        }

        if ($this->initialized) {
            return $this->collection->matching($criteria);
        }

        if ($this->association instanceof ManyToManyAssociationMetadata) {
            $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 = clone $criteria;
        $criteria->where($expression);

        $persister = $this->em->getUnitOfWork()->getEntityPersister($this->association->getTargetEntity());

        return $this->association->getFetchMode() === FetchMode::EXTRA_LAZY
            ? new LazyCriteriaCollection($persister, $criteria)
            : new ArrayCollection($persister->loadCriteria($criteria));
    }
893977
public function init(Criteria $criteria)
    {
        // init $this->db
        try {
            $db = Propel::getDB($criteria->getDbName());
            $this->setDB($db);
        } catch (Exception $e) {
            // we are only doing this to allow easier debugging, so
            // no need to throw up the exception, just make note of it.
            Propel::log("Could not get a DBAdapter, sql may be wrong", Propel::LOG_ERR);
        }

        // init $this->realtable
        $realtable = $criteria->getTableForAlias($this->table);
        $this->realtable = $realtable ? $realtable : $this->table;
    }
403025
protected function validateCriterionInput(Criterion $criterion)
    {
        /** @var $criterion \eZ\Publish\API\Repository\Values\Content\Query\Criterion\LogicalOperator */
        if (!isset($criterion->criteria[0]) || (count($criterion->criteria) > 1)) {
            throw new RuntimeException('Invalid aggregation in LogicalNot criterion.');
        }
    }
1229415
public function matching(Criteria $criteria)
    {
        $visitor = new QueryExpressionVisitor($this->createQueryBuilder());
        $queryBuilder = $this->createQueryBuilder();

        if ($criteria->getWhereExpression() !== null) {
            $expr = $visitor->dispatch($criteria->getWhereExpression());
            $queryBuilder->setQueryArray($expr->getQuery());
        }

        if ($criteria->getMaxResults() !== null) {
            $queryBuilder->limit($criteria->getMaxResults());
        }

        if ($criteria->getFirstResult() !== null) {
            $queryBuilder->skip($criteria->getFirstResult());
        }

        if ($criteria->getOrderings() !== null) {
            $queryBuilder->sort($criteria->getOrderings());
        }

        // @TODO: wrap around a specialized Collection for efficient count on large collections
        return new ArrayCollection($queryBuilder->getQuery()->execute()->toArray());
    }
875744
public function getByCriteria(CriteriaInterface $criteria)
    {
        if (!$this->allowedCache('getByCriteria') || $this->isSkippedCache()) {
            return parent::getByCriteria($criteria);
        }

        $key = $this->getCacheKey('getByCriteria', func_get_args());
        $minutes = $this->getCacheMinutes();
        $value = $this->getCacheRepository()->remember($key, $minutes, function () use ($criteria) {
            return parent::getByCriteria($criteria);
        });

        $this->resetModel();
        $this->resetScope();
        return $value;
    }
793789
@SuppressWarnings("unchecked")
	public final <T extends SolrDataQuery> T addCriteria(Criteria criteria) {

		Assert.notNull(criteria, "Cannot add null criteria.");

		if (this.criteria == null) {
			this.criteria = criteria;
		} else {
			if (this.criteria instanceof Crotch) {
				((Crotch) this.criteria).add(criteria);
			} else {
				Crotch tree = new Crotch();
				tree.add(this.criteria);
				tree.add(criteria);
				this.criteria = tree;
			}
		}
		return (T) this;
	}