Encode regular array response, with status 200.

@param  array             $action_result
@param  ResponseInterface $response
@param  int               $status
@return ResponseInterface
182681
protected function encodeArray(array $action_result, ResponseInterface $response, $status = 200)
    {
        return $response->write(json_encode($action_result))->withStatus($status);
    }
1361785
public function mapResponse($success, $response)
    {
        if (array_key_exists('collection', $response)) {
            $response = array_merge($response, $response['collection']);

            unset($response['collection']);
        }

        $rawResponse = $response;
        $test = $this->config['test'];

        unset($rawResponse['isRedirect']);
        unset($rawResponse['topic']);

        if ($response['isRedirect']) {
            return (new Response())->setRaw($rawResponse)->map([
                'isRedirect'      => $response['isRedirect'],
                'success'         => $response['isRedirect'] ? false : $success,
                'reference'       => $success ? Arr::get($response, 'id') : null,
                'message'         => 'Redirect',
                'test'            => $test,
                'authorization'   => $success ? Arr::get($response, $test ? 'sandbox_init_point' : 'init_point') : null,
                'status'          => $success ? new Status('pending') : new Status('failed'),
                'errorCode'       => $success ? null : $this->getErrorCode($response),
                'type'            => null,
            ]);
        }

        return (new Response())->setRaw($rawResponse)->map([
            'isRedirect'      => false,
            'success'         => $success,
            'reference'       => $success ? $this->getReference($response) : null,
            'message'         => $success ? 'Transaction approved' : $this->getMessage($rawResponse),
            'test'            => $test,
            'authorization'   => $success ? Arr::get($response, 'id') : null,
            'status'          => $this->getStatus($response),
            'errorCode'       => $success ? null : $this->getErrorCode($response),
            'type'            => Arr::get($response, 'topic'),
        ]);
    }
1374391
public function response($data = [], $status = Response::HTTP_OK, $headers = [])
    {
        return new JsonResponse($data, $status, $headers, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
    }
640215
protected function prepareActionResponse($status, $notificationId) {

        $response = new ActionResponse();
        $response->setStatus($status);
        $response->setNotify($this->getDataTablesNotification($notificationId));

        return $response;
    }
1065360
public static function processResult(string $url, ResponseInterface $response)
    {
        $body = $response->getBody()->getContents();
        $body = Tools::jsonNumbersToString($body);
        $result = Json::decode($body);
        self::checkErrors($result, $url);

        return $result;
    }
1014962
private function extractStatus(
        $name,
        ResponseInterface $response,
        array &$result
    ) {
        $result[$name] = (int) $response->getStatusCode();
    }
779352
public static function json($data, $status = NULL) {
        if ($status) {
            parent::setStatus($status);
        }
        parent::setContentType('application/json');
        return json_encode($data);
    }
730550
protected function getOutputResponse(
        ServerRequestInterface $request,
        ResponseInterface $response
    ) : ResponseInterface {
        ob_start();
        switch ($this->determineOutputType()) {
            case self::TYPE_JSON:
                $this->renderJSON($request, $response);
                break;
            case self::TYPE_XML:
                $this->renderXML($request, $response);
                break;
            case self::TYPE_PLAIN:
                $this->renderPlainText($request, $response);
                break;
            default:
                $this->renderHTML($request, $response);
                break;
        }

        $output = ob_get_clean();
        $body = new RequestBody();
        // write handler
        $body->write($output);
        return $response->withStatus(404)->withBody($body);
    }
328192
protected function renderAction(array $parameters = [], Action $action = null)
    {
        $response = new Response();
        $response->setContent($this->getTemplate($action)->render($parameters));

        return $response;
    }
479457
protected function respond($response, $status, $body)
    {
        $response->status($status);

        $response->end($body);
    }
919727
protected function getResultFromResponse(Response $response)
    {
        $result = [];

        foreach ($response->getData() as $element) {
            $attributes = $this->getAttributes($element);
            $attributes['type'] = $element['type'];

            $result[] = $attributes;
        }

        return $result;
    }
764081
private function getResult($response)
    {
        $status = $response->getStatusCode();
        if ($status == 200) {
            return json_decode($response->getBody(), JSON_PRETTY_PRINT);
        } else {
            return [$status => $response->getReasonPhrase()];
        }
    }
487364
public function toResponse($status = 200, array $headers = [], $options = 0)
    {
        return new JsonResponse($this->transform(), $status, $headers, $options);
    }
557923
public static function failedToDecodeResponse(ResponseInterface $response, $error)
    {
        $response->getBody()->rewind();
        return new static(sprintf(
            "Failed to decode response '%s' with error '%s'",
            $response->getBody()->getContents(),
            $error
        ));
    }
801059
public function response(ServerRequestInterface $request, ResponseInterface $response)
    {
        // Demo contents
        $contents = 'It works!';

        // Write Response to Body
        $response->getBody()->write($contents);

        // PSR-7 response
        return $response;
    }
482302
protected function json(array $data = [], string $status = Response::HTTP_OK): JsonResponse
    {
        $headers = $this->getResponse()->headers->all();

        $serializedData = [];

        foreach ($data as $key => $item) {
            if (is_array($item) && is_object($item[0])) {
                $serializedData[$key] = EntityNormalizer::normalize($item);

                unset($data[$key]);
            }

            if (is_object($item)) {
                $serializedData[$key] = EntityNormalizer::normalize([$item])[0];

                unset($data[$key]);
            }
        }

        $serializedData = array_merge($serializedData, $data);

        return new JsonResponse($serializedData, $status, $headers);
    }
127709
public function respond($statusCode = 200, $headers = [], $options = 0)
    {
        $response = new JsonResponse();

        $response->setData($this->createData()->toArray());

        if (is_int($statusCode)) {
            $statusCode = function (JsonResponse $response) use ($statusCode) {
                return $response->setStatusCode($statusCode);
            };
        }

        if (is_array($headers)) {
            $headers = function (JsonResponse $response) use ($headers) {
                return $response->withHeaders($headers);
            };
        }

        if (is_int($options)) {
            $options = function (JsonResponse $response) use ($options) {
                $response->setEncodingOptions($options);

                return $response;
            };
        }

        if (is_callable($options)) {
            $options($response);
        }

        if (is_callable($statusCode)) {
            $statusCode($response);
        }

        if (is_callable($headers)) {
            $headers($response);
        }

        return $response;
    }