コード例 #1
0
ファイル: DataResponseTest.php プロジェクト: evanjt/core
 public function testChainability()
 {
     $params = array('hi', 'yo');
     $this->response->setData($params)->setStatus(Http::STATUS_NOT_FOUND);
     $this->assertEquals(Http::STATUS_NOT_FOUND, $this->response->getStatus());
     $this->assertEquals(array('hi', 'yo'), $this->response->getData());
 }
コード例 #2
0
 /**
  * @NoAdminRequired
  *
  * @param string $userId
  * @param int $size
  * @return DataResponse|DataDisplayResponse
  */
 public function getAvatar($userId, $size)
 {
     if ($size > 2048) {
         $size = 2048;
     } elseif ($size <= 0) {
         $size = 64;
     }
     $avatar = $this->avatarManager->getAvatar($userId);
     $image = $avatar->get($size);
     if ($image instanceof \OCP\IImage) {
         $resp = new DataDisplayResponse($image->data(), Http::STATUS_OK, ['Content-Type' => $image->mimeType()]);
         $resp->setETag(crc32($image->data()));
     } else {
         $user = $this->userManager->get($userId);
         $userName = $user ? $user->getDisplayName() : '';
         $resp = new DataResponse(['data' => ['displayname' => $userName]]);
     }
     $resp->addHeader('Pragma', 'public');
     $resp->cacheFor(0);
     $resp->setLastModified(new \DateTime('now', new \DateTimeZone('GMT')));
     return $resp;
 }
コード例 #3
0
 /**
  * @param \OCA\Calendar\IObject|\OCA\Calendar\IObjectCollection $data
  * @param TimezoneMapper $timezones
  * @param int $statusCode
  */
 public function __construct($data, TimezoneMapper $timezones = null, $statusCode = Http::STATUS_OK)
 {
     $vobject = $data->getVObject();
     if ($vobject) {
         if ($timezones) {
             SabreUtility::addMissingVTimezones($vobject, $timezones);
         }
         $serialized = $vobject->serialize();
         parent::__construct($serialized, $statusCode, ['Content-type' => 'text/calendar; charset=utf-8']);
         if ($data instanceof IObject) {
             $this->setETag($data->getEtag(true));
         }
     } else {
         parent::__construct(null, HTTP::STATUS_NO_CONTENT);
     }
 }
コード例 #4
0
 /**
  * @NoAdminRequired
  * @NoCSRFRequired
  *
  * @param string $userId
  * @param int $size
  * @return DataResponse|DataDisplayResponse
  */
 public function getAvatar($userId, $size)
 {
     if ($size > 2048) {
         $size = 2048;
     } elseif ($size <= 0) {
         $size = 64;
     }
     try {
         $avatar = $this->avatarManager->getAvatar($userId)->getFile($size);
         $resp = new DataDisplayResponse($avatar->getContent(), Http::STATUS_OK, ['Content-Type' => $avatar->getMimeType()]);
         $resp->setETag($avatar->getEtag());
     } catch (NotFoundException $e) {
         $user = $this->userManager->get($userId);
         $resp = new DataResponse(['data' => ['displayname' => $user->getDisplayName()]]);
     } catch (\Exception $e) {
         $resp = new DataResponse(['data' => ['displayname' => '']]);
     }
     $resp->addHeader('Pragma', 'public');
     $resp->cacheFor(0);
     $resp->setLastModified(new \DateTime('now', new \DateTimeZone('GMT')));
     return $resp;
 }
コード例 #5
0
ファイル: ControllerTest.php プロジェクト: Romua1d/core
 public function customDataResponse($in)
 {
     $response = new DataResponse($in, 300);
     $response->addHeader('test', 'something');
     return $response;
 }