-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: jld3103 <[email protected]>
- Loading branch information
1 parent
266436b
commit e524051
Showing
20 changed files
with
215 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
* @author Joas Schilling <[email protected]> | ||
* @author Lukas Reschke <[email protected]> | ||
* @author Roeland Jago Douma <[email protected]> | ||
* @author Kate Döen <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
|
@@ -30,6 +31,13 @@ | |
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\AppFramework\Http\Response; | ||
|
||
/** | ||
* @psalm-import-type DataResponseType from DataResponse | ||
* @template S of int | ||
* @template-covariant T of DataResponseType | ||
* @template H of array<string, mixed> | ||
* @template-extends Response<int, array<string, mixed>> | ||
*/ | ||
abstract class BaseResponse extends Response { | ||
/** @var array */ | ||
protected $data; | ||
|
@@ -49,7 +57,7 @@ abstract class BaseResponse extends Response { | |
/** | ||
* BaseResponse constructor. | ||
* | ||
* @param DataResponse $dataResponse | ||
* @param DataResponse<S, T, H> $dataResponse | ||
* @param string $format | ||
* @param string|null $statusMessage | ||
* @param int|null $itemsCount | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
* @author Christoph Wurst <[email protected]> | ||
* @author Joas Schilling <[email protected]> | ||
* @author Roeland Jago Douma <[email protected]> | ||
* @author Kate Döen <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
|
@@ -25,8 +26,16 @@ | |
namespace OC\AppFramework\OCS; | ||
|
||
use OCP\AppFramework\Http; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\AppFramework\OCSController; | ||
|
||
/** | ||
* @psalm-import-type DataResponseType from DataResponse | ||
* @template S of int | ||
* @template-covariant T of DataResponseType | ||
* @template H of array<string, mixed> | ||
* @template-extends BaseResponse<int, DataResponseType, array<string, mixed>> | ||
*/ | ||
class V1Response extends BaseResponse { | ||
/** | ||
* The V1 endpoint has very limited http status codes basically everything | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
* | ||
* @author Christoph Wurst <[email protected]> | ||
* @author Roeland Jago Douma <[email protected]> | ||
* @author Kate Döen <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
|
@@ -24,8 +25,16 @@ | |
namespace OC\AppFramework\OCS; | ||
|
||
use OCP\AppFramework\Http; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\AppFramework\OCSController; | ||
|
||
/** | ||
* @psalm-import-type DataResponseType from DataResponse | ||
* @template S of int | ||
* @template-covariant T of DataResponseType | ||
* @template H of array<string, mixed> | ||
* @template-extends BaseResponse<int, DataResponseType, array<string, mixed>> | ||
*/ | ||
class V2Response extends BaseResponse { | ||
/** | ||
* The V2 endpoint just passes on status codes. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
* @author Julius Härtl <[email protected]> | ||
* @author Morris Jobke <[email protected]> | ||
* @author Roeland Jago Douma <[email protected]> | ||
* @author Kate Döen <[email protected]> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
|
@@ -30,6 +31,9 @@ | |
* Class DataDisplayResponse | ||
* | ||
* @since 8.1.0 | ||
* @template S of int | ||
* @template H of array<string, mixed> | ||
* @template-extends Response<int, array<string, mixed>> | ||
*/ | ||
class DataDisplayResponse extends Response { | ||
/** | ||
|
@@ -41,17 +45,14 @@ class DataDisplayResponse extends Response { | |
|
||
/** | ||
* @param string $data the data to display | ||
* @param int $statusCode the Http status code, defaults to 200 | ||
* @param array $headers additional key value based headers | ||
* @param S $statusCode the Http status code, defaults to 200 | ||
* @param H $headers additional key value based headers | ||
* @since 8.1.0 | ||
*/ | ||
public function __construct($data = '', $statusCode = Http::STATUS_OK, | ||
$headers = []) { | ||
parent::__construct(); | ||
public function __construct($data = '', int $statusCode = Http::STATUS_OK, array $headers = []) { | ||
parent::__construct($statusCode, $headers); | ||
|
||
$this->data = $data; | ||
$this->setStatus($statusCode); | ||
$this->setHeaders(array_merge($this->getHeaders(), $headers)); | ||
$this->addHeader('Content-Disposition', 'inline; filename=""'); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
* @author Georg Ehrke <[email protected]> | ||
* @author Morris Jobke <[email protected]> | ||
* @author Roeland Jago Douma <[email protected]> | ||
* @author Kate Döen <[email protected]> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
|
@@ -23,10 +24,16 @@ | |
*/ | ||
namespace OCP\AppFramework\Http; | ||
|
||
use OCP\AppFramework\Http; | ||
|
||
/** | ||
* Class DataDownloadResponse | ||
* | ||
* @since 8.0.0 | ||
* @template S of int | ||
* @template C of string | ||
* @template H of array<string, mixed> | ||
* @template-extends DownloadResponse<int, string, array<string, mixed>> | ||
*/ | ||
class DataDownloadResponse extends DownloadResponse { | ||
/** | ||
|
@@ -38,12 +45,14 @@ class DataDownloadResponse extends DownloadResponse { | |
* Creates a response that prompts the user to download the text | ||
* @param string $data text to be downloaded | ||
* @param string $filename the name that the downloaded file should have | ||
* @param string $contentType the mimetype that the downloaded file should have | ||
* @param C $contentType the mimetype that the downloaded file should have | ||
* @param S $status | ||
* @param H $headers | ||
* @since 8.0.0 | ||
*/ | ||
public function __construct($data, $filename, $contentType) { | ||
public function __construct($data, $filename, $contentType, int $status = Http::STATUS_OK, array $headers = []) { | ||
$this->data = $data; | ||
parent::__construct($filename, $contentType); | ||
parent::__construct($filename, $contentType, $status, $headers); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
* @author Christoph Wurst <[email protected]> | ||
* @author Morris Jobke <[email protected]> | ||
* @author Roeland Jago Douma <[email protected]> | ||
* @author Kate Döen <[email protected]> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
|
@@ -30,34 +31,37 @@ | |
* A generic DataResponse class that is used to return generic data responses | ||
* for responders to transform | ||
* @since 8.0.0 | ||
* @psalm-type DataResponseType = array|int|float|string|bool|object|null|\stdClass|\JsonSerializable | ||
* @template S of int | ||
* @template-covariant T of DataResponseType | ||
* @template H of array<string, mixed> | ||
* @template-extends Response<int, array<string, mixed>> | ||
*/ | ||
class DataResponse extends Response { | ||
/** | ||
* response data | ||
* @var array|int|float|string|bool|object | ||
* @var T | ||
*/ | ||
protected $data; | ||
|
||
|
||
/** | ||
* @param array|int|float|string|bool|object $data the object or array that should be transformed | ||
* @param int $statusCode the Http status code, defaults to 200 | ||
* @param array $headers additional key value based headers | ||
* @param T $data the object or array that should be transformed | ||
* @param S $statusCode the Http status code, defaults to 200 | ||
* @param H $headers additional key value based headers | ||
* @since 8.0.0 | ||
*/ | ||
public function __construct($data = [], $statusCode = Http::STATUS_OK, | ||
array $headers = []) { | ||
parent::__construct(); | ||
public function __construct($data = [], int $statusCode = Http::STATUS_OK, array $headers = []) { | ||
parent::__construct($statusCode, $headers); | ||
|
||
$this->data = $data; | ||
$this->setStatus($statusCode); | ||
$this->setHeaders(array_merge($this->getHeaders(), $headers)); | ||
} | ||
|
||
|
||
/** | ||
* Sets values in the data json array | ||
* @param array|int|float|string|object $data an array or object which will be transformed | ||
* @psalm-suppress InvalidTemplateParam | ||
* @param T $data an array or object which will be transformed | ||
* @return DataResponse Reference to this object | ||
* @since 8.0.0 | ||
*/ | ||
|
@@ -70,7 +74,7 @@ public function setData($data) { | |
|
||
/** | ||
* Used to get the set parameters | ||
* @return array|int|float|string|bool|object the data | ||
* @return T the data | ||
* @since 8.0.0 | ||
*/ | ||
public function getData() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
* @author Morris Jobke <[email protected]> | ||
* @author Roeland Jago Douma <[email protected]> | ||
* @author Thomas Müller <[email protected]> | ||
* @author Kate Döen <[email protected]> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
|
@@ -25,19 +26,27 @@ | |
*/ | ||
namespace OCP\AppFramework\Http; | ||
|
||
use OCP\AppFramework\Http; | ||
|
||
/** | ||
* Prompts the user to download the a file | ||
* @since 7.0.0 | ||
* @template S of int | ||
* @template C of string | ||
* @template H of array<string, mixed> | ||
* @template-extends Response<int, array<string, mixed>> | ||
*/ | ||
class DownloadResponse extends Response { | ||
/** | ||
* Creates a response that prompts the user to download the file | ||
* @param string $filename the name that the downloaded file should have | ||
* @param string $contentType the mimetype that the downloaded file should have | ||
* @param C $contentType the mimetype that the downloaded file should have | ||
* @param S $status | ||
* @param H $headers | ||
* @since 7.0.0 | ||
*/ | ||
public function __construct(string $filename, string $contentType) { | ||
parent::__construct(); | ||
public function __construct(string $filename, string $contentType, int $status = Http::STATUS_OK, array $headers = []) { | ||
parent::__construct($status, $headers); | ||
|
||
$filename = strtr($filename, ['"' => '\\"', '\\' => '\\\\']); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
* | ||
* @author Christoph Wurst <[email protected]> | ||
* @author Roeland Jago Douma <[email protected]> | ||
* @author Kate Döen <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
|
@@ -29,6 +30,9 @@ | |
* Class FileDisplayResponse | ||
* | ||
* @since 11.0.0 | ||
* @template S of int | ||
* @template H of array<string, mixed> | ||
* @template-extends Response<int, array<string, mixed>> | ||
*/ | ||
class FileDisplayResponse extends Response implements ICallbackResponse { | ||
/** @var \OCP\Files\File|\OCP\Files\SimpleFS\ISimpleFile */ | ||
|
@@ -38,17 +42,14 @@ class FileDisplayResponse extends Response implements ICallbackResponse { | |
* FileDisplayResponse constructor. | ||
* | ||
* @param \OCP\Files\File|\OCP\Files\SimpleFS\ISimpleFile $file | ||
* @param int $statusCode | ||
* @param array $headers | ||
* @param S $statusCode | ||
* @param H $headers | ||
* @since 11.0.0 | ||
*/ | ||
public function __construct($file, $statusCode = Http::STATUS_OK, | ||
$headers = []) { | ||
parent::__construct(); | ||
public function __construct($file, int $statusCode = Http::STATUS_OK, array $headers = []) { | ||
parent::__construct($statusCode, $headers); | ||
|
||
$this->file = $file; | ||
$this->setStatus($statusCode); | ||
$this->setHeaders(array_merge($this->getHeaders(), $headers)); | ||
$this->addHeader('Content-Disposition', 'inline; filename="' . rawurldecode($file->getName()) . '"'); | ||
|
||
$this->setETag($file->getEtag()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
* @author Roeland Jago Douma <[email protected]> | ||
* @author Thomas Müller <[email protected]> | ||
* @author Thomas Tanghus <[email protected]> | ||
* @author Kate Döen <[email protected]> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
|
@@ -32,26 +33,30 @@ | |
/** | ||
* A renderer for JSON calls | ||
* @since 6.0.0 | ||
* @template S of int | ||
* @template-covariant T of array|object|\stdClass|\JsonSerializable | ||
* @template H of array<string, mixed> | ||
* @template-extends Response<int, array<string, mixed>> | ||
*/ | ||
class JSONResponse extends Response { | ||
/** | ||
* response data | ||
* @var array|object | ||
* @var T | ||
*/ | ||
protected $data; | ||
|
||
|
||
/** | ||
* constructor of JSONResponse | ||
* @param array|object $data the object or array that should be transformed | ||
* @param int $statusCode the Http status code, defaults to 200 | ||
* @param T $data the object or array that should be transformed | ||
* @param S $statusCode the Http status code, defaults to 200 | ||
* @param H $headers | ||
* @since 6.0.0 | ||
*/ | ||
public function __construct($data = [], $statusCode = Http::STATUS_OK) { | ||
parent::__construct(); | ||
public function __construct($data = [], int $statusCode = Http::STATUS_OK, array $headers = []) { | ||
parent::__construct($statusCode, $headers); | ||
|
||
$this->data = $data; | ||
$this->setStatus($statusCode); | ||
$this->addHeader('Content-Type', 'application/json; charset=utf-8'); | ||
} | ||
|
||
|
@@ -68,7 +73,8 @@ public function render() { | |
|
||
/** | ||
* Sets values in the data json array | ||
* @param array|object $data an array or object which will be transformed | ||
* @psalm-suppress InvalidTemplateParam | ||
* @param T $data an array or object which will be transformed | ||
* to JSON | ||
* @return JSONResponse Reference to this object | ||
* @since 6.0.0 - return value was added in 7.0.0 | ||
|
@@ -81,8 +87,7 @@ public function setData($data) { | |
|
||
|
||
/** | ||
* Used to get the set parameters | ||
* @return array the data | ||
* @return T the data | ||
* @since 6.0.0 | ||
*/ | ||
public function getData() { | ||
|
Oops, something went wrong.