Get ModelCondition or subclass from a condition that can be string or array
or another condition object, in wich case it will return that object;
@param mixed $condition The original condition
@return static
557770
public static function getFrom($condition, $model) {
        if (is_a($condition, '\\mpf\datasources\\sql\\ModelCondition')) {
            $condition->model = $model;
            return $condition;
        }
        if (is_array($condition) && count($condition))
            $cond = new static($condition);
        else {
            $cond = new static;
            if ($condition)
                $cond->addCondition($condition);
        }
        $cond->model = $model;
        return $cond;
    }
1051488
public static function findAll($condition = '1=1', $params = array())
    {
        /* @var $condition \mpf\datasources\sql\ModelCondition */
        if (!is_a($condition, '\\mpf\\datasources\\sql\\ModelCondition')) {
            $condition = ModelCondition::getFrom($condition, get_called_class());
        } else {
            $condition->model = $condition->model ? $condition->model : get_called_class();
        }
        $condition->setParams($params);
        $searchedRelations = [];
        if (is_array($condition->with)) {
            foreach ($condition->with as $k) {
                $searchedRelations[$k] = $k;
            }
        }
        $models = static::getDb()->queryClass($condition, get_called_class(), $condition->getParams(), [
            [
                '_columns' => static::getDb()->getTableColumns(static::getTableName()),
                '_pk' => static::getDb()->getTablePk(static::getTableName()),
                '_isNewRecord' => false,
                '_action' => 'update',
                '_tableName' => static::getTableName(),
                '_db' => static::getDb(),
                '_searchedRelations' => $searchedRelations
            ]
        ]);
        if (!$models) {
            return [];
        }
        $condition->getExtraRelations($models);
        return $models;
    }
795126
protected function joinCondition(array $condition): string
	{
		return $this->column($condition['column1']) . ' ' . $condition['operator'] . ' ' . $this->column($condition['column2']);
	}
43297
private function getFilter($keyCondition)
    {
        $filter     = clone $this->expr->condition;
        $conditions = $keyCondition instanceof Composite ?
            $keyCondition->getParts() : [$keyCondition];

        foreach ($conditions as $condition) {
            $filter->remove($condition);
        }

        return $filter;
    }
305772
public function buildHashCondition($condition)
    {
        $result = [];
        foreach ($condition as $name => $value) {
            if (strncmp('$', $name, 1) === 0) {
                // Native Mongo condition:
                $result[$name] = $value;
            } else {
                if (is_array($value)) {
                    if (ArrayHelper::isIndexed($value)) {
                        // Quick IN condition:
                        $result = array_merge($result, $this->buildInCondition('IN', [$name, $value]));
                    } else {
                        // Mongo complex condition:
                        $result[$name] = $value;
                    }
                } else {
                    // Direct match:
                    if ($name == '_id') {
                        $value = $this->ensureMongoId($value);
                    }
                    $result[$name] = $value;
                }
            }
        }

        return $result;
    }
44494
protected function parseCondition($condition)
    {
        $tableAlias = $this->getAlias();
        $parts = [];

        if ($condition instanceof QueryBuilderAwareInterface) {
            $condition->setQueryBuilder($this);
        }

        if ($condition instanceof Expression) {
            $parts[] = $this->getAdapter()->quoteSql($condition->toSQL());
        } elseif ($condition instanceof Q) {
            $condition->setLookupBuilder($this->getLookupBuilder());
            $condition->setAdapter($this->getAdapter());
            $condition->setTableAlias($tableAlias);
            $parts[] = $condition->toSQL();
        } elseif ($condition instanceof ToSqlInterface) {
            $parts[] = $condition->toSQL();
        } elseif (is_array($condition)) {
            foreach ($condition as $key => $value) {
                if ($value instanceof Q) {
                    $parts[] = $this->parseCondition($value);
                } else {
                    list($lookup, $column, $lookupValue) = $this->lookupBuilder->parseLookup($this, $key, $value);
                    $column = $this->getLookupBuilder()->fetchColumnName($column);
                    if (false === empty($tableAlias) && false === strpos($column, '.')) {
                        $column = $tableAlias.'.'.$column;
                    }
                    $parts[] = $this->lookupBuilder->runLookup($this->getAdapter(), $lookup, $column, $lookupValue);
                }
            }
        } elseif (is_string($condition)) {
            $parts[] = $condition;
        } elseif ($condition instanceof Expression) {
            $parts[] = $condition->toSQL();
        }

        if (1 === count($parts)) {
            return $parts[0];
        }

        return '('.implode(') AND (', $parts).')';
    }
328533
protected function validateCondition($condition)
    {
        $condition = trim(strtolower($condition));

        if ($condition !== 'and' && $condition !== 'or') {
            throw new QBParseException("Condition can only be one of: 'and', 'or'.");
        }

        return $condition;
    }
1284719
public function deserialize(array $condition)
    {
        $this->assertHasKey('name', $condition);
        $this->assertHasKey('key', $condition);
        $this->assertHasKey('operator', $condition);

        if ($condition['name'] !== 'operator-condition') {
            throw new RuntimeException(sprintf('Unable to deserialize operator with name "%s".', $condition['name']));
        }

        $operator = $this->operatorSerializer->deserialize($condition['operator']);

        return new OperatorCondition($condition['key'], $operator);
    }
465685
public static function generateKey($condition)
    {
        if(is_string($condition))
        {
            return $condition;
        }
        else
        {
            $rule = ModelManager::getKeyRule(static::class);
            $result = $rule->rule;
            foreach($rule->paramNames as $paramName)
            {
                if(!isset($condition[$paramName]))
                {
                    throw new \Exception(sprintf('GenerateKey param %s does not exists', $paramName));
                }
                $result = str_replace('{' . $paramName . '}', $condition[$paramName], $result);
            }
            return $result;
        }
    }
1305647
public function where( $condition ) {
		if ( ! $condition instanceof ConditionInterface ) {
			$condition = func_get_args();
		}

		$condition = $this->router->mergeConditionAttribute(
			$this->getAttribute( 'condition' ),
			$condition
		);

		return $this->attribute( 'condition', $condition );
	}
404598
public function clause($condition = 'AND')
    {
        if (empty($this->where)) {
            $condition = null;
        }
        $clause = new AnDomainQueryClause($this, $condition);

        return $clause;
    }
8536
public function join($condition, string $expression = null): object
    {
        if (!is_array($condition)) {
            $condition = [$condition => $expression];
        }
        $this->container[$this->id]['s']['join'] = array_merge($this->container[$this->id]['s']['join'], $condition);
        return $this;
    }
1122981
protected static function evaluateCondition($condition)
    {
        if (is_string($condition)) {
            // Should be extended for functions, extensions???
            return self::safeClassExists($condition);
        }
        if (is_callable($condition)) {
            return (bool) $condition();
        }
        if (is_bool($condition)) {
            return $condition;
        }
        if (is_array($condition)) {
            foreach ($condition as $c) {
                if (false === static::evaluateCondition($c)) {
                    // Immediately stop execution if the condition is false
                    return false;
                }
            }

            return true;
        }

        return false;
    }
365594
public function parent($condition = null)
    {
        // Up one level
        if (null === $condition) {
            array_pop($this->paths);
        } elseif (is_int($condition)) {
            // Up mutiple level
            $this->paths = array_slice($this->paths, 0, -$condition);
        } elseif (is_string($condition)) {
            // Find a dir name and go to this level
            $paths = $this->paths;

            $paths = array_reverse($paths);

            // Find parent
            $n = 0;

            foreach ($paths as $key => $name) {
                if ($key == 0) {
                    // Ignore latest dir
                    continue;
                }

                // Is this dir match condition?
                if ($name == $condition) {
                    $n = $key;
                    break;
                }
            }

            $this->paths = array_slice($this->paths, 0, -$n);
        }

        return $this;
    }
484391
public function where($condition)
    {
        $this->where = ! $this->where ? $condition : $this->where . ' AND ' . $condition;

        return $this;
    }
911251
private function cleanCondition($condition)
    {
        if (is_array($condition)) {
            $condition = array_filter($condition);
            if (empty($condition)) {
                $condition = null;
            }
        }

        return $condition;
    }
486330
public static function deleteAll($condition, $params = array())
    {
        if (!is_a($condition, '\\mpf\\datasources\\sql\\ModelCondition')) {
            $condition = ModelCondition::getFrom($condition, get_called_class());
        }
        /* @var $condition ModelCondition */
        $condition->setParams($params);
        return static::getDb()->execQuery($condition->forDelete(), $condition->getParams());
    }