lithium\data\source\MongoDb::_conditions()

protected method

Protected helper method used to format conditions.

Parameters

  • array $conditions

    The conditions array to be processed.

  • string $model

    The name of the model class used in the query.

  • object $schema

    The object containing the schema definition.

  • object $context

    The Query object.

Returns

array

Processed query conditions.

Source

	protected function _conditions(array $conditions, $model, $schema, $context) {
		$ops = $this->_operators;
		$castOpts = array(
			'first' => true, 'database' => $this, 'wrap' => false, 'asContent' => true
		);

		$cast = function($key, $value) use (&$schema, &$castOpts) {
			return $schema ? $schema->cast(null, $key, $value, $castOpts) : $value;
		};

		foreach ($conditions as $key => $value) {
			if (in_array($key, $this->_boolean)) {
				$operator = isset($ops[$key]) ? $ops[$key] : $key;

				foreach ($value as $i => $compare) {
					$value[$i] = $this->_conditions($compare, $model, $schema, $context);
				}
				unset($conditions[$key]);
				$conditions[$operator] = $value;
				continue;
			}
			if (is_object($value)) {
				continue;
			}
			if (!is_array($value)) {
				$conditions[$key] = $cast($key, $value);
				continue;
			}
			$current = key($value);

			if (!isset($ops[$current]) && $current[0] !== '$') {
				$conditions[$key] = array('$in' => $cast($key, $value));
				continue;
			}
			$conditions[$key] = $this->_operators($key, $value, $schema);
		}
		return $conditions;
	}