Processes a single criterion.

@param Criterion $criterion
@param mixed $context The processing context
@return Criterion
15830
protected function processCriterion(Criterion $criterion, $context): Criterion
    {
        if ($criterion instanceof ValueCriterion) {
            $column = $this->processColumnOrSubQuery($criterion->column, $context);
            $value = $this->processValueOrSubQuery($criterion->value, $context);

            if ($column === $criterion->column && $value === $criterion->value) {
                return $criterion;
            } else {
                return new ValueCriterion($column, $criterion->rule, $value, $criterion->appendRule);
            }
        }

        if ($criterion instanceof ColumnsCriterion) {
            $column1 = $this->processColumnOrSubQuery($criterion->column1, $context);
            $column2 = $this->processColumnOrSubQuery($criterion->column2, $context);

            if ($column1 === $criterion->column1 && $column2 === $criterion->column2) {
                return $criterion;
            } else {
                return new ColumnsCriterion($column1, $criterion->rule, $column2, $criterion->appendRule);
            }
        }

        if ($criterion instanceof BetweenCriterion) {
            $column = $this->processColumnOrSubQuery($criterion->column, $context);
            $min = $this->processValueOrSubQuery($criterion->min, $context);
            $max = $this->processValueOrSubQuery($criterion->max, $context);

            if ($column === $criterion->column && $min === $criterion->min && $max === $criterion->max) {
                return $criterion;
            } else {
                return new BetweenCriterion($column, $min, $max, $criterion->not, $criterion->appendRule);
            }
        }

        if ($criterion instanceof CriteriaCriterion) {
            $criteria = [];
            foreach ($criterion->criteria as $index => $subCriterion) {
                $criteria[$index] = $this->processCriterion($subCriterion, $context);
            }

            if ($criteria === $criterion->criteria) {
                return $criterion;
            } else {
                return new CriteriaCriterion($criteria, $criterion->not, $criterion->appendRule);
            }
        }

        if ($criterion instanceof ExistsCriterion) {
            $subQuery = $this->processSubQuery($criterion->subQuery, $context);

            if ($subQuery === $criterion->subQuery) {
                return $criterion;
            } else {
                return new ExistsCriterion($subQuery, $criterion->not, $criterion->appendRule);
            }
        }

        if ($criterion instanceof InCriterion) {
            $column = $this->processColumnOrSubQuery($criterion->column, $context);
            if (is_array($criterion->values)) {
                $values = [];
                foreach ($criterion->values as $index => $value) {
                    $values[$index] = $this->processValueOrSubQuery($value, $context);
                }
            } else {
                $values = $this->processSubQuery($criterion->values, $context);
            }

            if ($column === $criterion->column && $values === $criterion->values) {
                return $criterion;
            } else {
                return new InCriterion($column, $values, $criterion->not, $criterion->appendRule);
            }
        }

        if ($criterion instanceof NullCriterion) {
            $column = $this->processColumnOrSubQuery($criterion->column, $context);

            if ($column === $criterion->column) {
                return $criterion;
            } else {
                return new NullCriterion($column, $criterion->isNull, $criterion->appendRule);
            }
        }

        return $criterion;
    }
437324
public function addOr(Criterion $criterion)
    {
        $this->clauses[] = $criterion;
        $this->conjunctions[] = self::ODER;

        return $this;
    }
1021846
public function addAnd(Criterion $criterion)
    {
        $this->clauses[] = $criterion;
        $this->conjunctions[] = self::UND;

        return $this;
    }
439686
public function filterBy($column, $value, $comparison = Comparison::EQUAL, $outerMode = Link::LINK_DEFAULT)
    {
        return $this->addCriterion(new Criterion($column, $value, $comparison), null, $outerMode);
    }
575554
protected function processBetweenFilter(Criteria $criteria, $field, $value)
    {
        if (is_array($value) && isset($value['start']) && isset($value['end'])) {

            $criteria->andWhere($criteria->expr()->andX(
                $criteria->expr()->gte($field, $value['start']),
                $criteria->expr()->lt($field, $value['end'])
            ));

        }

        return $this;
    }
187773
public function process($object = null)
    {
        if ($object === null) {
            $object = new Criteria();
        }

        return parent::process($object);
    }
241693
public function matching(Criteria $criteria)
    {
        $persister = $this->em->getUnitOfWork()->getEntityPersister($this->entityName);

        return new LazyCriteriaCollection($persister, $criteria);
    }
149864
public static function count($criteria = array())
    {
        self::processCriteriaWithType($criteria);
        $count = self::connection()->count(self::collectionName(), $criteria);
        return $count;
    }
109413
public function canVisit(Criterion $criterion)
    {
        return
            $criterion instanceof Criterion\LocationId &&
            (
                ($criterion->operator ?: Operator::IN) === Operator::IN ||
                $criterion->operator === Operator::EQ
            );
    }
814590
protected function serializeCriteria()
    {
        try {
            return serialize($this->getCriteria());
        } catch (Exception $e) {
            return serialize($this->getCriteria()->map(function ($criterion) {
                return $this->serializeCriterion($criterion);
            }));
        }
    }
417564
public function canVisit(Criterion $criterion)
    {
        return
            $criterion instanceof Criterion\SectionId &&
            (
                ($criterion->operator ?: Operator::IN) === Operator::IN ||
                $criterion->operator === Operator::EQ
            );
    }
932662
public function addCriteria(Criteria $criteria) : void
    {
        if (! $this->isValidFilter($criteria->getOperator())) {
            throw new \RuntimeException(sprintf('Invalid filter provided: %s', $criteria->getOperator()));
        }

        $this->criteria[] = $criteria;
    }
1172138
private function bracketCriteria(array &$criteria, string $bracket = self::BRACKET_OPEN, string $connector = self::LOGICAL_AND): self
    {
        $criteria[] = [
            'bracket'   => $bracket,
            'connector' => $connector,
        ];

        return $this;
    }
1229984
public function matching(Criteria $criteria)
    {
        $persister = $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName);

        return new LazyCriteriaCollection($persister, $criteria);
    }
41556
public function outerJoin($table, ...$criterion): self
    {
        $this->join[] = $this->joinArgumentsToJoinObject('OUTER', $table, $criterion);
        return $this;
    }
343627
protected function getTotalCount(Criterion $criterion, array $languageFilter)
    {
        $query = $this->handler->createSelectQuery();
        $query
            ->select($query->alias($query->expr->count('*'), 'count'))
            ->from($this->handler->quoteTable('ezcontentobject_tree'))
            ->innerJoin(
                'ezcontentobject',
                'ezcontentobject_tree.contentobject_id',
                'ezcontentobject.id'
            )
            ->innerJoin(
                'ezcontentobject_version',
                'ezcontentobject.id',
                'ezcontentobject_version.contentobject_id'
            );

        $query->where(
            $this->criteriaConverter->convertCriteria($query, $criterion, $languageFilter),
            $query->expr->eq(
                'ezcontentobject.status',
                //ContentInfo::STATUS_PUBLISHED
                $query->bindValue(1, null, PDO::PARAM_INT)
            ),
            $query->expr->eq(
                'ezcontentobject_version.status',
                //VersionInfo::STATUS_PUBLISHED
                $query->bindValue(1, null, PDO::PARAM_INT)
            ),
            $query->expr->neq(
                $this->handler->quoteColumn('depth', 'ezcontentobject_tree'),
                $query->bindValue(0, null, PDO::PARAM_INT)
            )
        );

        // If not main-languages query
        if (!empty($languageFilter['languages'])) {
            $query->where(
                $query->expr->gt(
                    $query->expr->bitAnd(
                        $this->handler->quoteColumn('language_mask', 'ezcontentobject'),
                        $query->bindValue(
                            $this->getLanguageMask($languageFilter),
                            null,
                            PDO::PARAM_INT
                        )
                    ),
                    $query->bindValue(0, null, PDO::PARAM_INT)
                )
            );
        }

        $statement = $query->prepare();
        $statement->execute();

        return (int)$statement->fetchColumn();
    }
275767
public function check(Criteria $criteria, Message $message)
    {
        foreach ($criteria as $criterium) {
            if ($criterium instanceof Criteria) {
                if (!$this->check($criterium, $message)) {
                    return false;
                }

                return true;
            } elseif (!$criterium instanceof Criterium) {
                throw new InvalidArgumentException('Criterium is neither of type Criterium nor Criteria. Type is '.gettype($criterium));
            }

            $type = $criterium->getType();
            $value = $criterium->getValue();

            if (!strlen($value)) {
                continue;
            }

            switch ($type) {
                case Criteria::CRITERIUM_SUBJECT_LIKE:
                    if (stristr($message->getSubject(), $value) === false) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_SUBJECT_NOT_LIKE:
                    if (stristr($message->getSubject(), $value) !== false) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_BODY_LIKE:
                    if (stristr($message->getBody(), $value) === false) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_BODY_NOT_LIKE:
                    if (stristr($message->getBody(), $value) !== false) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_PRIORITY_IS:
                    if ($message->getPriority() !== $value) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_PRIORITY_MIN:
                    if ($message->getPriority() < $value) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_PRIORITY_IN:
                    if (!in_array($message->getPriority(), $value)) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_TYPE_IS:
                    if ($message->getType() !== $value) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_TYPE_IN:
                    if (!in_array($message->getType(), $value)) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_CHANNEL_IS:
                    if ($message->getChannel() !== $value) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_CHANNEL_LIKE:
                    if (stristr($message->getChannel(), $value) === false) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_CHANNEL_IN:
                    if (!in_array($message->getChannel(), $value)) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_ROLE_IS:
                    if ($message->getRole() !== $value) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_ROLE_IN:
                    if (!in_array($message->getRole(), $value)) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_MAX_AGE:
                    if ($message->getCreatedAt()->format('U') < (time() - ($value * 24 * 60 * 60))) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_MIN_AGE:
                    if ($message->getCreatedAt()->format('U') > (time() - ($value * 24 * 60 * 60))) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_START_DATE:
                    if ($message->getCreatedAt()->format('U') < strtotime($value)) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_END_DATE:
                    if ($message->getCreatedAt()->format('U') > strtotime($value)) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_DATE_IS:
                    if ($message->getCreatedAt()->format('Y-m-d') !== date('Y-m-d', strtotime($value))) {
                        continue 2;
                    }
                    break;

                default:
                    continue 2;
                    break;
            }

            return true;
        }

        return false;
    }