Parse Criteria

@return ParsedCriteria
184336
function parse()
    {
        $criteria        = $this->criteria;
        $expectAsLiteral = $this->expectAsLiteral;


        $TOKENS  = preg_quote(static::TOKENS);

        $expectAsLiteral = (empty($expectAsLiteral)) ? '/@+-.' : $expectAsLiteral;
        $LITERAL = preg_quote($expectAsLiteral).'A-Za-z0-9_';


        $currentPos = 0;
        $length     = strlen($criteria);
        $parts      = [];
        $levelParts = [&$parts];
        $level      = 0;

        while ($currentPos < $length)
        {
            preg_match("(\G(?P<_literal_>[$LITERAL]*)(?P<_token_>[$TOKENS]|$))"
                , $criteria
                , $matches
                , 0
                , $currentPos
            );

            if ( empty($matches) )
                break;

            if (! empty($matches['_literal_']) ) {
                $levelParts[$level][] = ['_literal_' => $matches['_literal_']];
                $currentPos += strlen($matches['_literal_']);
            }

            # Deal With Token:
            if ( !isset($matches['_token_']) || $matches['_token_'] == '' )
                continue;

            $currentPos += strlen($matches['_token_']);
            $Token = $matches['_token_'];

            ## Regular Expression Token
            #
            #
            if ($Token === '~') {
                // ^ match any character that is not in list
                $pmatch = preg_match("/~(?P<_delimiter_>[^~]+)~/"
                    , $criteria
                    , $matches
                    , 0
                    , 0
                );
                if (! $pmatch )
                    throw new \RuntimeException('Miss usage of ~ ~ token.');

                $val['_regex_'] = $matches['_delimiter_'];
                $levelParts[$level][] = $val;

                $currentPos += strlen($matches[0])+2/*~x~*/;
            }
            ##
            # Variable
            # /:hash_id~\w{24}~
            #
            elseif ($Token === ':') {
                // ^$TOKENS  match any character that is not in list
                $pmatch = preg_match("(\G(?P<_name_>[^$TOKENS]+)(?:~(?P<_delimiter_>[^~]+)~)?:?)"
                    , $criteria
                    , $matches
                    , 0
                    , $currentPos
                );

                if (! $pmatch && !(isset($matches['_name_']) && isset($matches['_delimiter_'])) )
                    throw new \RuntimeException(
                        'Found empty parameter name or delimiter on (%s).'
                        , $criteria
                    );

                $parameter = $matches['_name_'];
                $val       = ['_parameter_' => $parameter];
                if (isset($matches['_delimiter_']))
                    $val[$parameter] = $matches['_delimiter_'];

                $levelParts[$level][] = $val;
                $currentPos += strlen($matches[0]);
            }

            ## Literal Token
            #  localhost\:port
            #
            elseif ($Token === '\\') {
                // Consider next character as Literal
                $nextChar = $currentPos += 1;
                $levelParts[$level][]   = ['_literal_' => $criteria[$nextChar]];
            }

            ## Optional Part
            #  /<u/:username~[a-zA-Z0-9._]+~><-:userid~\w{24}~>
            #
            elseif ($Token === '<') {
                if (! isset($va) ) {
                    $va = [];
                    $n = 0;
                }

                $n++;
                $va[$n] = [];
                $levelParts[$level][] = ['_optional_' => &$va[$n]];
                $level++;
                $levelParts[$level] = &$va[$n];
            }
            ## Close Optional ##
            elseif ($Token === '>') {
                unset($levelParts[$level]);
                $level--;

                if ($level < 0)
                    throw new \RuntimeException('Found closing bracket without matching opening bracket');
            }

            else
                // Recognized unused token return immanently
                $levelParts[$level][]   = ['_token_' => $Token];

        } // end while

        if ($level > 0)
            throw new \RuntimeException('Found unbalanced brackets');


        return ParsedCriteria::of($parts);
    }
441338
public function buildCriteria()
    {
        $criteria = new Criteria(PersonFunctionLinkTableMap::DATABASE_NAME);

        if ($this->isColumnModified(PersonFunctionLinkTableMap::ID)) $criteria->add(PersonFunctionLinkTableMap::ID, $this->id);
        if ($this->isColumnModified(PersonFunctionLinkTableMap::PERSON_ID)) $criteria->add(PersonFunctionLinkTableMap::PERSON_ID, $this->person_id);
        if ($this->isColumnModified(PersonFunctionLinkTableMap::FUNCTION_ID)) $criteria->add(PersonFunctionLinkTableMap::FUNCTION_ID, $this->function_id);
        if ($this->isColumnModified(PersonFunctionLinkTableMap::CREATED_AT)) $criteria->add(PersonFunctionLinkTableMap::CREATED_AT, $this->created_at);
        if ($this->isColumnModified(PersonFunctionLinkTableMap::UPDATED_AT)) $criteria->add(PersonFunctionLinkTableMap::UPDATED_AT, $this->updated_at);

        return $criteria;
    }
944489
protected function parseIncludes()
	{
		$includes = ['this' => [], 'forward' => []];

		foreach($this->model->getIncludes() as $include => $criteria)
		{
			if(is_numeric($include))
			{
				$include  = $criteria;
				$criteria = null;
			}

			if(($position = strpos($include, '.')) === false)
			{
				$includes['this'][$include] = $criteria;
			}
			else
			{
				if($criteria === null)
				{
					$includes['forward'][substr($include, 0, $position)][] = substr($include, $position + 1);
				}
				else
				{
					$includes['forward'][substr($include, 0, $position)][substr($include, $position + 1)] = $criteria;
				}
			}
		}

		return $includes;
	}
40927
public function parse()
    {
        $where = [];

        foreach ($this->where as $key => $val) {
            if ($val instanceof Expression) {
                $where[] = [$key, 'exp', $val];
            } elseif (is_null($val)) {
                $where[] = [$key, 'NULL', ''];
            } elseif (is_array($val)) {
                $where[] = $this->parseItem($key, $val);
            } else {
                $where[] = [$key, '=', $val];
            }
        }

        return $this->enclose ? [$where] : $where;
    }
208223
public function buildCriteria()
    {
        $criteria = new Criteria(GroupTableMap::DATABASE_NAME);

        if ($this->isColumnModified(GroupTableMap::COL_ID)) {
            $criteria->add(GroupTableMap::COL_ID, $this->id);
        }
        if ($this->isColumnModified(GroupTableMap::COL_TITLE)) {
            $criteria->add(GroupTableMap::COL_TITLE, $this->title);
        }
        if ($this->isColumnModified(GroupTableMap::COL_DESCRIPTION)) {
            $criteria->add(GroupTableMap::COL_DESCRIPTION, $this->description);
        }
        if ($this->isColumnModified(GroupTableMap::COL_SLUG)) {
            $criteria->add(GroupTableMap::COL_SLUG, $this->slug);
        }
        if ($this->isColumnModified(GroupTableMap::COL_SPORT_ID)) {
            $criteria->add(GroupTableMap::COL_SPORT_ID, $this->sport_id);
        }
        if ($this->isColumnModified(GroupTableMap::COL_SKILL_COUNT)) {
            $criteria->add(GroupTableMap::COL_SKILL_COUNT, $this->skill_count);
        }

        return $criteria;
    }
575608
@Override
    @SuppressWarnings("unchecked")
    public Criteria[] parseValue(String value) {
        EnumCriteria result = new EnumCriteria(this.name, this.columnName, this.enumClass);
        result.value = Enum.valueOf(enumClass, value);
        return new Criteria[] {result};
    }
220835
public function buildCriteria()
    {
        $criteria = new Criteria(PageTableMap::DATABASE_NAME);

        if ($this->isColumnModified(PageTableMap::COL_ID)) {
            $criteria->add(PageTableMap::COL_ID, $this->id);
        }
        if ($this->isColumnModified(PageTableMap::COL_SOURCE_ID)) {
            $criteria->add(PageTableMap::COL_SOURCE_ID, $this->source_id);
        }
        if ($this->isColumnModified(PageTableMap::COL_PAGEID)) {
            $criteria->add(PageTableMap::COL_PAGEID, $this->pageid);
        }
        if ($this->isColumnModified(PageTableMap::COL_TITLE)) {
            $criteria->add(PageTableMap::COL_TITLE, $this->title);
        }
        if ($this->isColumnModified(PageTableMap::COL_DISPLAYTITLE)) {
            $criteria->add(PageTableMap::COL_DISPLAYTITLE, $this->displaytitle);
        }
        if ($this->isColumnModified(PageTableMap::COL_PAGE_IMAGE_FREE)) {
            $criteria->add(PageTableMap::COL_PAGE_IMAGE_FREE, $this->page_image_free);
        }
        if ($this->isColumnModified(PageTableMap::COL_WIKIBASE_ITEM)) {
            $criteria->add(PageTableMap::COL_WIKIBASE_ITEM, $this->wikibase_item);
        }
        if ($this->isColumnModified(PageTableMap::COL_DISAMBIGUATION)) {
            $criteria->add(PageTableMap::COL_DISAMBIGUATION, $this->disambiguation);
        }
        if ($this->isColumnModified(PageTableMap::COL_DEFAULTSORT)) {
            $criteria->add(PageTableMap::COL_DEFAULTSORT, $this->defaultsort);
        }
        if ($this->isColumnModified(PageTableMap::COL_CREATED_AT)) {
            $criteria->add(PageTableMap::COL_CREATED_AT, $this->created_at);
        }
        if ($this->isColumnModified(PageTableMap::COL_UPDATED_AT)) {
            $criteria->add(PageTableMap::COL_UPDATED_AT, $this->updated_at);
        }

        return $criteria;
    }
292682
public function getQueryCriteria()
    {
        if (false === $this->isQuery()) {
            return [];
        }

        $queryKey = self::FILTER_QUERY;
        $criteriaKey = self::FILTER_QUERY_CRITERIA;

        $decoded = @json_decode($this->getFilter($queryKey)[$criteriaKey], true);
        if (!is_array($decoded)) {
            $param = sprintf('%s[%s][%s]', self::PARAM_FILTERING, $queryKey, $criteriaKey);
            throw RestException::invalidQueryParam($param, 'Was the value sent as valid JSON?');
        }
        return $decoded;
    }
814590
protected function serializeCriteria()
    {
        try {
            return serialize($this->getCriteria());
        } catch (Exception $e) {
            return serialize($this->getCriteria()->map(function ($criterion) {
                return $this->serializeCriterion($criterion);
            }));
        }
    }
126371
public function buildCriteria()
    {
        $criteria = new Criteria(PositionTableMap::DATABASE_NAME);

        if ($this->isColumnModified(PositionTableMap::COL_ID)) {
            $criteria->add(PositionTableMap::COL_ID, $this->id);
        }
        if ($this->isColumnModified(PositionTableMap::COL_TITLE)) {
            $criteria->add(PositionTableMap::COL_TITLE, $this->title);
        }
        if ($this->isColumnModified(PositionTableMap::COL_SLUG)) {
            $criteria->add(PositionTableMap::COL_SLUG, $this->slug);
        }
        if ($this->isColumnModified(PositionTableMap::COL_SPORT_ID)) {
            $criteria->add(PositionTableMap::COL_SPORT_ID, $this->sport_id);
        }
        if ($this->isColumnModified(PositionTableMap::COL_DESCRIPTION)) {
            $criteria->add(PositionTableMap::COL_DESCRIPTION, $this->description);
        }

        return $criteria;
    }
1353973
public function buildCriteria()
    {
        $criteria = new Criteria(PersonTableMap::DATABASE_NAME);

        if ($this->isColumnModified(PersonTableMap::ID)) $criteria->add(PersonTableMap::ID, $this->id);
        if ($this->isColumnModified(PersonTableMap::FIRST_NAME)) $criteria->add(PersonTableMap::FIRST_NAME, $this->first_name);
        if ($this->isColumnModified(PersonTableMap::LAST_NAME)) $criteria->add(PersonTableMap::LAST_NAME, $this->last_name);
        if ($this->isColumnModified(PersonTableMap::CREATED_AT)) $criteria->add(PersonTableMap::CREATED_AT, $this->created_at);
        if ($this->isColumnModified(PersonTableMap::UPDATED_AT)) $criteria->add(PersonTableMap::UPDATED_AT, $this->updated_at);

        return $criteria;
    }
877844
public function buildCriteria()
    {
        $criteria = new Criteria(SmartyFilterI18nTableMap::DATABASE_NAME);

        if ($this->isColumnModified(SmartyFilterI18nTableMap::ID)) {
            $criteria->add(SmartyFilterI18nTableMap::ID, $this->id);
        }
        if ($this->isColumnModified(SmartyFilterI18nTableMap::LOCALE)) {
            $criteria->add(SmartyFilterI18nTableMap::LOCALE, $this->locale);
        }
        if ($this->isColumnModified(SmartyFilterI18nTableMap::TITLE)) {
            $criteria->add(SmartyFilterI18nTableMap::TITLE, $this->title);
        }
        if ($this->isColumnModified(SmartyFilterI18nTableMap::DESCRIPTION)) {
            $criteria->add(SmartyFilterI18nTableMap::DESCRIPTION, $this->description);
        }

        return $criteria;
    }
60774
@Override
    public Criteria[] parseValue(String attribute) {
        PatternCriteria result = new PatternCriteria(this.name, this.columnName, this.condition);
        result.pattern = toSQLPattern(attribute);
        return new Criteria[] {result};
    }
774573
public function buildCriteria()
    {
        $criteria = new Criteria(ReferenceTableMap::DATABASE_NAME);

        if ($this->isColumnModified(ReferenceTableMap::COL_ID)) {
            $criteria->add(ReferenceTableMap::COL_ID, $this->id);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_TYPE)) {
            $criteria->add(ReferenceTableMap::COL_TYPE, $this->type);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_TITLE)) {
            $criteria->add(ReferenceTableMap::COL_TITLE, $this->title);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_YEAR)) {
            $criteria->add(ReferenceTableMap::COL_YEAR, $this->year);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_PUBLISHER)) {
            $criteria->add(ReferenceTableMap::COL_PUBLISHER, $this->publisher);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_JOURNAL)) {
            $criteria->add(ReferenceTableMap::COL_JOURNAL, $this->journal);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_NUMBER)) {
            $criteria->add(ReferenceTableMap::COL_NUMBER, $this->number);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_SCHOOL)) {
            $criteria->add(ReferenceTableMap::COL_SCHOOL, $this->school);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_AUTHOR)) {
            $criteria->add(ReferenceTableMap::COL_AUTHOR, $this->author);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_EDITION)) {
            $criteria->add(ReferenceTableMap::COL_EDITION, $this->edition);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_VOLUME)) {
            $criteria->add(ReferenceTableMap::COL_VOLUME, $this->volume);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_ADDRESS)) {
            $criteria->add(ReferenceTableMap::COL_ADDRESS, $this->address);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_EDITOR)) {
            $criteria->add(ReferenceTableMap::COL_EDITOR, $this->editor);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_HOWPUBLISHED)) {
            $criteria->add(ReferenceTableMap::COL_HOWPUBLISHED, $this->howpublished);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_NOTE)) {
            $criteria->add(ReferenceTableMap::COL_NOTE, $this->note);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_BOOKTITLE)) {
            $criteria->add(ReferenceTableMap::COL_BOOKTITLE, $this->booktitle);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_PAGES)) {
            $criteria->add(ReferenceTableMap::COL_PAGES, $this->pages);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_URL)) {
            $criteria->add(ReferenceTableMap::COL_URL, $this->url);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_LASTCHECKED)) {
            $criteria->add(ReferenceTableMap::COL_LASTCHECKED, $this->lastchecked);
        }
        if ($this->isColumnModified(ReferenceTableMap::COL_MANAGED)) {
            $criteria->add(ReferenceTableMap::COL_MANAGED, $this->managed);
        }

        return $criteria;
    }
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;
    }
984493
protected function getCriteriaToApply()
    {
        // get the standard criteria
        $criteriaToApply = $this->getCriteria();

        // overrule them with criteria to be applied once
        if ( ! $this->onceCriteria->isEmpty()) {

            foreach ($this->onceCriteria as $onceKey => $onceCriteria) {

                // if there is no key, we can only add the criteria
                if (is_numeric($onceKey)) {

                    $criteriaToApply->push($onceCriteria);
                    continue;
                }

                // if there is a key, override or remove
                // if Null, remove criteria
                if (empty($onceCriteria) || is_a($onceCriteria, NullCriteria::class)) {

                    $criteriaToApply->forget($onceKey);
                    continue;
                }

                // otherwise, overide the criteria
                $criteriaToApply->put($onceKey, $onceCriteria);
            }
        }

        return $criteriaToApply;
    }
120512
public function buildCriteria()
    {
        $criteria = new Criteria(FeatureTypeI18nTableMap::DATABASE_NAME);

        if ($this->isColumnModified(FeatureTypeI18nTableMap::ID)) $criteria->add(FeatureTypeI18nTableMap::ID, $this->id);
        if ($this->isColumnModified(FeatureTypeI18nTableMap::LOCALE)) $criteria->add(FeatureTypeI18nTableMap::LOCALE, $this->locale);
        if ($this->isColumnModified(FeatureTypeI18nTableMap::TITLE)) $criteria->add(FeatureTypeI18nTableMap::TITLE, $this->title);
        if ($this->isColumnModified(FeatureTypeI18nTableMap::DESCRIPTION)) $criteria->add(FeatureTypeI18nTableMap::DESCRIPTION, $this->description);

        return $criteria;
    }