Handle conditions.

@param string $conditions
@param string $context
@return array
760807
public function conditions($conditions, $context) {
		$path = null;
		if (isset($conditions['design'])) {
			$paths = ['design', 'view'];
			foreach ($paths as $element) {
				if (isset($conditions[$element])) {
					$path .= "_{$element}/{$conditions[$element]}/";
					unset($conditions[$element]);
				}
			}
		}
		if (isset($conditions['id'])) {
			$path = "{$conditions['id']}";
			unset($conditions['id']);
		}
		if (isset($conditions['path'])) {
			$path = "{$conditions['path']}";
			unset($conditions['path']);
		}
		return [$path, $conditions];
	}
327072
protected function loopThroughRules(array $rules, array $context = [], $condition = 'AND')
    {
        $result    = true;
        $condition = strtolower($condition);
        $this->validateCondition($condition);
        foreach ($rules as $rule) {
            $result = $this->evaluate($rule, $context);
            if ($result && $this->isNested($rule)) {
                $result = $this->loopThroughRules($rule->rules, $context, $condition);
            }
            // Conditions upon which we can stop evaluation.
            if ('and' == $condition && !$result) {
                break;
            } else {
                if ('or' == $condition && $result) {
                    break;
                }
            }
        }

        return $result;
    }
651689
public function proceed(Context $context)
    {
        $context = $this->route($context);
        $context = $this->resolve($context);
        $context = $this->guard($context);
        $context = $this->execute($context);
        $context = $this->render($context);

        return $context;
    }
440069
protected function _prepareQueryConditions(&$conditions) {
		if (empty($conditions) || !is_array($conditions)) {
			return;
		}

		$bindFields = $this->_getListFieldsUpdateQueryConditions();
		$newConditions = [];
		foreach ($conditions as $field => &$value) {
			if (ctype_digit((string)$field)) {
				$field = $value;
			}

			if (in_array($field, ['AND', 'OR', 'NOT']) && is_array($value)) {
				$this->_prepareQueryConditions($value);
				continue;
			}

			if (!is_string($field)) {
				continue;
			}

			foreach ($bindFields as $bindField => $bindFieldInfo) {
				$fieldName = $field;
				if (strpos($fieldName, ' ') !== false) {
					$fieldName = explode(' ', $fieldName, 2);
					$fieldName = array_shift($fieldName);
				}
				if ($fieldName !== $this->alias . '.' . $bindField) {
					continue;
				}

				unset($conditions[$field]);
				$field = str_replace($this->alias . '.' . $bindField, $bindFieldInfo['replace'], $field);
				if (!isset($bindFieldInfo['subQuery'])) {
					$newConditions[$field] = $value;
					continue;
				}

				$conditionsSubQuery = [$field => $value];
				$db = $this->getDataSource();
				$subQuery = $db->buildStatement(
					[
						'limit' => null,
						'offset' => null,
						'joins' => [],
						'conditions' => $conditionsSubQuery,
						'order' => null,
						'group' => null
					] + $bindFieldInfo['subQuery'],
					$this
				);
				$subQuery = 'Employee.id IN (' . $subQuery . ') ';
				$subQueryExpression = $db->expression($subQuery);

				$newConditions[] = $subQueryExpression;
			}
		}
		$conditions = array_merge($conditions, $newConditions);
	}
621543
private static function _getCondition($value, array $conditions)
    {
        if (empty($value) || empty($conditions)) {
            return false;
        }

        return current(array_intersect(array_keys($value), $conditions));
    }
1051143
public function getList($conditions = []) {
		$conditions += ['status' => 1];
		$res = $this->find('all', ['conditions' => $conditions, 'fields' => ['id', 'name']]);
		$ret = [];
		foreach ($res as $language) {
			$ret[$language['id']] = $language['name'];
		}
		return $ret;
	}
1250055
public function addContext(Context $context) {
    $contexts = $this->get('contextOut');
    $contexts[] = $context;
    $this->add('contextOut', $contexts);
  }
394683
final public function setConditions(array $conditions)
    {
        if ($this->hasRun) {
            throw new \RuntimeException("Cursor query has already run");
        }

        $this->conditions = $this->applyConditions($conditions);
    }
1011526
public function where($conditions, $values=null) {
		if(!$conditions)
			return $this;
		if($values !== null)
			$this->where[] = [$conditions => $values];
		else
			$this->where[] = $conditions;

		return $this;
	}
559373
public function push($handler, $condition = '*')
    {
        list($handler, $condition) = $this->resolveHandlerAndCondition($handler, $condition);

        if (!isset($this->handlers[$condition])) {
            $this->handlers[$condition] = [];
        }

        array_push($this->handlers[$condition], $handler);

        return $this->newClause($handler);
    }
289007
public function setConditions(array $conditions = [])
    {
        $this->conditions = $conditions;

        $this->condition = $this->parseCondition($this->uri());
        $this->conditionParams = $this->parseConditionParams($this->getAction());

        return $this;
    }
225614
public function evaluate(Context $context)
    {
        /** @var VariableOperand $left */
        /** @var VariableOperand $right */
        list($left, $right) = $this->getOperands();

        return $left->prepareValue($context)->getSet()->setContains($right->prepareValue($context)) === false;
    }
1140484
protected function makeConditions(array $conditions): ?\SplObjectStorage
    {
        if (empty($conditions)) {
            return null;
        }

        $storage = new \SplObjectStorage();
        foreach ($conditions as $condition => $options) {
            $condition = $this->config->resolveAlias($condition);

            if ($this->config->hasCondition($condition)) {
                $autowire = $this->config->getCondition($condition);
            } else {
                $autowire = new Autowire($condition);
            }

            $storage->attach($autowire->resolve($this->factory), $options);
        }

        return $storage;
    }
913307
private function parseCondition($condition, $parameters = [])
	{
		if (strpos($condition, ' ')) {
			$match = preg_match('~^
				(.+)\s                          ## identifier 
				(
					(?:\$\w+) |                 ## $mongoOperator
					(?:[A-Z]+(?:_[A-Z]+)*) |    ## NAMED_OPERATOR or 
					(?:[\<\>\!]?\=|\>|\<\>?)    ## logical operator
				)	
				(?:
					\s%(\w+(?:\[\])?) |         ## modifier or
					\s(.+)                      ## value
				)?$~xs', $condition, $cond);

			//['cond IN' => [...]], ['cond = %s' => 'param'], ['cond $gt' => 20]
			if (!empty($match)) {

				if (substr($cond[1], 0, 1) === $this->cmd) {
					throw new InvalidArgumentException("Field name cannot start with '{$this->cmd}'");
				}

				if ($parameters === [] && !isset($cond[4])) {
					throw new InvalidArgumentException("Missing value for item '{$cond[1]}'");
				}

				return $this->formatCondition($cond[1], trim($cond[2], $this->cmd), isset($cond[4]) ? $cond[4] : $parameters, isset($cond[3]) ? $cond[3] : NULL);
			}
		}

		if ($parameters === []) {
			throw new InvalidArgumentException("Missing value for item '{$condition}'");
		}

		if (is_array($parameters) && ($value = reset($parameters))) {

			//['$cond' => $param[]]
			if (substr($condition, 0, 1) === $this->cmd) {
				return [$condition => $this->parseDeepCondition($parameters, TRUE)];
			}
			//['cond' => ['param', ...]]
			if (substr($key = key($parameters), 0, 1) !== $this->cmd) {
				return $this->formatCondition($condition, 'IN', $parameters);
			}
			//['cond' => ['$param' => [...]]]
			if (is_array($value)) {
				return [$condition => [$key => $this->parseDeepCondition($value)]];
			}
		}

		// [cond => param]
		return [$condition => $parameters];
	}
176657
public function deleteAll($conditions)
    {
        $target = $this->getTarget();
        $expression = $target->query()
            ->where($this->getConditions())
            ->where($conditions)
            ->clause('where');

        return $target->deleteAll($expression);
    }
1190308
protected function processConditions()
    {
        $data = $this->getData();
        $conditions = $this->_conditions;
        $result = array_filter($data, function ($val) use ($conditions) {
            $res = false;
            foreach ($conditions as $cond) {
                $tmp = true;
                foreach ($cond as $rule) {
                    $function = self::$_rulesMap[$rule['condition']];
                    if (!is_callable($function)) {
                        if (!method_exists(Condition::class, $function)) {
                            throw new ConditionNotAllowedException("Exception: $function condition not allowed");
                        }
                        
                        $function = [Condition::class, $function];
                    }
                    
                    $value = $this->getFromNested($val, $rule['key']);
                    $return = $value instanceof ValueNotFound ? false :  call_user_func_array($function, [$value, $rule['value']]);
                    $tmp &= $return;
                }
                $res |= $tmp;
            }
            return $res;
        });

        return $result;
    }
103243
public function find($conditions)
    {
        $conditions[$this->_property] = $this->_root;

        $found = $this->getRepository()->find($conditions);

        return $found;
    }