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];
	}
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];
	}
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 ] ; }
Parses single condition
@param $condition string
@param $parameters mixed
@throws InvalidArgumentException
Parses single condition