Ensures a DA-style response element is wrapped properly as an array.

@param mixed $result Messy input
@return array Sane output
169589
public static function sanitizeArray($result)
    {
        if (count($result) == 1 && isset($result['list[]'])) {
            $result = $result['list[]'];
        }
        return is_array($result) ? $result : [$result];
    }
267612
private function makeTree(array $result)
    {
        $tree = [];

        foreach ($result as $row) {
            $this->makeNode($row, $tree);
        }

        return $tree;
    }
620932
protected function append_result($result)
    {
        $this->meta['count'] += $result->count();

        // append UIDs to global index
        $folder = $result->get_parameters('MAILBOX');
        $index  = array_map(function($uid) use ($folder) { return $uid . '-' . $folder; }, $result->get());

        $this->index = array_merge($this->index, $index);
    }
791818
protected function checkReturn($result)
    {
        // 返回[ServerRequestInterface $req, ResponseInterface $res]
        if (!is_array($result) ||
            $result[0] instanceof ServerRequestInterface === false ||
            $result[1] instanceof ResponseInterface === false) {
            throw new \UnexpectedValueException(
                i18n(
                    'Middleware must return a array, the first element is %s and then second is %s.',
                    ServerRequestInterface::class,
                    ResponseInterface::class
                )
            );
        }
    }
1174500
protected function filterModelEventResults($result)
    {
        if (is_array($result)) {
            $result = array_filter($result, function ($response) {
                return ! is_null($response);
            });
        }

        return $result;
    }
399135
public static function group(array $result): array
    {
        $firstRow = current($result);
        if (empty($firstRow)) {
            return $result;
        }

        $dataKeys = array_keys($firstRow);
        $groupKey = array_shift($dataKeys);

        $rows = [];
        foreach ($result as $row) {
            $index = $row[$groupKey];
            unset($row[$groupKey]);

            $rows[$index][] = $row;
        }

        return $rows;
    }
1286720
protected function restoreVerbatimBlocks($result)
    {
        $result = preg_replace_callback(
            '/' . preg_quote($this->verbatimPlaceholder) . '/',
            function () {
                return array_shift($this->verbatimBlocks);
            },
            $result
        );

        $this->verbatimBlocks = [];

        return $result;
    }
355665
protected function _parseResult($result)
    {
        if (empty($result)) {
            $this->errCode = 'result error';
            $this->errMsg = '解析返回结果失败';
            return false;
        }
        if ($result['return_code'] !== 'SUCCESS') {
            $this->errCode = $result['return_code'];
            $this->errMsg = $result['return_msg'];
            return false;
        }
        if (isset($result['err_code']) && $result['err_code'] !== 'SUCCESS') {
            $this->errMsg = $result['err_code_des'];
            $this->errCode = $result['err_code'];
            return false;
        }
        return $result;
    }
500833
protected function processUpdateLists($result)
    {
        if ($core = array_get($result, 'core')) {
            $result['core']['updates'] = array_reverse(array_get($core, 'updates', []), true);
        }

        foreach (array_get($result, 'plugins', []) as $code => $plugin) {
            $result['plugins'][$code]['updates'] = array_reverse(array_get($plugin, 'updates', []), true);
        }

        return $result;
    }
990616
private static function unwrap(array $result): array
    {
        array_walk_recursive($result, function (&$value) {
            if ($value instanceof Image) {
                $value = $value->image;
            }
        });

        return $result;
    }
786059
public function buildResult($result)
    {
        $updates = [];

        foreach ($result as $updateData) {
            $update = new Update($updateData);
            $updates[] = $update;
            $this->lastUpdateId = max($this->lastUpdateId, $update->updateId);
        }

        return $updates;
    }
215196
protected function fixLinks($result)
    {
        if (false === $this->replaceLinks) {
            return $result;
        }

        $isArray = false;
        $string = '';
        if (is_array($result)) {
            $string = json_encode($result, JSON_UNESCAPED_SLASHES);
            $isArray = true;
        } elseif (is_string($result)) {
            $string = $result;
        }

        $myUri = Environment::getURI();

        $allRws = Service::whereType('rws')->whereIsActive(1)->get()->all();
        if (!empty($allRws)) {
            /** @var Service $rws */
            foreach ($allRws as $rws) {
                $config = $rws->getConfigAttribute();
                $baseUrl = trim(array_get($config, 'base_url'), '/');
                $dfUrl = trim($myUri, '/') . '/api/v2/' . $rws->name;
                $string = str_replace($baseUrl, $dfUrl, $string);
            }
        }

        return ($isArray) ? json_decode($string, true) : $string;
    }
1131342
public function fetchResult($result)
    {
        $fetchMode = $this->fetchMode;
        switch ($fetchMode) {
            case PDO::FETCH_ASSOC:
                return $result->result_array();
            case PDO::FETCH_OBJ:
                return $result->result();
        }

        throw new \BadMethodCallException("Unsupported fetch mode '$fetchMode'.");
    }
217979
protected function prepareAccessTokenResponse(array $result)
    {
        if ($this->getAccessTokenResourceOwnerId() !== null) {
            $result['resource_owner_id'] = $this->getValueByKey(
                $result,
                $this->getAccessTokenResourceOwnerId()
            );
        }
        return $result;
    }
1329662
public function formatAutocompleteResponse($results)
    {
        $output = [];
        foreach ($results as $row) {

            // Only keep the id and title fields
            $item = new stdClass;
            $item->id = $row->getKey();
            $item->title = $row->getAdminTitleAttribute();

            // Add properties for the columns mentioned in the list view within the
            // 'columns' property of this row in the response.  Use the same logic
            // found in Decoy::renderListColumn();
            $item->columns = [];
            foreach ($this->columns() as $column) {
                if (method_exists($row, $column)) {
                    $item->columns[$column] = call_user_func([$row, $column]);
                } elseif (isset($row->$column)) {
                    if (is_a($row->$column, 'Carbon\Carbon')) {
                        $item->columns[$column] = $row->$column->format(FORMAT_DATE);
                    } else {
                        $item->columns[$column] = $row->$column;
                    }
                } else {
                    $item->columns[$column] = null;
                }
            }

            // Add the item to the output
            $output[] = $item;
        }

        return $output;
    }
307434
protected function _decorateResults($result)
    {
        $result = $this->_applyDecorators($result);

        if (!($result instanceof ResultSet) && $this->isBufferedResultsEnabled()) {
            $class = $this->_decoratorClass();
            $result = new $class($result->buffered());
        }

        return $result;
    }
949521
protected function arrayToXml($result, &$xml)
	{
		foreach ($result as $key => $value) {
			if (is_array($value)) {
				if (!is_numeric($key)) {
					$subnode = $xml->addChild((string) $key);
				} else {
					$subnode = $xml->addChild('item_' . $key);
				}
				$this->arrayToXml($value, $subnode);
			} else {
				$xml->addChild($key, $value);
			}
		}
	}