diff options
Diffstat (limited to 'lib/public')
36 files changed, 721 insertions, 176 deletions
diff --git a/lib/public/AppFramework/Db/Entity.php b/lib/public/AppFramework/Db/Entity.php index 34cd297e57e..1ae938f6e32 100644 --- a/lib/public/AppFramework/Db/Entity.php +++ b/lib/public/AppFramework/Db/Entity.php @@ -163,9 +163,9 @@ abstract class Entity { * @since 7.0.0 */ public function __call(string $methodName, array $args) { - if (strpos($methodName, 'set') === 0) { + if (str_starts_with($methodName, 'set')) { $this->setter(lcfirst(substr($methodName, 3)), $args); - } elseif (strpos($methodName, 'get') === 0) { + } elseif (str_starts_with($methodName, 'get')) { return $this->getter(lcfirst(substr($methodName, 3))); } elseif ($this->isGetterForBoolProperty($methodName)) { return $this->getter(lcfirst(substr($methodName, 2))); @@ -181,9 +181,9 @@ abstract class Entity { * @since 18.0.0 */ protected function isGetterForBoolProperty(string $methodName): bool { - if (strpos($methodName, 'is') === 0) { + if (str_starts_with($methodName, 'is')) { $fieldName = lcfirst(substr($methodName, 2)); - return isset($this->_fieldTypes[$fieldName]) && strpos($this->_fieldTypes[$fieldName], 'bool') === 0; + return isset($this->_fieldTypes[$fieldName]) && str_starts_with($this->_fieldTypes[$fieldName], 'bool'); } return false; } diff --git a/lib/public/AppFramework/Http/DataDisplayResponse.php b/lib/public/AppFramework/Http/DataDisplayResponse.php index 78ab343abd6..be2ade50bb5 100644 --- a/lib/public/AppFramework/Http/DataDisplayResponse.php +++ b/lib/public/AppFramework/Http/DataDisplayResponse.php @@ -6,6 +6,7 @@ * @author Julius Härtl <jus@bitgrid.net> * @author Morris Jobke <hey@morrisjobke.de> * @author Roeland Jago Douma <roeland@famdouma.nl> + * @author Kate Döen <kate.doeen@nextcloud.com> * * @license AGPL-3.0 * @@ -30,6 +31,9 @@ use OCP\AppFramework\Http; * 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(string $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=""'); } diff --git a/lib/public/AppFramework/Http/DataDownloadResponse.php b/lib/public/AppFramework/Http/DataDownloadResponse.php index 7f2bc73f6e2..f7005604795 100644 --- a/lib/public/AppFramework/Http/DataDownloadResponse.php +++ b/lib/public/AppFramework/Http/DataDownloadResponse.php @@ -5,6 +5,7 @@ * @author Georg Ehrke <oc.list@georgehrke.com> * @author Morris Jobke <hey@morrisjobke.de> * @author Roeland Jago Douma <roeland@famdouma.nl> + * @author Kate Döen <kate.doeen@nextcloud.com> * * @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(string $data, string $filename, string $contentType, int $status = Http::STATUS_OK, array $headers = []) { $this->data = $data; - parent::__construct($filename, $contentType); + parent::__construct($filename, $contentType, $status, $headers); } /** diff --git a/lib/public/AppFramework/Http/DataResponse.php b/lib/public/AppFramework/Http/DataResponse.php index e329b9c2975..1a56847d63d 100644 --- a/lib/public/AppFramework/Http/DataResponse.php +++ b/lib/public/AppFramework/Http/DataResponse.php @@ -6,6 +6,7 @@ * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Morris Jobke <hey@morrisjobke.de> * @author Roeland Jago Douma <roeland@famdouma.nl> + * @author Kate Döen <kate.doeen@nextcloud.com> * * @license AGPL-3.0 * @@ -30,34 +31,37 @@ use OCP\AppFramework\Http; * 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(mixed $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 @@ class DataResponse extends Response { /** * 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() { diff --git a/lib/public/AppFramework/Http/DownloadResponse.php b/lib/public/AppFramework/Http/DownloadResponse.php index b80f03958c0..5b3a235d444 100644 --- a/lib/public/AppFramework/Http/DownloadResponse.php +++ b/lib/public/AppFramework/Http/DownloadResponse.php @@ -7,6 +7,7 @@ * @author Morris Jobke <hey@morrisjobke.de> * @author Roeland Jago Douma <roeland@famdouma.nl> * @author Thomas Müller <thomas.mueller@tmit.eu> + * @author Kate Döen <kate.doeen@nextcloud.com> * * @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, ['"' => '\\"', '\\' => '\\\\']); diff --git a/lib/public/AppFramework/Http/EmptyContentSecurityPolicy.php b/lib/public/AppFramework/Http/EmptyContentSecurityPolicy.php index 98a42aeabb5..035b4f01f60 100644 --- a/lib/public/AppFramework/Http/EmptyContentSecurityPolicy.php +++ b/lib/public/AppFramework/Http/EmptyContentSecurityPolicy.php @@ -37,8 +37,6 @@ namespace OCP\AppFramework\Http; * @since 9.0.0 */ class EmptyContentSecurityPolicy { - /** @var bool Whether inline JS snippets are allowed */ - protected $inlineScriptAllowed = null; /** @var string Whether JS nonces should be used */ protected $useJsNonce = null; /** @var bool Whether strict-dynamic should be used */ @@ -84,18 +82,6 @@ class EmptyContentSecurityPolicy { protected $reportTo = null; /** - * Whether inline JavaScript snippets are allowed or forbidden - * @param bool $state - * @return $this - * @since 8.1.0 - * @deprecated 10.0 CSP tokens are now used - */ - public function allowInlineScript($state = false) { - $this->inlineScriptAllowed = $state; - return $this; - } - - /** * @param bool $state * @return EmptyContentSecurityPolicy * @since 24.0.0 @@ -447,7 +433,7 @@ class EmptyContentSecurityPolicy { $policy .= "base-uri 'none';"; $policy .= "manifest-src 'self';"; - if (!empty($this->allowedScriptDomains) || $this->inlineScriptAllowed || $this->evalScriptAllowed) { + if (!empty($this->allowedScriptDomains) || $this->evalScriptAllowed) { $policy .= 'script-src '; if (is_string($this->useJsNonce)) { if ($this->strictDynamicAllowed) { @@ -464,9 +450,6 @@ class EmptyContentSecurityPolicy { if (is_array($this->allowedScriptDomains)) { $policy .= implode(' ', $this->allowedScriptDomains); } - if ($this->inlineScriptAllowed) { - $policy .= ' \'unsafe-inline\''; - } if ($this->evalScriptAllowed) { $policy .= ' \'unsafe-eval\''; } diff --git a/lib/public/AppFramework/Http/FileDisplayResponse.php b/lib/public/AppFramework/Http/FileDisplayResponse.php index 41b452b5553..f194a23f1fe 100644 --- a/lib/public/AppFramework/Http/FileDisplayResponse.php +++ b/lib/public/AppFramework/Http/FileDisplayResponse.php @@ -4,6 +4,7 @@ * * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Roeland Jago Douma <roeland@famdouma.nl> + * @author Kate Döen <kate.doeen@nextcloud.com> * * @license GNU AGPL version 3 or any later version * @@ -24,31 +25,33 @@ namespace OCP\AppFramework\Http; use OCP\AppFramework\Http; +use OCP\Files\File; +use OCP\Files\SimpleFS\ISimpleFile; /** * 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 */ + /** @var File|ISimpleFile */ private $file; /** * FileDisplayResponse constructor. * - * @param \OCP\Files\File|\OCP\Files\SimpleFS\ISimpleFile $file - * @param int $statusCode - * @param array $headers + * @param File|ISimpleFile $file + * @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|ISimpleFile $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()); diff --git a/lib/public/AppFramework/Http/JSONResponse.php b/lib/public/AppFramework/Http/JSONResponse.php index d31a2761673..f6004296323 100644 --- a/lib/public/AppFramework/Http/JSONResponse.php +++ b/lib/public/AppFramework/Http/JSONResponse.php @@ -9,6 +9,7 @@ * @author Roeland Jago Douma <roeland@famdouma.nl> * @author Thomas Müller <thomas.mueller@tmit.eu> * @author Thomas Tanghus <thomas@tanghus.net> + * @author Kate Döen <kate.doeen@nextcloud.com> * * @license AGPL-3.0 * @@ -32,26 +33,30 @@ use OCP\AppFramework\Http; /** * 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(mixed $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 @@ class JSONResponse extends Response { /** * 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 @@ class JSONResponse extends Response { /** - * Used to get the set parameters - * @return array the data + * @return T the data * @since 6.0.0 */ public function getData() { diff --git a/lib/public/AppFramework/Http/NotFoundResponse.php b/lib/public/AppFramework/Http/NotFoundResponse.php index 34b74d353db..d6df0f60467 100644 --- a/lib/public/AppFramework/Http/NotFoundResponse.php +++ b/lib/public/AppFramework/Http/NotFoundResponse.php @@ -6,6 +6,7 @@ * @author Lukas Reschke <lukas@statuscode.ch> * @author Morris Jobke <hey@morrisjobke.de> * @author Roeland Jago Douma <roeland@famdouma.nl> + * @author Kate Döen <kate.doeen@nextcloud.com> * * @license AGPL-3.0 * @@ -24,18 +25,24 @@ */ namespace OCP\AppFramework\Http; +use OCP\AppFramework\Http; + /** * A generic 404 response showing an 404 error page as well to the end-user * @since 8.1.0 + * @template S of int + * @template H of array<string, mixed> + * @template-extends TemplateResponse<int, array<string, mixed>> */ class NotFoundResponse extends TemplateResponse { /** + * @param S $status + * @param H $headers * @since 8.1.0 */ - public function __construct() { - parent::__construct('core', '404', [], 'guest'); + public function __construct(int $status = Http::STATUS_NOT_FOUND, array $headers = []) { + parent::__construct('core', '404', [], 'guest', $status, $headers); $this->setContentSecurityPolicy(new ContentSecurityPolicy()); - $this->setStatus(404); } } diff --git a/lib/public/AppFramework/Http/RedirectResponse.php b/lib/public/AppFramework/Http/RedirectResponse.php index 87853391e86..b6916195954 100644 --- a/lib/public/AppFramework/Http/RedirectResponse.php +++ b/lib/public/AppFramework/Http/RedirectResponse.php @@ -7,6 +7,7 @@ * @author Roeland Jago Douma <roeland@famdouma.nl> * @author Thomas Müller <thomas.mueller@tmit.eu> * @author v1r0x <vinzenz.rosenkranz@gmail.com> + * @author Kate Döen <kate.doeen@nextcloud.com> * * @license AGPL-3.0 * @@ -30,6 +31,9 @@ use OCP\AppFramework\Http; /** * Redirects to a different URL * @since 7.0.0 + * @template S of int + * @template H of array<string, mixed> + * @template-extends Response<int, array<string, mixed>> */ class RedirectResponse extends Response { private $redirectURL; @@ -37,13 +41,14 @@ class RedirectResponse extends Response { /** * Creates a response that redirects to a url * @param string $redirectURL the url to redirect to + * @param S $status + * @param H $headers * @since 7.0.0 */ - public function __construct($redirectURL) { - parent::__construct(); + public function __construct(string $redirectURL, int $status = Http::STATUS_SEE_OTHER, array $headers = []) { + parent::__construct($status, $headers); $this->redirectURL = $redirectURL; - $this->setStatus(Http::STATUS_SEE_OTHER); $this->addHeader('Location', $redirectURL); } diff --git a/lib/public/AppFramework/Http/RedirectToDefaultAppResponse.php b/lib/public/AppFramework/Http/RedirectToDefaultAppResponse.php index ad11b53637b..7a1bfdbaf8f 100644 --- a/lib/public/AppFramework/Http/RedirectToDefaultAppResponse.php +++ b/lib/public/AppFramework/Http/RedirectToDefaultAppResponse.php @@ -7,6 +7,7 @@ declare(strict_types=1); * * @author Joas Schilling <coding@schilljs.com> * @author Roeland Jago Douma <roeland@famdouma.nl> + * @author Kate Döen <kate.doeen@nextcloud.com> * * @license GNU AGPL version 3 or any later version * @@ -26,6 +27,7 @@ declare(strict_types=1); */ namespace OCP\AppFramework\Http; +use OCP\AppFramework\Http; use OCP\IURLGenerator; /** @@ -33,17 +35,22 @@ use OCP\IURLGenerator; * * @since 16.0.0 * @deprecated 23.0.0 Use RedirectResponse() with IURLGenerator::linkToDefaultPageUrl() instead + * @template S of int + * @template H of array<string, mixed> + * @template-extends RedirectResponse<int, array<string, mixed>> */ class RedirectToDefaultAppResponse extends RedirectResponse { /** * Creates a response that redirects to the default app * + * @param S $status + * @param H $headers * @since 16.0.0 * @deprecated 23.0.0 Use RedirectResponse() with IURLGenerator::linkToDefaultPageUrl() instead */ - public function __construct() { + public function __construct(int $status = Http::STATUS_SEE_OTHER, array $headers = []) { /** @var IURLGenerator $urlGenerator */ $urlGenerator = \OC::$server->get(IURLGenerator::class); - parent::__construct($urlGenerator->linkToDefaultPageUrl()); + parent::__construct($urlGenerator->linkToDefaultPageUrl(), $status, $headers); } } diff --git a/lib/public/AppFramework/Http/Response.php b/lib/public/AppFramework/Http/Response.php index 152f8c4a3c5..d14d68d32b3 100644 --- a/lib/public/AppFramework/Http/Response.php +++ b/lib/public/AppFramework/Http/Response.php @@ -12,6 +12,7 @@ * @author Roeland Jago Douma <roeland@famdouma.nl> * @author Thomas Müller <thomas.mueller@tmit.eu> * @author Thomas Tanghus <thomas@tanghus.net> + * @author Kate Döen <kate.doeen@nextcloud.com> * * @license AGPL-3.0 * @@ -41,15 +42,15 @@ use Psr\Log\LoggerInterface; * * It handles headers, HTTP status code, last modified and ETag. * @since 6.0.0 + * @template S of int + * @template H of array<string, mixed> */ class Response { /** - * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate'] - * @var array + * Headers + * @var H */ - private $headers = [ - 'Cache-Control' => 'no-cache, no-store, must-revalidate' - ]; + private $headers; /** @@ -61,9 +62,9 @@ class Response { /** * HTTP status code - defaults to STATUS OK - * @var int + * @var S */ - private $status = Http::STATUS_OK; + private $status; /** @@ -91,15 +92,13 @@ class Response { private $throttleMetadata = []; /** + * @param S $status + * @param H $headers * @since 17.0.0 */ - public function __construct() { - /** @var IRequest $request */ - /** - * @psalm-suppress UndefinedClass - */ - $request = \OC::$server->get(IRequest::class); - $this->addHeader("X-Request-Id", $request->getId()); + public function __construct(int $status = Http::STATUS_OK, array $headers = []) { + $this->setStatus($status); + $this->setHeaders($headers); } /** @@ -231,11 +230,14 @@ class Response { /** * Set the headers - * @param array $headers value header pairs - * @return $this + * @template NewH as array<string, mixed> + * @param NewH $headers value header pairs + * @psalm-this-out static<S, NewH> + * @return static * @since 8.0.0 */ - public function setHeaders(array $headers) { + public function setHeaders(array $headers): static { + /** @psalm-suppress InvalidPropertyAssignmentValue Expected due to @psalm-this-out */ $this->headers = $headers; return $this; @@ -244,21 +246,27 @@ class Response { /** * Returns the set headers - * @return array the headers + * @return array{X-Request-Id: string, Cache-Control: string, Content-Security-Policy: string, Feature-Policy: string, X-Robots-Tag: string, Last-Modified?: string, ETag?: string, ...H} the headers * @since 6.0.0 */ public function getHeaders() { - $mergeWith = []; + /** @var IRequest $request */ + /** + * @psalm-suppress UndefinedClass + */ + $request = \OC::$server->get(IRequest::class); + $mergeWith = [ + 'X-Request-Id' => $request->getId(), + 'Cache-Control' => 'no-cache, no-store, must-revalidate', + 'Content-Security-Policy' => $this->getContentSecurityPolicy()->buildPolicy(), + 'Feature-Policy' => $this->getFeaturePolicy()->buildPolicy(), + 'X-Robots-Tag' => 'noindex, nofollow', + ]; if ($this->lastModified) { - $mergeWith['Last-Modified'] = - $this->lastModified->format(\DateTimeInterface::RFC2822); + $mergeWith['Last-Modified'] = $this->lastModified->format(\DateTimeInterface::RFC2822); } - $this->headers['Content-Security-Policy'] = $this->getContentSecurityPolicy()->buildPolicy(); - $this->headers['Feature-Policy'] = $this->getFeaturePolicy()->buildPolicy(); - $this->headers['X-Robots-Tag'] = 'noindex, nofollow'; - if ($this->ETag) { $mergeWith['ETag'] = '"' . $this->ETag . '"'; } @@ -279,11 +287,14 @@ class Response { /** * Set response status - * @param int $status a HTTP status code, see also the STATUS constants - * @return Response Reference to this object + * @template NewS as int + * @param NewS $status a HTTP status code, see also the STATUS constants + * @psalm-this-out static<NewS, H> + * @return static * @since 6.0.0 - return value was added in 7.0.0 */ - public function setStatus($status) { + public function setStatus($status): static { + /** @psalm-suppress InvalidPropertyAssignmentValue Expected due to @psalm-this-out */ $this->status = $status; return $this; @@ -338,6 +349,7 @@ class Response { /** * Get response status * @since 6.0.0 + * @return S */ public function getStatus() { return $this->status; diff --git a/lib/public/AppFramework/Http/StandaloneTemplateResponse.php b/lib/public/AppFramework/Http/StandaloneTemplateResponse.php index 35a48481333..8a39dca71e3 100644 --- a/lib/public/AppFramework/Http/StandaloneTemplateResponse.php +++ b/lib/public/AppFramework/Http/StandaloneTemplateResponse.php @@ -6,6 +6,7 @@ declare(strict_types=1); * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl> * * @author Roeland Jago Douma <roeland@famdouma.nl> + * @author Kate Döen <kate.doeen@nextcloud.com> * * @license GNU AGPL version 3 or any later version * @@ -32,6 +33,9 @@ namespace OCP\AppFramework\Http; * full nextcloud UI. Like the 2FA page, or the grant page in the login flow. * * @since 16.0.0 + * @template S of int + * @template H of array<string, mixed> + * @template-extends TemplateResponse<int, array<string, mixed>> */ class StandaloneTemplateResponse extends TemplateResponse { } diff --git a/lib/public/AppFramework/Http/StreamResponse.php b/lib/public/AppFramework/Http/StreamResponse.php index 25ad37e5d9a..14394383ba1 100644 --- a/lib/public/AppFramework/Http/StreamResponse.php +++ b/lib/public/AppFramework/Http/StreamResponse.php @@ -8,6 +8,7 @@ * @author Morris Jobke <hey@morrisjobke.de> * @author Robin Appelman <robin@icewind.nl> * @author Roeland Jago Douma <roeland@famdouma.nl> + * @author Kate Döen <kate.doeen@nextcloud.com> * * @license AGPL-3.0 * @@ -32,6 +33,9 @@ use OCP\AppFramework\Http; * Class StreamResponse * * @since 8.1.0 + * @template S of int + * @template H of array<string, mixed> + * @template-extends Response<int, array<string, mixed>> */ class StreamResponse extends Response implements ICallbackResponse { /** @var string */ @@ -39,10 +43,12 @@ class StreamResponse extends Response implements ICallbackResponse { /** * @param string|resource $filePath the path to the file or a file handle which should be streamed + * @param S $status + * @param H $headers * @since 8.1.0 */ - public function __construct($filePath) { - parent::__construct(); + public function __construct(mixed $filePath, int $status = Http::STATUS_OK, array $headers = []) { + parent::__construct($status, $headers); $this->filePath = $filePath; } diff --git a/lib/public/AppFramework/Http/StrictContentSecurityPolicy.php b/lib/public/AppFramework/Http/StrictContentSecurityPolicy.php index c62f79e8801..ed137bad930 100644 --- a/lib/public/AppFramework/Http/StrictContentSecurityPolicy.php +++ b/lib/public/AppFramework/Http/StrictContentSecurityPolicy.php @@ -32,7 +32,7 @@ namespace OCP\AppFramework\Http; * ('self') are allowed. * * Even if a value gets modified above defaults will still get appended. Please - * notice that Nextcloud ships already with sensible defaults and those policies + * note that Nextcloud ships already with sensible defaults and those policies * should require no modification at all for most use-cases. * * This class represents out strictest defaults. They may get change from release diff --git a/lib/public/AppFramework/Http/StrictEvalContentSecurityPolicy.php b/lib/public/AppFramework/Http/StrictEvalContentSecurityPolicy.php index ed799e4fd94..005b0db3dfc 100644 --- a/lib/public/AppFramework/Http/StrictEvalContentSecurityPolicy.php +++ b/lib/public/AppFramework/Http/StrictEvalContentSecurityPolicy.php @@ -26,13 +26,13 @@ declare(strict_types=1); namespace OCP\AppFramework\Http; /** - * Class StrictInlineContentSecurityPolicy is a simple helper which allows applications to + * Class StrictEvalContentSecurityPolicy is a simple helper which allows applications to * modify the Content-Security-Policy sent by Nextcloud. Per default only JavaScript, * stylesheets, images, fonts, media and connections from the same domain * ('self') are allowed. * * Even if a value gets modified above defaults will still get appended. Please - * notice that Nextcloud ships already with sensible defaults and those policies + * note that Nextcloud ships already with sensible defaults and those policies * should require no modification at all for most use-cases. * * This is a temp helper class from the default ContentSecurityPolicy to allow slow diff --git a/lib/public/AppFramework/Http/StrictInlineContentSecurityPolicy.php b/lib/public/AppFramework/Http/StrictInlineContentSecurityPolicy.php index 45b230ad9b5..aec94e8fb19 100644 --- a/lib/public/AppFramework/Http/StrictInlineContentSecurityPolicy.php +++ b/lib/public/AppFramework/Http/StrictInlineContentSecurityPolicy.php @@ -32,7 +32,7 @@ namespace OCP\AppFramework\Http; * ('self') are allowed. * * Even if a value gets modified above defaults will still get appended. Please - * notice that Nextcloud ships already with sensible defaults and those policies + * note that Nextcloud ships already with sensible defaults and those policies * should require no modification at all for most use-cases. * * This is a temp helper class from the default ContentSecurityPolicy to allow slow diff --git a/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php b/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php index 1196c90935d..def25d01c51 100644 --- a/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php +++ b/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php @@ -5,6 +5,7 @@ * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Julius Härtl <jus@bitgrid.net> * @author Roeland Jago Douma <roeland@famdouma.nl> + * @author Kate Döen <kate.doeen@nextcloud.com> * * @license GNU AGPL version 3 or any later version * @@ -25,12 +26,16 @@ namespace OCP\AppFramework\Http\Template; use InvalidArgumentException; +use OCP\AppFramework\Http; use OCP\AppFramework\Http\TemplateResponse; /** * Class PublicTemplateResponse * * @since 14.0.0 + * @template H of array<string, mixed> + * @template S of int + * @template-extends TemplateResponse<int, array<string, mixed>> */ class PublicTemplateResponse extends TemplateResponse { private $headerTitle = ''; @@ -44,10 +49,12 @@ class PublicTemplateResponse extends TemplateResponse { * @param string $appName * @param string $templateName * @param array $params + * @param S $status + * @param H $headers * @since 14.0.0 */ - public function __construct(string $appName, string $templateName, array $params = []) { - parent::__construct($appName, $templateName, $params, 'public'); + public function __construct(string $appName, string $templateName, array $params = [], $status = Http::STATUS_OK, array $headers = []) { + parent::__construct($appName, $templateName, $params, 'public', $status, $headers); \OC_Util::addScript('core', 'public/publicpage'); } diff --git a/lib/public/AppFramework/Http/TemplateResponse.php b/lib/public/AppFramework/Http/TemplateResponse.php index 23843cd21d1..0364ba10e50 100644 --- a/lib/public/AppFramework/Http/TemplateResponse.php +++ b/lib/public/AppFramework/Http/TemplateResponse.php @@ -10,6 +10,7 @@ * @author Roeland Jago Douma <roeland@famdouma.nl> * @author Thomas Müller <thomas.mueller@tmit.eu> * @author Thomas Tanghus <thomas@tanghus.net> + * @author Kate Döen <kate.doeen@nextcloud.com> * * @license AGPL-3.0 * @@ -28,9 +29,15 @@ */ namespace OCP\AppFramework\Http; +use OCP\AppFramework\Http; + /** * Response for a normal template * @since 6.0.0 + * + * @template S of int + * @template H of array<string, mixed> + * @template-extends Response<int, array<string, mixed>> */ class TemplateResponse extends Response { /** @@ -98,11 +105,12 @@ class TemplateResponse extends Response { * @param array $params an array of parameters which should be passed to the * template * @param string $renderAs how the page should be rendered, defaults to user + * @param S $status + * @param H $headers * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0 */ - public function __construct($appName, $templateName, array $params = [], - $renderAs = self::RENDER_AS_USER) { - parent::__construct(); + public function __construct(string $appName, string $templateName, array $params = [], string $renderAs = self::RENDER_AS_USER, int $status = Http::STATUS_OK, array $headers = []) { + parent::__construct($status, $headers); $this->templateName = $templateName; $this->appName = $appName; @@ -203,7 +211,6 @@ class TemplateResponse extends Response { $renderAs = $this->renderAs; } - \OCP\Util::addHeader('meta', ['name' => 'robots', 'content' => 'noindex, nofollow']); $template = new \OCP\Template($this->appName, $this->templateName, $renderAs); foreach ($this->params as $key => $value) { diff --git a/lib/public/AppFramework/Http/TextPlainResponse.php b/lib/public/AppFramework/Http/TextPlainResponse.php index 93edf704863..7bcd353e102 100644 --- a/lib/public/AppFramework/Http/TextPlainResponse.php +++ b/lib/public/AppFramework/Http/TextPlainResponse.php @@ -6,6 +6,7 @@ declare(strict_types=1); * @copyright 2021 Lukas Reschke <lukas@statuscode.ch> * * @author 2021 Lukas Reschke <lukas@statuscode.ch> + * @author Kate Döen <kate.doeen@nextcloud.com> * * @license GNU AGPL version 3 or any later version * @@ -30,6 +31,9 @@ use OCP\AppFramework\Http; /** * A renderer for text responses * @since 22.0.0 + * @template S of int + * @template H of array<string, mixed> + * @template-extends Response<int, array<string, mixed>> */ class TextPlainResponse extends Response { /** @var string */ @@ -38,14 +42,14 @@ class TextPlainResponse extends Response { /** * constructor of TextPlainResponse * @param string $text The text body - * @param int $statusCode the Http status code, defaults to 200 + * @param S $statusCode the Http status code, defaults to 200 + * @param H $headers * @since 22.0.0 */ - public function __construct(string $text = '', int $statusCode = Http::STATUS_OK) { - parent::__construct(); + public function __construct(string $text = '', int $statusCode = Http::STATUS_OK, array $headers = []) { + parent::__construct($statusCode, $headers); $this->text = $text; - $this->setStatus($statusCode); $this->addHeader('Content-Type', 'text/plain'); } diff --git a/lib/public/AppFramework/Http/TooManyRequestsResponse.php b/lib/public/AppFramework/Http/TooManyRequestsResponse.php index caf565ee954..043ae0161e9 100644 --- a/lib/public/AppFramework/Http/TooManyRequestsResponse.php +++ b/lib/public/AppFramework/Http/TooManyRequestsResponse.php @@ -6,6 +6,7 @@ declare(strict_types=1); * @copyright Copyright (c) 2020 Joas Schilling <coding@schilljs.com> * * @author Joas Schilling <coding@schilljs.com> + * @author Kate Döen <kate.doeen@nextcloud.com> * * @license GNU AGPL version 3 or any later version * @@ -26,20 +27,25 @@ declare(strict_types=1); namespace OCP\AppFramework\Http; use OCP\Template; +use OCP\AppFramework\Http; /** * A generic 429 response showing an 404 error page as well to the end-user * @since 19.0.0 + * @template S of int + * @template H of array<string, mixed> + * @template-extends Response<int, array<string, mixed>> */ class TooManyRequestsResponse extends Response { /** + * @param S $status + * @param H $headers * @since 19.0.0 */ - public function __construct() { - parent::__construct(); + public function __construct(int $status = Http::STATUS_TOO_MANY_REQUESTS, array $headers = []) { + parent::__construct($status, $headers); $this->setContentSecurityPolicy(new ContentSecurityPolicy()); - $this->setStatus(429); } /** diff --git a/lib/public/AppFramework/Http/ZipResponse.php b/lib/public/AppFramework/Http/ZipResponse.php index 23e9f1f7a94..cd7f71f858d 100644 --- a/lib/public/AppFramework/Http/ZipResponse.php +++ b/lib/public/AppFramework/Http/ZipResponse.php @@ -9,6 +9,7 @@ declare(strict_types=1); * @author Jakob Sack <mail@jakobsack.de> * @author Morris Jobke <hey@morrisjobke.de> * @author Roeland Jago Douma <roeland@famdouma.nl> + * @author Kate Döen <kate.doeen@nextcloud.com> * * @license GNU AGPL version 3 or any later version * @@ -29,12 +30,16 @@ declare(strict_types=1); namespace OCP\AppFramework\Http; use OC\Streamer; +use OCP\AppFramework\Http; use OCP\IRequest; /** * Public library to send several files in one zip archive. * * @since 15.0.0 + * @template S of int + * @template H of array<string, mixed> + * @template-extends Response<int, array<string, mixed>> */ class ZipResponse extends Response implements ICallbackResponse { /** @var array{internalName: string, resource: resource, size: int, time: int}[] Files to be added to the zip response */ @@ -44,10 +49,12 @@ class ZipResponse extends Response implements ICallbackResponse { private IRequest $request; /** + * @param S $status + * @param H $headers * @since 15.0.0 */ - public function __construct(IRequest $request, string $name = 'output') { - parent::__construct(); + public function __construct(IRequest $request, string $name = 'output', int $status = Http::STATUS_OK, array $headers = []) { + parent::__construct($status, $headers); $this->name = $name; $this->request = $request; diff --git a/lib/public/BackgroundJob/TimedJob.php b/lib/public/BackgroundJob/TimedJob.php index 9d6b599c21b..8fd8fadce4f 100644 --- a/lib/public/BackgroundJob/TimedJob.php +++ b/lib/public/BackgroundJob/TimedJob.php @@ -26,7 +26,6 @@ declare(strict_types=1); */ namespace OCP\BackgroundJob; -use OC\BackgroundJob\JobList; use OCP\ILogger; /** @@ -81,20 +80,20 @@ abstract class TimedJob extends Job { } /** - * run the job if the last run is is more than the interval ago + * Run the job if the last run is more than the interval ago * - * @param JobList $jobList + * @param IJobList $jobList * @param ILogger|null $logger * * @since 15.0.0 * @deprecated since 25.0.0 Use start() instead */ - final public function execute($jobList, ILogger $logger = null) { + final public function execute(IJobList $jobList, ILogger $logger = null) { $this->start($jobList); } /** - * Run the job if the last run is is more than the interval ago + * Run the job if the last run is more than the interval ago * * @since 25.0.0 */ diff --git a/lib/public/Comments/ICommentsManager.php b/lib/public/Comments/ICommentsManager.php index a245e5d2f20..8d7ffd164b3 100644 --- a/lib/public/Comments/ICommentsManager.php +++ b/lib/public/Comments/ICommentsManager.php @@ -61,12 +61,12 @@ interface ICommentsManager { public function get($id); /** - * returns the comment specified by the id and all it's child comments + * Returns the comment specified by the id and all it's child comments * * @param string $id * @param int $limit max number of entries to return, 0 returns all * @param int $offset the start entry - * @return array + * @return array{comment: IComment, replies: list<array{comment: IComment, replies: array<empty, empty>}>} * @since 9.0.0 * * The return array looks like this @@ -110,7 +110,7 @@ interface ICommentsManager { * @param int $offset optional, starting point * @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments * that may be returned - * @return IComment[] + * @return list<IComment> * @since 9.0.0 */ public function getForObject( @@ -129,7 +129,7 @@ interface ICommentsManager { * @param int $limit optional, number of maximum comments to be returned. if * set to 0, all comments are returned. * @param bool $includeLastKnown - * @return IComment[] + * @return list<IComment> * @since 14.0.0 * @deprecated 24.0.0 - Use getCommentsWithVerbForObjectSinceComment instead */ @@ -151,7 +151,7 @@ interface ICommentsManager { * @param int $limit optional, number of maximum comments to be returned. if * set to 0, all comments are returned. * @param bool $includeLastKnown - * @return IComment[] + * @return list<IComment> * @since 24.0.0 */ public function getCommentsWithVerbForObjectSinceComment( @@ -173,7 +173,7 @@ interface ICommentsManager { * @param string $verb Limit the verb of the comment * @param int $offset * @param int $limit - * @return IComment[] + * @return list<IComment> * @since 14.0.0 */ public function search(string $search, string $objectType, string $objectId, string $verb, int $offset, int $limit = 50): array; diff --git a/lib/public/Federation/ICloudIdManager.php b/lib/public/Federation/ICloudIdManager.php index 1612c03ba4a..52920751739 100644 --- a/lib/public/Federation/ICloudIdManager.php +++ b/lib/public/Federation/ICloudIdManager.php @@ -62,4 +62,14 @@ interface ICloudIdManager { * @since 12.0.0 */ public function isValidCloudId(string $cloudId): bool; + + /** + * remove scheme/protocol from an url + * + * @param string $url + * + * @return string + * @since 28.0.0 + */ + public function removeProtocolFromUrl(string $url): string; } diff --git a/lib/public/Files/Folder.php b/lib/public/Files/Folder.php index 912c5472fac..eb81a2098ec 100644 --- a/lib/public/Files/Folder.php +++ b/lib/public/Files/Folder.php @@ -142,6 +142,16 @@ interface Folder extends Node { public function searchByTag($tag, $userId); /** + * search for files by system tag + * + * @param string|int $tag tag name + * @param string $userId user id to ensure access on returned nodes + * @return \OCP\Files\Node[] + * @since 28.0.0 + */ + public function searchBySystemTag(string $tagName, string $userId, int $limit = 0, int $offset = 0); + + /** * get a file or folder inside the folder by it's internal id * * This method could return multiple entries. For example once the file/folder diff --git a/lib/public/Files/IRootFolder.php b/lib/public/Files/IRootFolder.php index 452c0fd3157..1fee0b3595e 100644 --- a/lib/public/Files/IRootFolder.php +++ b/lib/public/Files/IRootFolder.php @@ -26,6 +26,7 @@ namespace OCP\Files; use OC\Hooks\Emitter; use OC\User\NoUserException; +use OCP\Files\Mount\IMountPoint; /** * Interface IRootFolder @@ -55,4 +56,16 @@ interface IRootFolder extends Folder, Emitter { * @since 24.0.0 */ public function getByIdInPath(int $id, string $path); + + /** + * @return IMountPoint[] + * + * @since 28.0.0 + */ + public function getMountsIn(string $mountPoint): array; + + /** + * @since 28.0.0 + */ + public function getMount(string $mountPoint): IMountPoint; } diff --git a/lib/public/Http/Client/IClient.php b/lib/public/Http/Client/IClient.php index d692edc5b71..fb1760c25f2 100644 --- a/lib/public/Http/Client/IClient.php +++ b/lib/public/Http/Client/IClient.php @@ -44,7 +44,7 @@ interface IClient { * 'headers' => [ * 'foo' => 'bar', * ], - * 'cookies' => [' + * 'cookies' => [ * 'foo' => 'bar', * ], * 'allow_redirects' => [ @@ -69,7 +69,7 @@ interface IClient { * 'headers' => [ * 'foo' => 'bar', * ], - * 'cookies' => [' + * 'cookies' => [ * 'foo' => 'bar', * ], * 'allow_redirects' => [ @@ -99,7 +99,7 @@ interface IClient { * 'headers' => [ * 'foo' => 'bar', * ], - * 'cookies' => [' + * 'cookies' => [ * 'foo' => 'bar', * ], * 'allow_redirects' => [ @@ -129,7 +129,7 @@ interface IClient { * 'headers' => [ * 'foo' => 'bar', * ], - * 'cookies' => [' + * 'cookies' => [ * 'foo' => 'bar', * ], * 'allow_redirects' => [ @@ -159,7 +159,7 @@ interface IClient { * 'headers' => [ * 'foo' => 'bar', * ], - * 'cookies' => [' + * 'cookies' => [ * 'foo' => 'bar', * ], * 'allow_redirects' => [ @@ -178,7 +178,7 @@ interface IClient { public function delete(string $uri, array $options = []): IResponse; /** - * Sends a options request + * Sends an OPTIONS request * @param string $uri * @param array $options Array such as * 'body' => [ @@ -189,7 +189,7 @@ interface IClient { * 'headers' => [ * 'foo' => 'bar', * ], - * 'cookies' => [' + * 'cookies' => [ * 'foo' => 'bar', * ], * 'allow_redirects' => [ @@ -206,4 +206,173 @@ interface IClient { * @since 8.1.0 */ public function options(string $uri, array $options = []): IResponse; + + /** + * Sends an asynchronous GET request + * @param string $uri + * @param array $options Array such as + * 'query' => [ + * 'field' => 'abc', + * 'other_field' => '123', + * 'file_name' => fopen('/path/to/file', 'r'), + * ], + * 'headers' => [ + * 'foo' => 'bar', + * ], + * 'cookies' => [ + * 'foo' => 'bar', + * ], + * 'allow_redirects' => [ + * 'max' => 10, // allow at most 10 redirects. + * 'strict' => true, // use "strict" RFC compliant redirects. + * 'referer' => true, // add a Referer header + * 'protocols' => ['https'] // only allow https URLs + * ], + * 'sink' => '/path/to/file', // save to a file or a stream + * 'verify' => true, // bool or string to CA file + * 'debug' => true, + * @return IPromise + * @since 28.0.0 + */ + public function getAsync(string $uri, array $options = []): IPromise; + + /** + * Sends an asynchronous HEAD request + * @param string $uri + * @param array $options Array such as + * 'headers' => [ + * 'foo' => 'bar', + * ], + * 'cookies' => [ + * 'foo' => 'bar', + * ], + * 'allow_redirects' => [ + * 'max' => 10, // allow at most 10 redirects. + * 'strict' => true, // use "strict" RFC compliant redirects. + * 'referer' => true, // add a Referer header + * 'protocols' => ['https'] // only allow https URLs + * ], + * 'sink' => '/path/to/file', // save to a file or a stream + * 'verify' => true, // bool or string to CA file + * 'debug' => true, + * @return IPromise + * @since 28.0.0 + */ + public function headAsync(string $uri, array $options = []): IPromise; + + /** + * Sends an asynchronous POST request + * @param string $uri + * @param array $options Array such as + * 'body' => [ + * 'field' => 'abc', + * 'other_field' => '123', + * 'file_name' => fopen('/path/to/file', 'r'), + * ], + * 'headers' => [ + * 'foo' => 'bar', + * ], + * 'cookies' => [ + * 'foo' => 'bar', + * ], + * 'allow_redirects' => [ + * 'max' => 10, // allow at most 10 redirects. + * 'strict' => true, // use "strict" RFC compliant redirects. + * 'referer' => true, // add a Referer header + * 'protocols' => ['https'] // only allow https URLs + * ], + * 'sink' => '/path/to/file', // save to a file or a stream + * 'verify' => true, // bool or string to CA file + * 'debug' => true, + * @return IPromise + * @since 28.0.0 + */ + public function postAsync(string $uri, array $options = []): IPromise; + + /** + * Sends an asynchronous PUT request + * @param string $uri + * @param array $options Array such as + * 'body' => [ + * 'field' => 'abc', + * 'other_field' => '123', + * 'file_name' => fopen('/path/to/file', 'r'), + * ], + * 'headers' => [ + * 'foo' => 'bar', + * ], + * 'cookies' => [ + * 'foo' => 'bar', + * ], + * 'allow_redirects' => [ + * 'max' => 10, // allow at most 10 redirects. + * 'strict' => true, // use "strict" RFC compliant redirects. + * 'referer' => true, // add a Referer header + * 'protocols' => ['https'] // only allow https URLs + * ], + * 'sink' => '/path/to/file', // save to a file or a stream + * 'verify' => true, // bool or string to CA file + * 'debug' => true, + * @return IPromise + * @since 28.0.0 + */ + public function putAsync(string $uri, array $options = []): IPromise; + + /** + * Sends an asynchronous DELETE request + * @param string $uri + * @param array $options Array such as + * 'body' => [ + * 'field' => 'abc', + * 'other_field' => '123', + * 'file_name' => fopen('/path/to/file', 'r'), + * ], + * 'headers' => [ + * 'foo' => 'bar', + * ], + * 'cookies' => [ + * 'foo' => 'bar', + * ], + * 'allow_redirects' => [ + * 'max' => 10, // allow at most 10 redirects. + * 'strict' => true, // use "strict" RFC compliant redirects. + * 'referer' => true, // add a Referer header + * 'protocols' => ['https'] // only allow https URLs + * ], + * 'sink' => '/path/to/file', // save to a file or a stream + * 'verify' => true, // bool or string to CA file + * 'debug' => true, + * @return IPromise + * @since 28.0.0 + */ + public function deleteAsync(string $uri, array $options = []): IPromise; + + /** + * Sends an asynchronous OPTIONS request + * @param string $uri + * @param array $options Array such as + * 'body' => [ + * 'field' => 'abc', + * 'other_field' => '123', + * 'file_name' => fopen('/path/to/file', 'r'), + * ], + * 'headers' => [ + * 'foo' => 'bar', + * ], + * 'cookies' => [ + * 'foo' => 'bar', + * ], + * 'allow_redirects' => [ + * 'max' => 10, // allow at most 10 redirects. + * 'strict' => true, // use "strict" RFC compliant redirects. + * 'referer' => true, // add a Referer header + * 'protocols' => ['https'] // only allow https URLs + * ], + * 'sink' => '/path/to/file', // save to a file or a stream + * 'verify' => true, // bool or string to CA file + * 'debug' => true, + * @return IPromise + * @since 28.0.0 + */ + public function optionsAsync(string $uri, array $options = []): IPromise; } diff --git a/lib/public/Http/Client/IPromise.php b/lib/public/Http/Client/IPromise.php new file mode 100644 index 00000000000..29e186d0168 --- /dev/null +++ b/lib/public/Http/Client/IPromise.php @@ -0,0 +1,100 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2023, Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCP\Http\Client; + +use Exception; +use LogicException; + +/** + * A wrapper around Guzzle's PromiseInterface + * @see \GuzzleHttp\Promise\PromiseInterface + * @since 28.0.0 + */ +interface IPromise { + /** + * @since 28.0.0 + */ + public const STATE_PENDING = 'pending'; + /** + * @since 28.0.0 + */ + public const STATE_FULFILLED = 'fulfilled'; + /** + * @since 28.0.0 + */ + public const STATE_REJECTED = 'rejected'; + + /** + * Appends fulfillment and rejection handlers to the promise, and returns + * a new promise resolving to the return value of the called handler. + * + * @param ?callable(IResponse): void $onFulfilled Invoked when the promise fulfills. Gets an \OCP\Http\Client\IResponse passed in as argument + * @param ?callable(Exception): void $onRejected Invoked when the promise is rejected. Gets an \Exception passed in as argument + * + * @return IPromise + * @since 28.0.0 + */ + public function then( + ?callable $onFulfilled = null, + ?callable $onRejected = null, + ): IPromise; + + /** + * Get the state of the promise ("pending", "rejected", or "fulfilled"). + * + * The three states can be checked against the constants defined: + * STATE_PENDING, STATE_FULFILLED, and STATE_REJECTED. + * + * @return self::STATE_* + * @since 28.0.0 + */ + public function getState(): string; + + /** + * Cancels the promise if possible. + * + * @link https://github.com/promises-aplus/cancellation-spec/issues/7 + * @since 28.0.0 + */ + public function cancel(): void; + + /** + * Waits until the promise completes if possible. + * + * Pass $unwrap as true to unwrap the result of the promise, either + * returning the resolved value or throwing the rejected exception. + * + * If the promise cannot be waited on, then the promise will be rejected. + * + * @param bool $unwrap + * + * @return mixed + * + * @throws LogicException if the promise has no wait function or if the + * promise does not settle after waiting. + * @since 28.0.0 + */ + public function wait(bool $unwrap = true): mixed; +} diff --git a/lib/public/IEventSourceFactory.php b/lib/public/IEventSourceFactory.php new file mode 100644 index 00000000000..5876189cebb --- /dev/null +++ b/lib/public/IEventSourceFactory.php @@ -0,0 +1,38 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2023 Daniel Kesselberg <mail@danielkesselberg.de> + * + * @author Daniel Kesselberg <mail@danielkesselberg.de> + * + * @license AGPL-3.0-or-later + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCP; + +/** + * @since 28.0.0 + */ +interface IEventSourceFactory { + /** + * Create a new event source + * + * @return IEventSource + * @since 28.0.0 + */ + public function create(): IEventSource; +} diff --git a/lib/public/IServerContainer.php b/lib/public/IServerContainer.php index c69dab8b3c6..f438838b98e 100644 --- a/lib/public/IServerContainer.php +++ b/lib/public/IServerContainer.php @@ -396,15 +396,6 @@ interface IServerContainer extends ContainerInterface, IContainer { public function getCertificateManager(); /** - * Create a new event source - * - * @return \OCP\IEventSource - * @since 8.0.0 - * @deprecated 20.0.0 have it injected or fetch it through \Psr\Container\ContainerInterface::get - */ - public function createEventSource(); - - /** * Returns an instance of the HTTP client service * * @return \OCP\Http\Client\IClientService diff --git a/lib/public/Log/BeforeMessageLoggedEvent.php b/lib/public/Log/BeforeMessageLoggedEvent.php new file mode 100644 index 00000000000..40e929d5d39 --- /dev/null +++ b/lib/public/Log/BeforeMessageLoggedEvent.php @@ -0,0 +1,81 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2023 Robin Appelman <robin@icewind.nl> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCP\Log; + +use OCP\EventDispatcher\Event; + +/** + * Even for when a log item is being logged + * + * @since 28.0.0 + */ +class BeforeMessageLoggedEvent extends Event { + private int $level; + private string $app; + private $message; + + /** + * @param string $app + * @param int $level + * @param array $message + * @since 28.0.0 + */ + public function __construct(string $app, int $level, array $message) { + $this->level = $level; + $this->app = $app; + $this->message = $message; + } + + /** + * Get the level of the log item + * + * @return int + * @since 28.0.0 + */ + public function getLevel(): int { + return $this->level; + } + + + /** + * Get the app context of the log item + * + * @return string + * @since 28.0.0 + */ + public function getApp(): string { + return $this->app; + } + + + /** + * Get the message of the log item + * + * @return array + * @since 28.0.0 + */ + public function getMessage(): array { + return $this->message; + } +} diff --git a/lib/public/Mail/IMessage.php b/lib/public/Mail/IMessage.php index b3cc86839f1..bd96918c7ac 100644 --- a/lib/public/Mail/IMessage.php +++ b/lib/public/Mail/IMessage.php @@ -33,6 +33,36 @@ namespace OCP\Mail; */ interface IMessage { /** + * Set the subject of this message + * + * @param string $subject + * + * @return self + * @since 28.0.0 + */ + public function setSubject(string $subject): IMessage; + + /** + * Set the plain-text body of this message + * + * @param string $body + * + * @return self + * @since 28.0.0 + */ + public function setPlainBody(string $body): IMessage; + + /** + * Set the HTML body of this message. Consider also sending a plain-text body instead of only an HTML one. + * + * @param string $body + * + * @return self + * @since 28.0.0 + */ + public function setHtmlBody(string $body): IMessage; + + /** * @param IAttachment $attachment * @return IMessage * @since 13.0.0 @@ -47,7 +77,7 @@ interface IMessage { * @param string|null $contentType MIME Content-Type (e.g. text/plain or text/calendar) * * @return IMessage - * @since 26.0.0 + * @since 27.0.0 */ public function attachInline(string $body, string $name, string $contentType = null): IMessage; diff --git a/lib/public/Preview/BeforePreviewFetchedEvent.php b/lib/public/Preview/BeforePreviewFetchedEvent.php index 37da63b95a1..19048e08620 100644 --- a/lib/public/Preview/BeforePreviewFetchedEvent.php +++ b/lib/public/Preview/BeforePreviewFetchedEvent.php @@ -27,19 +27,27 @@ declare(strict_types=1); namespace OCP\Preview; use OCP\Files\Node; +use OCP\IPreview; /** * @since 25.0.1 */ class BeforePreviewFetchedEvent extends \OCP\EventDispatcher\Event { - private Node $node; - /** * @since 25.0.1 */ - public function __construct(Node $node) { + public function __construct( + private Node $node, + /** @deprecated 28.0.0 null deprecated **/ + private ?int $width = null, + /** @deprecated 28.0.0 null deprecated **/ + private ?int $height = null, + /** @deprecated 28.0.0 null deprecated **/ + private ?bool $crop = null, + /** @deprecated 28.0.0 null deprecated **/ + private ?string $mode = null, + ) { parent::__construct(); - $this->node = $node; } /** @@ -48,4 +56,33 @@ class BeforePreviewFetchedEvent extends \OCP\EventDispatcher\Event { public function getNode(): Node { return $this->node; } + + /** + * @since 28.0.0 + */ + public function getWidth(): ?int { + return $this->width; + } + + /** + * @since 28.0.0 + */ + public function getHeight(): ?int { + return $this->height; + } + + /** + * @since 28.0.0 + */ + public function isCrop(): ?bool { + return $this->crop; + } + + /** + * @since 28.0.0 + * @return null|IPreview::MODE_FILL|IPreview::MODE_COVER + */ + public function getMode(): ?string { + return $this->mode; + } } diff --git a/lib/public/SystemTag/ISystemTagManager.php b/lib/public/SystemTag/ISystemTagManager.php index 1cf7263b456..0f5c373c49f 100644 --- a/lib/public/SystemTag/ISystemTagManager.php +++ b/lib/public/SystemTag/ISystemTagManager.php @@ -38,6 +38,7 @@ interface ISystemTagManager { * Returns the tag objects matching the given tag ids. * * @param array|string $tagIds id or array of unique ids of the tag to retrieve + * @param ?IUser $user optional user to run a visibility check against for each tag * * @return ISystemTag[] array of system tags with tag id as key * @@ -45,9 +46,9 @@ interface ISystemTagManager { * @throws TagNotFoundException if at least one given tag ids did no exist * The message contains a json_encoded array of the ids that could not be found * - * @since 9.0.0 + * @since 9.0.0, optional parameter $user added in 28.0.0 */ - public function getTagsByIds($tagIds): array; + public function getTagsByIds($tagIds, ?IUser $user = null): array; /** * Returns the tag object matching the given attributes. diff --git a/lib/public/Util.php b/lib/public/Util.php index 64934c5f3ad..5bb126d26b0 100644 --- a/lib/public/Util.php +++ b/lib/public/Util.php @@ -182,7 +182,7 @@ class Util { // need separate handling if ($application !== 'core' && $file !== null - && strpos($file, 'l10n') === false) { + && !str_contains($file, 'l10n')) { self::addTranslations($application); } @@ -278,21 +278,6 @@ class Util { } /** - * Creates an absolute url for public use - * @param string $service id - * @return string the url - * @since 4.5.0 - * @deprecated 15.0.0 - use OCP\IURLGenerator - */ - public static function linkToPublic($service) { - $urlGenerator = \OC::$server->getURLGenerator(); - if ($service === 'files') { - return $urlGenerator->getAbsoluteURL('/s'); - } - return $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'public.php').'?service='.$service); - } - - /** * Returns the server host name without an eventual port number * @return string the server hostname * @since 5.0.0 @@ -611,11 +596,6 @@ class Util { if (in_array($functionName, $disabled)) { return false; } - $disabled = explode(',', $ini->get('suhosin.executor.func.blacklist') ?: ''); - $disabled = array_map('trim', $disabled); - if (in_array($functionName, $disabled)) { - return false; - } return true; } } |