Process the result and split into headers and content

@param string|bool $result
@return array
182804
public function prepareResponse($result)
    {
        $response = ['header' => null, 'content' => null];
        $d = "\r\n\r\n"; // Headers and content delimiter

        if (is_string($result) && strpos($result, $d) !== false) {
            list($header, $content) = explode($d, $result, 2);
            if (stripos($header, '100 Continue') !== false && strpos($content, $d) !== false) {
                list($header, $content) = explode($d, $content, 2);
            }
            $response['header'] = $header;
            $response['content'] = htmlentities($content);
        }

        return $response;
    }
1363429
public function renderOnSuccess($result, SilexKernel $silexKernel)
    {
        if (!is_array($result)) {
            $result = ['result' => $result];
        }
        
        return new JsonResponse($result);
    }
804243
public function result_collections($result)
    {
        // Combine $collection and $expanded headers
        $collections = isset($result['$collection'])
            ? array($result['$collection'])
            : array();

        if (isset($result['$expanded'])) {
            foreach ($result['$expanded'] as $expanded_collection) {
                $collections[] = $expanded_collection;
            }
        }

        return $collections;
    }
1154505
protected function processChannels($data, Result &$result)
    {

        // Create a buffer
        $buffer = new Buffer($data);

        // The first line holds the column names, data returned is in column/row format
        $columns = explode("\t", trim($buffer->readString("\n")), 9);

        // Loop through the rows until we run out of information
        while ($buffer->getLength()) {
            // Grab the row, which is a tabbed list of items
            $row = trim($buffer->readString("\n"));

            // Explode and merge the data with the columns, then parse
            $data = array_combine($columns, explode("\t", $row, 9));

            foreach ($data as $key => $value) {
                // Now add the data to the result
                $result->addTeam($key, utf8_encode($value));
            }
        }

        unset($data, $buffer, $row, $columns, $key, $value);
    }
530496
public function convertArticleLayout($result) {
        if (isset($result->chapters)) {
            $result->chapters = array_map(
                array($this, '_convertChapterLayout'),
                $result->chapters->toArray()
            );
        }
    }
241233
private static function toRow(ResultInterface $result): array
    {
        $row = [
            'id' => $result->getChecker()->getId(),
            'link' => $result->getChecker()->getLink(),
            'description' => $result->getChecker()->getDescription(),
            'status' => $result->getStatus(),
            'messages' => $result->getMessages(),
        ];

        $row['status'] = self::colorize($result, $row['status']);
        $row['message'] = implode(PHP_EOL, $row['messages']);

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

        return $result;
    }
717414
private function processResults($results)
    {
        $entries = $this->connection->getEntries($results);

        $objects = [];

        if (array_key_exists('count', $entries)) {
            for ($i = 0; $i < $entries['count']; $i++) {
                $entry = $this->newLdapEntry($entries[$i], $this->connection);

                $objects[] = $entry->getAttributes();
            }

            if (!empty($this->sortByField)) {
                return $this->processSortBy($objects);
            }
        }

        return $objects;
    }
525965
private function processHitResults(&$results, $result_set, $query_settings) {
        // If we're only returning hits, we can return the count here.
        if($query_settings['count']) {
            $results[] = ['count' => array_sum(array_map(function($x) { return $x['hits']['total']; }, $result_set))];
            return;
        }

        foreach($result_set as $result) {
            foreach($result['hits']['hits'] as $result) {
                $result = array_merge($result, $result['_source']);
                unset($result['_source']);
                if($query_settings['flatten']) {
                    $result = $this->flattenResults($result);
                }

                $results[] = $result;
            }
        }
    }
1158367
public function processResponse()
    {
        // Will hold the results when complete
        $results = [];

        // Holds sorted response packets
        $packets = [];

        // We need to pre-sort these for split packets so we can do extra work where needed
        foreach ($this->packets_response as $response) {
            $buffer = new Buffer($response);

            // Get the header of packet (long)
            $header = $buffer->readInt32Signed();

            // Single packet
            if ($header == -1) {
                // We need to peek and see what kind of engine this is for later processing
                if ($buffer->lookAhead(1) == "\x6d") {
                    $this->source_engine = self::GOLDSOURCE_ENGINE;
                }

                $packets[] = $buffer->getBuffer();
                continue;
            } else {
                // Split packet

                // Packet Id (long)
                $packet_id = $buffer->readInt32Signed() + 10;

                // Add the buffer to the packet as another array
                $packets[$packet_id][] = $buffer->getBuffer();
            }
        }

        // Free up memory
        unset($response, $packet_id, $buffer, $header);

        // Now that we have the packets sorted we need to iterate and process them
        foreach ($packets as $packet_id => $packet) {
            // We first need to off load split packets to combine them
            if (is_array($packet)) {
                $buffer = new Buffer($this->processPackets($packet_id, $packet));
            } else {
                $buffer = new Buffer($packet);
            }

            // Figure out what packet response this is for
            $response_type = $buffer->read(1);

            // Figure out which packet response this is
            if (!array_key_exists($response_type, $this->responses)) {
                throw new Exception(__METHOD__ . " response type '{$response_type}' is not valid");
            }

            // Now we need to call the proper method
            $results = array_merge(
                $results,
                call_user_func_array([$this, $this->responses[$response_type]], [$buffer])
            );

            unset($buffer);
        }

        // Free up memory
        unset($packets, $packet, $packet_id, $response_type);

        return $results;
    }
518390
public function processColumnListing($results)
	{
		$mapping = function ($r) {
			$r = (object) $r;

			return $r->name;
		};

		return array_map($mapping, $results);
	}
1223902
private function getFormattedResults(&$results) {
    return implode('', array(
        $this->getReportInfo($results),
        $this->getPaginationInfo($results),
        $this->getProfileInformation($results),
        $this->getQueryParameters($results),
        $this->getColumnHeaders($results),
        $this->getTotalsForAllResults($results),
        $this->getRows($results)
    ));
    
  }
253061
protected function processI(array $result) {
		$entity = df_ic($this->entityC(), O::class, $result); /** @var O $entity */
		$entity->validate();
		return $result;
	}
92972
protected function processResponse(ResultSet $result = null)
    {
        $this->hits = array();
        if (is_null($result)) {
            return null;
        }
        $this->collectHits($result);
        $this->collectAggregations($result);
    }
1331717
public function getResponse($result)
    {
        $content = $result->getContent();

        if ($result->headers->get('content-type') == 'application/json'){
            $content = json_decode($result->getContent(),true);
        }

        return array(
          'type' => 'rpc',
          'tid' => $this->tid,
          'action' => $this->action,
          'method' => $this->method,
          'result' => $content
        );
    }
1265379
protected function show($result)
    {
        $callback = Yii::$app->request->get('callback', null);

        if ($callback && is_string($callback)) {
            Yii::$app->response->format = yii\web\Response::FORMAT_JSONP;
            return [
                'callback' => $callback,
                'data' => $result
            ];
        }

        Yii::$app->response->format = yii\web\Response::FORMAT_JSON;
        return $result;
    }
1134187
private function format(DiffResult $result)
    {
        $serializer = SerializerBuilder::create()->build();

        return $serializer->serialize($result, 'json');
    }