Create a service response of success

@param array $objects An object or array of objects
@param bool $echoResponse Whether to echo out of response
@param string $format 'json' or 'xml'
@return string The response
189682
public static function _success($objects, $echoResponse = TRUE, $format = 'json') {
        return self::_doResponse('success', $objects, $echoResponse, $format);
    }
346816
public function respond(array $data = [], array $headers = []): JsonResponse
    {
        $meta = [
            'meta' => [
                'server_time' => time(),
                'server_timezone' => date_default_timezone_get(),
                'api_version' => 'v1',
            ],
        ];

        return response()->json(array_merge($data, $meta), $this->getStatusCode(), $headers);
    }
452268
private function generateResult($format, $data, $trigger = true) {
        $etime = time();
        if ($trigger) {
            if (isset($data['error'])) {
                if ($this->api) {
                    fire('restful\errApi', $this->api, $etime, $data);
                }
                fire('restful\callError', $etime, $data);
            }
            fire('restful\endCall', $etime, $data);
        }
        if ($format == 'json') {
            return new JsonView(['response' => $data]);
        } else {
            return new XmlView($data, 'response');
        }
    }
106583
private function createResponse($content, $headers, \stdClass $curlMetaData) {
        $response = new Response();
        $response->setContent($content);
        $response->headers->add($headers);
        $response->setStatusCode($curlMetaData->http_code);

        return $response;
    }
692419
public static function createFromFormat($format, $time, $object = NULL)
    {
        $date = $object ? \DateTime::createFromFormat($format, $time, $object)
            : \DateTime::createFromFormat($format, $time);

        return $date !== false ?
            new self($date->format('Y-m-d H:i:s'), $date->getTimezone())
            : false;
    }
1110742
protected function handle(EchoRequest $request, Pbjx $pbjx): EchoResponse
    {
        return EchoResponseV1::create()->set('msg', $request->get('msg'));
    }
1374391
public function response($data = [], $status = Response::HTTP_OK, $headers = [])
    {
        return new JsonResponse($data, $status, $headers, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
    }
394717
public function getResponse($printResponse = true)
    {
        $this->setStatusInfo();
        if ($printResponse) {
            header('Content-Type: application/json');
            echo $this->ResponseData;
        } else {
            return $this->ResponseData;
        }
        return null;
    }
889178
public function setResponseFormat($format)
    {
        $format = strtolower($format);
        if (!in_array($format, array('php', 'json', 'jsonp'))) {
            throw new Exception("Expected a format of php, json or jsonp, got '$format'");
        } else {
            $this->responseFormat = $format;
        }
    }
678495
public function response($data, $format, $is_success=true, $status_code = 200)
    {
        $this->httpCode($status_code);
        if ($is_success) {
            $data['status'] = 1;
        } else {
            $data['status'] = 0;
        }
        switch ($format) {
            case self::RESPONSE_TYPE_JSON:
                $response_content = JsonHelper::encode($data);
                break;
            case self::RESPONSE_TYPE_XML:
                header('Content-type:application/xml');
                $response_content = XMLHelper::encode($data);
                break;
            default:
                $response_content = '';
        }
        if (!$is_success) {
            Lb::app()->stop($response_content);
        } else {
            echo $response_content;
        }
    }
348495
public static function create($format = self::FORMAT_JSON, $engine = self::ENGINE_API)
    {
        $response = '\Eureka\Component\Response';

        switch ($format) {
            //~ Json
            case self::FORMAT_JSON:
                $responseFormat = '\Json';
                break;
            //~ Html
            case self::FORMAT_HTML:
                $responseFormat = '\Html';
                break;
            //~ Other
            case self::FORMAT_XML:
            case self::FORMAT_TEXT:
            default:
                throw new \DomainException('Unsupported output format !');
        }

        switch ($engine) {
            //~ Api Engine
            case self::ENGINE_API:
                $response .= $responseFormat . '\Api';
                break;
            //~ Layout Engine
            case self::ENGINE_TEMPLATE:
                $response .= $responseFormat . '\Template';
                break;
            //~ None
            case self::ENGINE_NONE:
                $response .= $responseFormat . $responseFormat;
                //~ Do not add engine name to the class name.
                break;
            //~ Other
            default:
                throw new \DomainException('Unsupported output engine !');
        }

        $responseInstance = new $response();

        return $responseInstance;
    }
1305729
public static function create(array $parsedResponse)
    {
        $result = new self();
        $result->_serviceProperties = ServiceProperties::create($parsedResponse);

        return $result;
    }
1286506
public static function handle($object)
    {
        // allow only POST-JSON-RCP requests
        if (! $_SERVER['REQUEST_METHOD'] == 'POST') {
            header('Status: 405 Method Not Allowed');
            header('Allow: POST');
            echo "405 Method Not Allowed; Allow only: POST";
        } elseif (! isset($_SERVER['CONTENT_TYPE']) || substr($_SERVER['CONTENT_TYPE'], 0, 16) !== 'application/json') {
            header('Status: 406 Not Acceptable');
            header('Content-Type: application/json');
            echo "Status: 406 Not Acceptable; Valid Content-Type application/json";
        } else {
            // read the input data
            $request = json_decode(file_get_contents('php://input'), true);
            // executes the task on local object
            $response = array(
                'id' => $request['id'],
                'result' => null,
                'error' => null
            );
            try {
                $response['result'] = call_user_func_array(array(
                    $object,
                    $request['method']
                ), $request['params']);
            } catch (\Exception $e) {
                $response['result'] = null;
                $response['error'] = $e->getMessage();
            }

            // output the response, don't respond on notifications
            if ($request['id'] !== null) {
                header('content-type: text/javascript; charset=utf-8');
                echo json_encode($response);
            }
            return true;
        }
        return false;
    }
946683
public function echoJson($response, $res, $statusCode = 200)
    {
        $newResponse = $response->withJson($res, $statusCode);

        return $newResponse;
    }
25743
public function createResponse(ViewHandler $handler, View $view, Request $request, $format)
    {
        if (!$view->getData() instanceof ListRepresentation) {
            throw new ObjectNotSupportedException($view);
        }

        $viewData = $view->getData();
        $data = new CallbackCollection($viewData->getData(), [$this, 'prepareData']);
        $fileName = sprintf('%s.csv', $viewData->getRel());

        $config = new ExporterConfig();
        $exporter = new Exporter($config);

        $data->rewind();
        if ($row = $data->current()) {
            $config->setColumnHeaders(array_keys($row));
        }

        $config->setDelimiter($this->convertValue($request->get('delimiter', ';'), self::$delimiterMap));
        $config->setNewline($this->convertValue($request->get('newLine', '\\n'), self::$newLineMap));
        $config->setEnclosure($request->get('enclosure', '"'));
        $config->setEscape($request->get('escape', '\\'));

        $response = new StreamedResponse();
        $disposition = $response->headers->makeDisposition(
            ResponseHeaderBag::DISPOSITION_ATTACHMENT,
            $fileName,
            $fileName
        );
        $response->headers->set('Content-Type', 'text/csv');
        $response->headers->set('Content-Disposition', $disposition);
        $response->setCallback(
            function() use ($data, $exporter) {
                $exporter->export('php://output', $data);
            }
        );
        $response->send();

        return $response;
    }
476824
public function normalize($object, $format = null, array $context = [])
    {
        $normalized = ['errors' => []];

        foreach ($object as $innerError) {
            $normalized['errors'][] = $this->normalizer->normalize($innerError, $format, $context);
        }

        $normalized = $this->appendCollectionAttributes($normalized, $object, (string) $format, $context);

        return $normalized;
    }
849191
public function buildBatch(string $responseMessage): HttpResponseInterface
    {
        $response = $responseMessage;
        $this->splitResponseToHeadersArrayAndBody($response);
        $statusLineArray = explode(' ', trim($this->headers['status'][0]));

        $this->status = (int) $statusLineArray[1];

        //todo: Revisit this:
        if ($this->verboseExtractStatusLine === true) {
            $this->protocol = $statusLineArray[0];

            $this->statusPhrase = $this->decodeGetStatusPhrase($statusLineArray);
        }

        if (in_array((int) $this->status, $this->enabledHttpServerExceptions, true)) {
            // Ignoring this for now.
            // @codeCoverageIgnoreStart
            $this->protocol     = $statusLineArray[0];
            $this->statusPhrase = $this->decodeGetStatusPhrase($statusLineArray);
            throw new ServerException($this->statusPhrase, $this->status);
            // @codeCoverageIgnoreEnd
        }

        //todo: End revisit this:

        return $this;
    }