예제 #1
0
 /**
  * constructor of the controller
  * @param string $appName the name of the app
  * @param IRequest $request an instance of the request
  * @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0
  */
 public function __construct($appName, IRequest $request)
 {
     $this->appName = $appName;
     $this->request = $request;
     // default responders
     $this->responders = array('json' => function ($data) {
         if ($data instanceof DataResponse) {
             $response = new JSONResponse($data->getData(), $data->getStatus());
             $response->setHeaders(array_merge($data->getHeaders(), $response->getHeaders()));
             return $response;
         } else {
             return new JSONResponse($data);
         }
     });
 }
예제 #2
0
 /**
  * constructor of the controller
  * @param string $appName the name of the app
  * @param IRequest $request an instance of the request
  * @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0
  */
 public function __construct($appName, IRequest $request)
 {
     $this->appName = $appName;
     $this->request = $request;
     // default responders
     $this->responders = array('json' => function ($data) {
         if ($data instanceof DataResponse) {
             $response = new JSONResponse($data->getData(), $data->getStatus());
             $dataHeaders = $data->getHeaders();
             $headers = $response->getHeaders();
             // do not overwrite Content-Type if it already exists
             if (isset($dataHeaders['Content-Type'])) {
                 unset($headers['Content-Type']);
             }
             $response->setHeaders(array_merge($dataHeaders, $headers));
             return $response;
         } else {
             return new JSONResponse($data);
         }
     });
 }
예제 #3
0
 /**
  * @param \OC_OCS_Result $ocsResult
  * @return JSONResponse
  */
 protected function ocsToJsonResponse(\OC_OCS_Result $ocsResult)
 {
     $response = new JSONResponse(['ocs' => ['meta' => ['status' => 'ok', 'statuscode' => 100, 'message' => null], 'data' => $ocsResult->getData()]], $ocsResult->getStatusCode() === 100 ? Http::STATUS_OK : $ocsResult->getStatusCode());
     $response->setHeaders(array_merge($ocsResult->getHeaders(), ['Content-Type' => 'application/json; charset=utf-8']));
     return $response;
 }