Parses query criteria into a query string

@param   array   $criteria
@return  string
168619
private function parseCriteria(array $criteria)
    {
        $out = '';
        if (!empty($criteria)) {
            $conditions = [];
            foreach ($criteria as $field => $value) {
                if (is_array($value)) {
                    $values = array_map(function($value) { return $this->connection->quote($value); }, $value);
                    $conditions[] = sprintf('%s IN (%s)', $field, implode(', ', $values));
                } else {
                    $operator = '=';
                    $ops = ['<>', '<', '>', '<=', '>='];
                    foreach ($ops as $op) {
                        if (false !== strpos($value, $op)) {
                            $operator = $op;
                            $value = str_replace(sprintf('%s ', $op), '', $value);
                            break;
                        }
                    }
                    $conditions[] = sprintf('%s %s %s', $field, $operator, $this->connection->quote($value));
                }
            }
            $out = sprintf(' WHERE %s', implode(' AND ', $conditions));
        }
        return $out;
    }
344631
public function findOneBy(array $criteria) : ?array
    {
        foreach ($this->getSourceRows() as $row) {
            if ($this->matches($criteria, $row)) {
                return $row;
            }
        }

        return null;
    }
22899
private function GetWhereSQL($criteria)
	{
		$ands = $criteria->GetAnds();
		$ors = $criteria->GetOrs();
		
		// TODO: this all needs to move to the criteria object so it will recurse properly  ....
		$where = $this->RemoveWherePrefix($criteria->GetWhere());
		
		if (count($ands))
		{
			$wdelim = ($where) ? " and " : "";
			foreach($ands as $c)
			{
				$tmp = $c->GetWhere();
				$buff = $this->RemoveWherePrefix($tmp);
				if ($buff)
				{
					$where .= $wdelim . $buff;
					$wdelim = " and ";
				}
			}
		}
		
		if (count($ors))
		{
			$where = trim($where) ? "(" . $where . ")" : ""; // no primary criteria.  kinda strange
			$wdelim = $where ? " or " : "";
				
			foreach($ors as $c)
			{
				$tmp = $c->GetWhere();
				$buff = $this->RemoveWherePrefix($tmp);
				if ($buff)
				{
					$where .= $wdelim . "(" . $buff . ")";
					$wdelim = " or ";
				}
			}
		}
		
		// .. end of stuff that should be in criteria	

		// prepend the "where" onto the statement
		if ($where) $where = " where (" . trim($where) . ") ";
		
		return $where;
	}
42104
protected function getSelectConditionCriteriaSQL(Criteria $criteria)
    {
        $expression = $criteria->getWhereExpression();

        if ($expression === null) {
            return '';
        }

        $visitor = new SqlExpressionVisitor($this, $this->class);

        return $visitor->dispatch($expression);
    }
1291945
private function filterHasEncryptedField(array $criteria)
    {
        $result = false;

        if (!empty($criteria)) {
            $encryptedFields = array_keys($this->getEncryptedFields());
            $criteriaFields = array_keys($criteria);
            $commonFields = array_intersect($encryptedFields, $criteriaFields);

            $result = !empty($commonFields);
        }

        return $result;
    }
1246482
public function scanLocations(array $criteria)
    {
        $uris = $this->locations->map(function ($location) use ($criteria) {
            /** @var Location $location */
            return $location->getURI($criteria);
        })->filter(function ($uri) {
            return false !== $uri;
        });
        
        // Fall back for absolute paths on current filesystem.
        if ($uris->isEmpty()) {
            foreach ($criteria as $criterion) {
                if (file_exists($criterion)) {
                    return $criterion;
                }
            }
        }

        return $uris->isEmpty() ? false : $uris->first();
    }
859764
@Deprecated
    public static Criteria parse(String criteria) {
        if(criteria == null){
            throw new InvalidPathException("Criteria can not be null");
        }
        String[] split = criteria.trim().split(" ");
        if(split.length == 3){
            return create(split[0], split[1], split[2]);
        } else if(split.length == 1){
            return create(split[0], "EXISTS", "true");
        } else {
            throw new InvalidPathException("Could not parse criteria");
        }
    }
965685
public static function countByRequest(array $criteria = [])
    {
        if (!empty($condition = array_get($criteria, 'condition'))) {
            $params = array_get($criteria, 'params', []);

            return static::whereRaw($condition, $params)->count();
        }

        return static::count();
    }
414114
private static function getPrimaryKey(Criteria $criteria)
    {
        // Assume all the keys are for the same table.
        $keys = $criteria->keys();
        $key = $keys[0];
        $table = $criteria->getTableName($key);

        $pk = null;

        if (!empty($table)) {

            $dbMap = Propel::getDatabaseMap($criteria->getDbName());

            $pks = $dbMap->getTable($table)->getPrimaryKeys();
            if (!empty($pks)) {
                $pk = array_shift($pks);
            }
        }

        return $pk;
    }
876583
protected function getQueryBuilder(Criteria $criteria)
    {
        /** @var QueryBuilder $queryBuilder */
        $queryBuilder = $this->getRepository()->createQueryBuilder('e');
        $queryBuilder->addCriteria($criteria);

        return $queryBuilder;
    }
1060786
public function get($criteria)
    {
        foreach (array_merge($this->assemblers, $this->fallbackAssemblers) as $candidate) {
            $matcher = $candidate['matcher'];
            if ($matcher($criteria) === true) {
                return $candidate['assembler'];
            }
        }

        return null;
    }
984094
public function searchEntities(CriteriaBase $criteria)
    {
        $this->throttler->throttle();
        $query = $criteria ? get_object_vars($criteria) : array();

        $entityName = $criteria->getEntityName();

        $url = $this->_buildURL($criteria->getEntityListName(), $query);
        $response = $this->client->get($url)->send();
        //check exception in response
        $this->checkException($response);



        $entityXMLItems = $response->xml()->{$entityName . 'List'}->{$entityName};
        if(!$entityXMLItems){
            $entityXMLItems = $response->xml()->{$entityName . 'List'}->{$entityName. 'ListItem'};
        }

        $res = array();

        /**
         * @var \Dlin\Saasu\Entity\EntityBase $entity
         */
        foreach ($entityXMLItems as $item) {
            $fullClass = $criteria->getEntityClass();
            $entity = new $fullClass();
            $entity->fromXML($item->asXML());
            $res[] = $entity;
        }
        return $res;

    }
1130312
public function seeUserInDatabase(array $criteria)
    {
        $tableName = $this->grabPrefixedTableNameFor('users');
        $allCriteria = $criteria;
        if (!empty($criteria['user_pass'])) {
            $userPass = $criteria['user_pass'];
            unset($criteria['user_pass']);
            $hashedPass = $this->grabFromDatabase($tableName, 'user_pass', $criteria);
            $passwordOk = WpPassword::instance()->check($userPass, $hashedPass);
            $this->assertTrue(
                $passwordOk,
                'No matching records found for criteria ' . json_encode($allCriteria) . ' in table ' . $tableName
            );
        }
        $this->seeInDatabase($tableName, $criteria);
    }
23859
public function findOneBy(array $criteria) : ?array
    {
        foreach ($this->objects as $object) {
            $matches = true;

            foreach ($criteria as $key => $value) {
                if ($object[$key] === $value) {
                    continue;
                }

                $matches = false;
            }

            if ($matches) {
                return $object;
            }
        }

        return null;
    }
1364667
public function dump(Criteria $criteria)
    {
        $mode = strtoupper($criteria->getMode());

        $parts = array();
        foreach ($criteria as $criterium) {
            if ($criterium instanceof Criteria) {
                $parts[] = $this->dump($criterium, 1);
            } elseif ($criterium instanceof Criterium) {
                $type = $criterium->getType();
                $value = $criterium->getValue();
                if ($value instanceof \DateTime) {
                    $parts[] = $type.' = "'.$value->format('Y-m-d H:i:s').'"';
                } else {
                    $parts[] = $type.' = "'.$value.'"';
                }
            }
        }

        return '('.implode(' '.$mode.' ', $parts).')';
    }
1282964
public function getPlainSelectedColumns(Criteria $criteria)
    {
        $selected = [];
        foreach ($criteria->getSelectColumns() as $columnName) {
            if (false === strpos($columnName, '(')) {
                $selected[] = $columnName;
            }
        }

        foreach ($criteria->getAsColumns() as $alias => $col) {
            if (false === strpos($col, '(') && !in_array($col, $selected)) {
                $selected[] = $col;
            }
        }

        return $selected;
    }
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);
    }