Use any available transformation method to process
the payload returned by the handler.

@param mixed $payload
@return JsonResource
@throws ResponderException
973726
protected function intoResource($payload)
    {
        // Transformer are intended to singular resources,
        // so what to do with collections
        if ($this->transformer != null) {
            $payload = $this->transformPayload($payload);
        }

        if($payload instanceof Collection || $payload instanceof AbstractPaginator) {
            return is_array($payload->first()) 
                ?  new ResourceCollection($payload->map(function($item) {
                    return new ArrayWrapper($item);
                }))
                : new ResourceCollection($payload);
        }

        if($payload instanceof Arrayable) {
            return $this->instantiateJsonResource($payload);
        }
        
        if(is_array($payload)) {
            return $this->instantiateJsonResource(new ArrayWrapper($payload));
        }
        
        if($payload instanceof \JsonSerializable) {
            return $this->instantiateJsonResource($payload);
        }

        throw new ResponderException("Cannot serialize object");
    }
416000
public function makeResponse(Request $request, Response $response, Responder $responder): Response
    {
        return $responder(
            $request,
            $response,
            new Payload(
                $this->getCode(),
                '',
                $this->getMessage()
            )
        );
    }
1374155
protected function handleRequest($request, $respondent)
    {
        try {
            $this->app->instance('respondent', $respondent);

            $request->enableHttpMethodParameterOverride();

            $response = $this->sendRequestThroughRouter($request);
        } catch (Exception $e) {
            $this->reportException($e);

            $response = $this->handleException($request, $e);
        } catch (Throwable $e) {
            $this->reportException($e = new FatalThrowableError($e));

            $response = $this->handleException($request, $e);
        }

        $this->app->forgetInstance('respondent');

        return $response;
    }
1348584
private function performCurlSession($payload)
    {
        $perCurlConnection = curl_init();
        curl_setopt($perCurlConnection, CURLOPT_URL, $this->url);
        curl_setopt($perCurlConnection, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($perCurlConnection, CURLOPT_TIMEOUT, 10);
        curl_setopt($perCurlConnection, CURLOPT_POSTFIELDS, $payload);

        $result = curl_exec($perCurlConnection);

        return $result;
    }
1078496
public function trigger(Payload $payload) {
		$url = $payload->getRepository()->getUrl();
		$branch = $payload->getRepository()->getMasterBranch();
		$isEnabled = (boolean) $this->getSettingValue(self::OPTION_ENABLED, TRUE);
		$matchesRepository = $url === $this->getSettingValue(self::OPTION_REPOSITORY, $url);
		$matchesBranch = $payload->getRef() === 'refs/heads/' . $this->getSettingValue(self::OPTION_BRANCH, $branch);
		return ($matchesRepository && $matchesBranch && $isEnabled);
	}
792638
protected static function handleResponse($response)
    {
        self::resolveContentType($response);

        $body = $response->getBody();
        $response = json_decode($body);

        self::resolveErrorResponse($response);

        return $response;
    }
124754
public function process($payload)
    {
        foreach ($this->stages as $stage) {
            $payload = call_user_func($stage, $payload);
        }
        return $payload;
    }
698264
public function generate($payload, $container = 'data')
    {
        if ($payload) {
            if ( ! is_array($payload)) {
                throw new ResponderException('Failed To Generate XML - Payload not an array');
            }
            $xml = new XMLWriter();
            $xml->openMemory();
            $xml->setIndent(true);
            $xml->startDocument('1.0', 'UTF-8');
            $xml->startElement($container);

            $this->write($xml, $payload);

            $xml->endElement(); //write end element
            //Return the XML results
            return $xml->outputMemory(true);
        }

        return '';
    }
1271547
public function fill($payload)
    {
        $payload = $this->determineTypeAndMessage($payload);
        $payload = $this->fillBlanks($payload);
        return $payload;
    }
232576
public function store($payload)
    {
        $payload['external'] = isset($payload['external']) ? $payload['external'] : 0;

        if ($payload['external'] != 0 && empty($payload['external_url'])) {
            throw new Exception("Your link was missing a URL", 1);
        }

        if (!isset($payload['page_id'])) {
            $payload['page_id'] = 0;
        }

        if ($payload['page_id'] == 0 && $payload['external'] == 0) {
            throw new Exception("Your link was not connected to anything, and could not be made", 1);
        }

        $link = $this->model->create($payload);

        $order = json_decode($link->menu->order);
        array_push($order, $link->id);
        $link->menu->update([
            'order' => json_encode($order),
        ]);

        return $link;
    }
1015940
private function preparePayload($payload, CompressionInterface $compression_method = null)
    {
        $prepared = is_string($payload) ? $payload : json_encode($payload);

        Assertion::notNull($prepared, 'The payload is empty or cannot encoded into JSON.');

        if (null === $compression_method) {
            return $prepared;
        }
        $compressed_payload = $compression_method->compress($prepared);
        Assertion::string($compressed_payload, 'Compression failed.');

        return $compressed_payload;
    }
702309
protected function handlePayload(Request $request, Response $response, Payload $payload): Response
    {
        $handler = $this->getHandler($request);

        return $response
            ->withBody(Factory::newStream($handler->body($payload)))
            ->withHeader('Content-Type', $handler->type())
            ->withStatus($payload->getCode())
        ;
    }
1367864
public function respond($payload = [])
    {
        if ($meta = $this->getMeta()) {
            $payload = array_merge(
                $payload,
                ['meta' => $meta]
            );
        }

        if (config('api.convert')) {
            $payload = PayloadConverter::run($payload);
        }

        $statusCode = (config('api.suppress_response_code') === true)
            ? StatusCode::OK : $this->getStatusCode();

        return (! $callback = $this->request->input('callback'))
            ? $this->response->json(
                $payload,
                $statusCode,
                $this->getHeaders(),
                config('api.jsonEncodeOption')
            )
            : $this->response->jsonp(
                $callback,
                $payload,
                $statusCode,
                $this->getHeaders()
            );
    }
991517
private function processResponse(Response $response)
    {
        $response = $response->getBody()->getContents();
        $response = json_decode($response, true);

        return $response;
    }
910342
public function generate($payload, $container = 'data')
    {
        if ($payload) {
            try {
                $flags = (defined('Symfony\Component\Yaml\Yaml::DUMP_OBJECT_AS_MAP')) ? (SFYaml::DUMP_OBJECT_AS_MAP | SFYaml::DUMP_EXCEPTION_ON_INVALID_TYPE) : true;
                return SFYaml::dump([$container => $payload], 9999, 4, $flags);
            } catch (\Exception $ex) {
                throw new ResponderException('Failed To Generate YAML');
            }
        }

        return '';
    }
1245921
public function parse($payload)
    {
        if (function_exists('MongoDB\BSON\toPHP') && ! function_exists('bson_decode')) {
            require_once(__DIR__ . '/BSONPolyfill.php');  //@codeCoverageIgnore
        } elseif ( ! (function_exists('bson_decode') || function_exists('MongoDB\BSON\toPHP'))) {
            throw new ParserException('Failed To Parse BSON - Supporting Library Not Available');  // @codeCoverageIgnore
        }

        if ($payload) {
            $prevHandler = set_error_handler(function ($errno, $errstr, $errfile, $errline, $errcontext) {
                throw new \Exception($errstr);  // @codeCoverageIgnore
            });

            try {
                $bson = bson_decode(trim($payload, " \t\n\r\x0b"));  // Don't trim \0, as it has valid meaning in BSON
                if ( ! $bson) {
                    throw new \Exception('Unknown error');  // @codeCoverageIgnore
                }
            } catch (\Exception $e) {
                set_error_handler($prevHandler);
                throw new ParserException('Failed To Parse BSON - ' . $e->getMessage());
            }

            set_error_handler($prevHandler);

            return $bson;
        }

        return [];
    }
118265
public function update(array $payload): Response
    {
        $this->requiresAccessToken();

        return $this->sendJson(
            'PATCH', 'profile', $this->getApiHeaders(), $this->mergeApiBody($payload)
        );
    }