Compose JSON.

@param  array  $data
@param  int  $status
@param  array  $config

@return \Symfony\Component\HttpFoundation\Response
979472
public function composeJson(array $data = [], int $status = 200, array $config = []): SymfonyResponse
    {
        return Response::make($this->createJsonResponse($data, $config)(), $status, [
            'Content-Type' => 'application/json',
        ]);
    }
281538
protected function createJsonResponse($data = null, $scope = null, $status = 200)
    {
        if ($data !== null) {
            $data = is_string($data) ?
                $data :
                $this->container->get('serializer')->serialize(
                    $data, 'json', empty($scope) ? array() : array('scope' => $scope)
                )
            ;
        }

        $response = new Response(null === $data ? '' : $data, $status);
        $response->headers->set('Content-Type', 'application/json');

        return $response;
    }
372774
public function respond($response, $status, $headers, $options)
    {
        switch ($this->getRequestFormat()) {
            case 'html' :
            case 'text/html' :
                return Response::make($response, $status, $headers, $options)
                    ->header('Content-Type', 'text/html');
            default :
                // whether 'Content-Type' is NULL or equal to anything such as 'application/json' response will be JSON
                return Response::json($response, $status, $headers, $options);
        }
    }
451118
protected function prepareHttpResponse($data, $status, $exception = null)
	{
	    
	    $error = $this->getRequest()->getHeader(
	            self::HEADER_ERRORS, 
	            self::HEADER_ERRORS_DEFAULT);
	    
	    $forceHtmlContentType = $this->getRequest()->getHeader(
	            self::HEADER_FORCE_CONTENT_HTML,
	            false);
	    
	    if ($error instanceof HeaderInterface) {
	        $error = $error->getFieldValue();
	    }
	    
	    $response = $this->getResponse();
	    
	    $headers = array(
	    	'Cache-Control' => 'no-cache, must-revalidate',
	        'Pragma' 		=> 'no-cache',
	    	'Expires' 		=> '2000-01-01 00:00:00',
            'Content-Type'  => 'application/json',
	    );
	    
	    if ($forceHtmlContentType) {
	        $headers['Content-Type'] = 'text/html';
	    }

	    $response->getHeaders()->addHeaders($headers);
	    
	    // update response status code
	    $response->setStatusCode(
        	$status
        );
	    
	    // update reason phrase
	    if($exception){
	        
	        if ($exception instanceof ServiceException) {
	            $message = $exception->getMessage();
	        } else {
	            $message = 'Unknown exception';
	        }
	        
	    	$response->setReasonPhrase(
    	        $message
	    	);
	    }
	    
	    if ($data instanceof \Zend\Http\Response) {
	        
    	    // Attach custom stream response sender listener
	        // to send the stream to output buffer in chunks
	        if ($data instanceof Stream) {
	            $sendReponseListener = $this->getServiceLocator()->get('SendResponseListener');
	            $sendReponseListener->getEventManager()->attach(
	                    SendResponseEvent::EVENT_SEND_RESPONSE,
	                    new StreamResponseSender(),
	                    10000);
	        }
	        
	        return $data;
	    } else {
	        
	        $responseModel = array(
                'd' => $data
	        );
	        
	        // Append exception data
	        if ($exception) {
	            
	            if ($error == self::HEADER_ERRORS_VERBOSE && $exception instanceof ServiceException) {
	                $responseModel['e'] = array(
                        'm' => $exception->getRawMessage(),
                        'c' => $exception->getCode(),
                        'a' => $exception->getVars()
	                );
	                
	            } else {
	                $responseModel['e'] = array(
                        'm' => $response->getReasonPhrase(),
                        'c' => $exception->getCode(),
	                );
	            }
	        }
	        
	        try {
	            $response->setContent(JsonEncoder::encode($responseModel, true));
	        } catch (Exception $e) {
	            
	            if ($e instanceof RecursionException) {
	                $message = self::CYCLIC_DATA_ERROR;
	            } else {
	                $message = $e->getMessage();
	            }
	            
	            $response->setReasonPhrase(
                    $message
	            );
	            
	            $response->setStatusCode(
                    self::STATUS_UNKNOWN_EXCEPTION
	            );
	            
	            $response->setContent(JsonEncoder::encode([
                    'd' => null,
                    'e' => [
	                   'm' => $message,
	                   'c' => $e->getCode()
	               ]
	            ], true));
	        }
	        
	        return $response;
	    }
	}
994063
public function xml($data, $status = 200)
    {
        $body = $this->response->getBody();
        $body->rewind();
        $body->write($data);

        $response = $this->response->withHeader('Content-Type', 'application/xml;charset=utf-8');

        if (isset($status)) {
            return $response->withStatus($status);
        }

        return $response;
    }
560483
public function respond(array $data, $status = 200, $code, array $headers = [], $options = 0)
    {
        return $this->response->json(
            array_merge(compact('status', 'code'), $data), $status, $headers, $options
        );
    }
803190
public function getByStatus( $status, $config = [] ) {

		$limit = $config[ 'limit' ] ?? 10;

		$modelClass	 = static::$modelClass;
		$modelTable	 = $modelClass::tableName();

		$query = $modelClass::find()->where( [ "$modelTable.status" => $status ] );

		$query->limit( $limit );

		return $query->orderBy( [ 'id' => SORT_DESC ] )->all();
	}
526840
public function outputJson($data = null, $message = '', $status = 200)
    {
        // 错误信息返回格式可参考：[https://developer.github.com/v3/]
        if ($status != 200 && $message !== '') {
            $data = [
                'message' => $message
            ];
        }
        parent::outputJson($data, $status);
    }
601114
public function streamCsv(array $data = [], $status = 200, array $config = []): SymfonyResponse
    {
        $filename = $config['filename'] ?? 'export';

        $collection = $this->convertToCsvable($data, $config);

        return Response::stream(function () use ($collection) {
            $collection->streamCsv();
        }, $status, [
            'Content-Type' => 'text/csv',
            'Content-Disposition' => 'attachment; filename="'.$filename.'.csv"',
        ]);
    }
580555
public function serializeSingleObject(array $data, $type,  $statusCode = Response::HTTP_OK)
    {
        $model = new ResponseModel($data, $type);

        return new JsonResponse($model->getBody(), $statusCode);
    }
646715
public function json( array $config = [] ) {
        $options = isset($config['big_int_strings']) ? JSON_BIGINT_AS_STRING : 0;
        return json_decode($this->response->getBody(), false, 512, $options);
    }
483756
public function error($data = [], $status = Response::HTTP_BAD_REQUEST, $headers = [])
    {
        return $this->response($data, $status, $headers);
    }
891113
public function composeXlsx(array $data = [], int $status = 200, array $config = []): SymfonyResponse
    {
        return $this->composeExcel($data, $config, Exporter::XLSX);
    }
797226
public function jsonp($callback, $data = [], $status = 200, array $headers = [], $options = 0)
    {
        return $this->json($data, $status, $headers, $options)->setCallback($callback);
    }
1019411
public function json($data, $statusCode=null)
    {
        // Set Status Code
        if ($statusCode) {
            $this->setStatusCode($statusCode);
        }
        
        $this->setFormat(Response::FORMAT_JSON);

        if (!is_null($data)) {
            $this->setData($data);
        }
        
        return $this->send();
    }
279450
public function respondWithData(array $data)
    {

        $responseData = $this->getResponseStructure(true, $data, '');
        $response = new JsonResponse($responseData, $this->getStatusCode(), $this->getHeaders());
        return $response;
    }
992117
public function json($data = [], $status = 200, array $headers = [], $options = false)
    {
        $options = ($options === false) ? JSON_PRETTY_PRINT : $options;

        return new JsonResponse($data, $status, $headers, $options);
    }