lithium\data\source\MongoDb::_conditions PHP Method

_conditions() protected method

Protected helper method used to format conditions.
protected _conditions ( array $conditions, string $model, object $schema, object $context ) : array
$conditions array The conditions array to be processed.
$model string The name of the model class used in the query.
$schema object The object containing the schema definition.
$context object The `Query` object.
return array Processed query conditions.
    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;
    }