lithium\data\source\Database::_operator PHP Method

_operator() protected method

Handles conversion of SQL operator keys to SQL statements.
protected _operator ( string $key, mixed $value, array $schema = [], array $options = [] ) : string
$key string Key in a conditions array. Usually a field name.
$value mixed An SQL operator or comparison value.
$schema array An array defining the schema of the field used in the criteria.
$options array
return string Returns an SQL string representing part of a `WHERE` clause of a query.
    protected function _operator($key, $value, array $schema = array(), array $options = array())
    {
        $defaults = array('boolean' => 'AND');
        $options += $defaults;
        list($op, $value) = each($value);
        $op = strtoupper($op);
        $config = $this->_operators[$op];
        $key = $this->name($key);
        $values = array();
        if (!is_object($value)) {
            if ($value === null) {
                $value = array(null);
            }
            foreach ((array) $value as $val) {
                $values[] = $this->value($val, $schema);
            }
        } elseif (isset($value->scalar)) {
            return "{$key} {$op} {$value->scalar}";
        }
        switch (true) {
            case isset($config['format']):
                return $key . ' ' . String::insert($config['format'], $values);
            case is_object($value) && isset($config['multiple']):
                $op = $config['multiple'];
                $value = trim(rtrim($this->renderCommand($value), ';'));
                return "{$key} {$op} ({$value})";
            case count($values) > 1 && isset($config['multiple']):
                $op = $config['multiple'];
                $values = join(', ', $values);
                return "{$key} {$op} ({$values})";
            case count($values) > 1:
                return join(" {$options['boolean']} ", array_map(function ($v) use($key, $op) {
                    return "{$key} {$op} {$v}";
                }, $values));
        }
        return "{$key} {$op} {$values[0]}";
    }