对字段列表进行标准化
@param $fields mixed 字段列表
@return array 字段=>别名 数组
167915
private function formatFields($fields): array
    {
        // 按逗号分解
        if (is_string($fields)) {
            $fields = explode(',', $fields);
        }

        // 列名信息必须是字符串或对象或数组或0或空
        if (!is_array($fields)) {
            trigger_error('字段列表必须是字符串或数组:' . json($fields), E_USER_ERROR);
        }

        $ret = [];

        // 每一个字段进行检查
        foreach ($fields as $key => $value) {
            // 列名必须是字符串
            if (!is_string($value) or is_numeric($value)) {
                trigger_error('字段名必须是字符串:' . json($value), E_USER_ERROR);
            }

            // 如果是整数,表明,未指定键名,只有键 值
            if (is_int($key)) {
                // 是字段名或表达式
                if ($this->isField($value)) {
                    $ret[] = $this->markField($value);
                } else {
                    $ret[] = $value;
                }
                continue;
            }

            // 非整数的数值,这不科学
            if (is_numeric($key)) {
                trigger_error('字段别名必须是字符串:' . json($key), E_USER_ERROR);
            }

            // 键是字段名
            if ($this->isField($key)) {
                $ret[] = $this->markField($key) . ' AS `' . trim($value) . '`';
                continue;
            }

            // 加上别名
            $ret[] = $key . ' AS `' . trim($value) . '`';
        }

        return $ret;
    }
650917
protected function getFieldValues($fields)
    {
        $result = array();
        foreach ($fields as $id => $field) {
            if (isset($field['value'])) {
                $result[$id] = $field['value'];
            }
            if (!empty($field['fields'])) {
                /** @noinspection SlowArrayOperationsInLoopInspection */
                $result = array_merge($result, $this->getFieldValues($field['fields']));
            }
        }
        return $result;
    }
358714
public function group(array $fields)
    {
        $output = array();
        foreach ($fields as $name => $data) {
            if (is_array($data)) {
                list($data, $value, $class, $id) = $this->_findMainAttr($data);
                $output[] = $this->render($name, $value, $class, $id, $data);
            } else {
                $output[] = $this->render($name, $data);
            }
        }

        return implode(PHP_EOL, $output);
    }
177535
final public function toArrayFor($fields){
		$array = array();
		$all = $this->toArray();
		foreach($fields as $field){
			if( array_key_exists($field, $all) ){
				$array[$field] = $all[$field];
			}
		}
		return $array;
	}
95653
private function assoc_array_to_rows( $fields ) {
		$rows = array();

		foreach ( $fields as $field => $value ) {

			if ( ! is_string( $value ) ) {
				$value = json_encode( $value );
			}

			$rows[] = (object) array(
				'Field' => $field,
				'Value' => $value,
			);
		}

		return $rows;
	}
604125
public function only($fields)
    {
        if ( count(func_get_args()) > 1 ) {
            $fields = func_get_args();
        }

        if ( !is_array($fields) ) {
            $fields = [$fields];
        }

        $result = [];
        foreach ($this->all() as $fieldName => $value) {
            if ( in_array($fieldName, $fields) ) {
                $result[ $fieldName ] = $value;
            }
        }

        return $result;
    }
789107
public function select($fields = '*')
    {
        $query = new Query\SelectQuery();

        if ($this->pdo) {
            $query->setPDO($this->pdo);
        }

        return $query->select($fields);
    }
242546
public function col($fields, $where = null, $orderBy = null, $limit = null): array
    {
        // 按Select进行查询
        $table = self::selectArray($fields, $where, $orderBy, $limit);

        // 如果没有查到
        if (!$table) {
            return [];
        }

        // 保存返回值
        $ret = [];

        // 取所有的列名
        $keys = array_keys($table[0]);

        // 取第一个列名
        $key = $keys[0];

        // 逐个循环,取出一列的值
        foreach ($table as $row) {
            $ret[] = $row[$key];
        }

        // 返回一列
        return $ret;
    }
791816
public function whereNull($fields)
    {
        if (!is_array($fields)) {
            $fields = [$fields];
        }

        $exp = $this->newExpr();

        foreach ($fields as $field) {
            $exp->isNull($field);
        }

        return $this->where($exp);
    }
1353777
public function orderBy($fields)
    {
        if (!is_array($fields)) {
            $fields = explode(",", $fields);
        }

        $orderBy = "";

        foreach ($fields as $field) {
            if (!$field = trim($field)) {
                continue;
            }
            if (!$orderBy) {
                $orderBy = "ORDER BY ";
            } else {
                $orderBy .= ", ";
            }

            if (strpos($field, " ")) {
                $orderBy .= $field;
            } else {
                $orderBy .= $this->quoteField($field);
            }
        }

        return $orderBy;
    }
1185710
public function compileFields($fields)
    {
        $statement = [];

        foreach ($fields as $field) {
            $method = 'compile'.ucfirst($field->type);

            if (method_exists($this, $method)) {
                if (!empty($map = $this->$method($field))) {
                    $statement[$field->name] = $map;
                }
            }
        }

        return $statement;
    }
942680
public function fields( $fields )
	{
		if ( !is_array( $fields ) && !is_null( $fields ) )
		{
			$fields = array( $fields );
		}
		
		// do nothing if we get nothing
		if ( empty( $fields ) || $fields == array( '*' ) )
		{
			$this->fields = array(); return $this;
		}
		
		$this->fields = $fields;

		// return self so we can continue running the next function
		return $this;
	}
1150597
protected static function query($fields)
    {
        $result = Query::from(static::$table);

        $result = $result->where();

        foreach ($fields as $key => $value) {
            $result = $result->andWhere($key, '=', $value);
        }

        return $result->get();
    }
657561
public function parseField($fields){
        if(empty($fields)) {
            $fields    = array();
        }
        if(is_string($fields)) {
            $_fields    = explode(',',$fields);
            $fields     = array();
            foreach ($_fields as $f)
                $fields[$f] = true;
        }elseif(is_array($fields)) {
            $_fields    = $fields;
            $fields     = array();
            foreach ($_fields as $f=>$v) {
                if(is_numeric($f))
                    $fields[$v] = true;
                else
                    $fields[$f] = $v ? true : false;
            }
        }
        return $fields;
    }
1063344
protected function parseField($fields, $options = [])
    {
        $fieldsStr = '';
        if ('*' == $fields || empty($fields)) {
            $fieldsStr = '*';
        } elseif (is_array($fields)) {
            // 支持 'field1'=>'field2' 这样的字段别名定义
            $array = [];
            foreach ($fields as $key => $field) {
                if (!is_numeric($key)) {
                    $array[] = $this->parseKey($key, $options) . ' AS ' . $this->parseKey($field, $options);
                } else {
                    $array[] = $this->parseKey($field, $options);
                }
            }
            $fieldsStr = implode(',', $array);
        }
        return $fieldsStr;
    }
1333071
public function returnedFields($fields) {
		if(empty($this->data['returnedFields'])) {
			$this->data['returnedFields'] = array();
		}
		$this->data['returnedFields'] = array_unique(array_merge($this->data['returnedFields'], (array)$fields));
		return $this;
	}
290623
public function optimizeFields(array $fields)
	{
		$this->fields = $fields;
		foreach ($this->fields as $field)
		{
			foreach ($field as $source => $ids)
			{
				if ( ! isset($this->requests[$source]))
				{
					$this->requests[$source] = [];
				}
				foreach ($ids as $id)
				{
					$this->requests[$source][] = $id;
				}
				$this->requests[$source] = array_unique($this->requests[$source]);
			}
		}

		return $this;
	}