コード例 #1
0
ファイル: api.php プロジェクト: nem0xff/core
 /**
  * respond to a call
  * @param OC_OCS_Result $result
  * @param string $format the format xml|json
  */
 public static function respond($result, $format = 'xml')
 {
     // Send 401 headers if unauthorised
     if ($result->getStatusCode() === API::RESPOND_UNAUTHORISED) {
         header('WWW-Authenticate: Basic realm="Authorisation Required"');
         header('HTTP/1.0 401 Unauthorized');
     }
     foreach ($result->getHeaders() as $name => $value) {
         header($name . ': ' . $value);
     }
     $meta = $result->getMeta();
     $data = $result->getData();
     if (self::isV2(\OC::$server->getRequest())) {
         $statusCode = self::mapStatusCodes($result->getStatusCode());
         if (!is_null($statusCode)) {
             $meta['statuscode'] = $statusCode;
             OC_Response::setStatus($statusCode);
         }
     }
     self::setContentType($format);
     $body = self::renderResult($format, $meta, $data);
     echo $body;
 }
コード例 #2
0
ファイル: privatedata.php プロジェクト: olucao/owncloud-core
 /**
  * @param \OC_OCS_Result $result
  * @param integer $expectedArraySize
  */
 public function assertOcsResult($expectedArraySize, $result)
 {
     $this->assertEquals(100, $result->getStatusCode());
     $data = $result->getData();
     $this->assertTrue(is_array($data));
     $this->assertEquals($expectedArraySize, sizeof($data));
 }
コード例 #3
0
ファイル: api.php プロジェクト: kebenxiaoming/owncloudRedis
 /**
  * respond to a call
  * @param OC_OCS_Result $result
  * @param string $format the format xml|json
  */
 public static function respond($result, $format = 'xml')
 {
     // Send 401 headers if unauthorised
     if ($result->getStatusCode() === self::RESPOND_UNAUTHORISED) {
         header('WWW-Authenticate: Basic realm="Authorisation Required"');
         header('HTTP/1.0 401 Unauthorized');
     }
     $response = array('ocs' => array('meta' => $result->getMeta(), 'data' => $result->getData()));
     if ($format == 'json') {
         OC_JSON::encodedPrint($response);
     } else {
         if ($format == 'xml') {
             header('Content-type: text/xml; charset=UTF-8');
             $writer = new XMLWriter();
             $writer->openMemory();
             $writer->setIndent(true);
             $writer->startDocument();
             self::toXML($response, $writer);
             $writer->endDocument();
             echo $writer->outputMemory(true);
         }
     }
 }
コード例 #4
0
ファイル: shareestest.php プロジェクト: lchen01/STEdwards
 /**
  * @param \OC_OCS_Result $ocs
  * @param string $message
  */
 protected function assertOCSError(\OC_OCS_Result $ocs, $message)
 {
     $this->assertSame(Http::STATUS_BAD_REQUEST, $ocs->getStatusCode(), 'Expected status code 400');
     $this->assertSame([], $ocs->getData(), 'Expected that no data is send');
     $meta = $ocs->getMeta();
     $this->assertNotEmpty($meta);
     $this->assertArrayHasKey('message', $meta);
     $this->assertSame($message, $meta['message']);
 }
コード例 #5
0
ファイル: EndPoint.php プロジェクト: drognisep/Portfolio-Site
 /**
  * @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;
 }