Cml\Db\MongoDB\MongoDB::parseKey PHP Method

parseKey() protected method

查询语句条件组装
protected parseKey ( string $key, boolean $and = true, boolean $noCondition = false, boolean $noTable = false ) : array
$key string eg: 'forum-fid-1-uid-2'
$and boolean 多个条件之间是否为and true为and false为or
$noCondition boolean 是否为无条件操作 set/delete/update操作的时候 condition为空是正常的不报异常
$noTable boolean 是否可以没有数据表 当delete/update等操作的时候已经执行了table() table为空是正常的
return array eg: ['forum', "`fid` = '1' AND `uid` = '2'"]
    protected function parseKey($key, $and = true, $noCondition = false, $noTable = false)
    {
        $keys = explode('-', $key);
        $table = strtolower(array_shift($keys));
        $len = count($keys);
        $condition = [];
        for ($i = 0; $i < $len; $i += 2) {
            $val = is_numeric($keys[$i + 1]) ? intval($keys[$i + 1]) : $keys[$i + 1];
            $and ? $condition[$keys[$i]] = $val : ($condition['$or'][][$keys[$i]] = $val);
        }
        if (empty($table) && !$noTable) {
            throw new \InvalidArgumentException(Lang::get('_DB_PARAM_ERROR_PARSE_KEY_', $key, 'table'));
        }
        if (empty($condition) && !$noCondition) {
            throw new \InvalidArgumentException(Lang::get('_DB_PARAM_ERROR_PARSE_KEY_', $key, 'condition'));
        }
        return [$table, $condition];
    }