aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2019-07-17 20:22:03 +0200
committerGitHub <noreply@github.com>2019-07-17 20:22:03 +0200
commit5b604eaeaba7d5ee5dd12a92f37c9e8e7519c9c2 (patch)
treea507ff70a162b7c779a62faa1f341ec025539b9f /lib/private
parent782554d2acdfd48b322753500906e8b291035250 (diff)
parent594efca1e3b936d0d86f2d80ebf366980a425713 (diff)
downloadnextcloud-server-5b604eaeaba7d5ee5dd12a92f37c9e8e7519c9c2.tar.gz
nextcloud-server-5b604eaeaba7d5ee5dd12a92f37c9e8e7519c9c2.zip
Merge pull request #15040 from nextcloud/feature/13980/push-for-deleted-notifications
Notifications overhaul
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Authentication/Listeners/RemoteWipeNotificationsListener.php2
-rw-r--r--lib/private/Authentication/Notifications/Notifier.php21
-rw-r--r--lib/private/Notification/Action.php45
-rw-r--r--lib/private/Notification/Manager.php172
-rw-r--r--lib/private/Notification/Notification.php112
-rw-r--r--lib/private/Server.php3
6 files changed, 198 insertions, 157 deletions
diff --git a/lib/private/Authentication/Listeners/RemoteWipeNotificationsListener.php b/lib/private/Authentication/Listeners/RemoteWipeNotificationsListener.php
index ffddddff1d8..57213a8a191 100644
--- a/lib/private/Authentication/Listeners/RemoteWipeNotificationsListener.php
+++ b/lib/private/Authentication/Listeners/RemoteWipeNotificationsListener.php
@@ -61,7 +61,7 @@ class RemoteWipeNotificationsListener implements IEventListener {
$notification->setApp('auth')
->setUser($token->getUID())
->setDateTime($this->timeFactory->getDateTime())
- ->setObject('token', $token->getId())
+ ->setObject('token', (string) $token->getId())
->setSubject($event, [
'name' => $token->getName(),
]);
diff --git a/lib/private/Authentication/Notifications/Notifier.php b/lib/private/Authentication/Notifications/Notifier.php
index 0aafc115b22..f76bb077a3c 100644
--- a/lib/private/Authentication/Notifications/Notifier.php
+++ b/lib/private/Authentication/Notifications/Notifier.php
@@ -42,7 +42,7 @@ class Notifier implements INotifier {
/**
* @inheritDoc
*/
- public function prepare(INotification $notification, $languageCode) {
+ public function prepare(INotification $notification, string $languageCode): INotification {
if ($notification->getApp() !== 'auth') {
// Not my app => throw
throw new InvalidArgumentException();
@@ -74,4 +74,23 @@ class Notifier implements INotifier {
}
}
+ /**
+ * Identifier of the notifier, only use [a-z0-9_]
+ *
+ * @return string
+ * @since 17.0.0
+ */
+ public function getID(): string {
+ return 'auth';
+ }
+
+ /**
+ * Human readable name describing the notifier
+ *
+ * @return string
+ * @since 17.0.0
+ */
+ public function getName(): string {
+ return $this->factory->get('lib')->t('Authentication');
+ }
}
diff --git a/lib/private/Notification/Action.php b/lib/private/Notification/Action.php
index 8dfeecb98cb..f6d6a333583 100644
--- a/lib/private/Notification/Action.php
+++ b/lib/private/Notification/Action.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -45,9 +46,6 @@ class Action implements IAction {
/** @var bool */
protected $primary;
- /**
- * Constructor
- */
public function __construct() {
$this->label = '';
$this->labelParsed = '';
@@ -62,8 +60,8 @@ class Action implements IAction {
* @throws \InvalidArgumentException if the label is invalid
* @since 8.2.0
*/
- public function setLabel($label) {
- if (!is_string($label) || $label === '' || isset($label[32])) {
+ public function setLabel(string $label): IAction {
+ if ($label === '' || isset($label[32])) {
throw new \InvalidArgumentException('The given label is invalid');
}
$this->label = $label;
@@ -74,7 +72,7 @@ class Action implements IAction {
* @return string
* @since 8.2.0
*/
- public function getLabel() {
+ public function getLabel(): string {
return $this->label;
}
@@ -84,8 +82,8 @@ class Action implements IAction {
* @throws \InvalidArgumentException if the label is invalid
* @since 8.2.0
*/
- public function setParsedLabel($label) {
- if (!is_string($label) || $label === '') {
+ public function setParsedLabel(string $label): IAction {
+ if ($label === '') {
throw new \InvalidArgumentException('The given parsed label is invalid');
}
$this->labelParsed = $label;
@@ -96,21 +94,16 @@ class Action implements IAction {
* @return string
* @since 8.2.0
*/
- public function getParsedLabel() {
+ public function getParsedLabel(): string {
return $this->labelParsed;
}
/**
* @param $primary bool
* @return $this
- * @throws \InvalidArgumentException if $primary is invalid
* @since 9.0.0
*/
- public function setPrimary($primary) {
- if (!is_bool($primary)) {
- throw new \InvalidArgumentException('The given primary option is invalid');
- }
-
+ public function setPrimary(bool $primary): IAction {
$this->primary = $primary;
return $this;
}
@@ -119,7 +112,7 @@ class Action implements IAction {
* @return bool
* @since 9.0.0
*/
- public function isPrimary() {
+ public function isPrimary(): bool {
return $this->primary;
}
@@ -130,11 +123,17 @@ class Action implements IAction {
* @throws \InvalidArgumentException if the link is invalid
* @since 8.2.0
*/
- public function setLink($link, $requestType) {
- if (!is_string($link) || $link === '' || isset($link[256])) {
+ public function setLink(string $link, string $requestType): IAction {
+ if ($link === '' || isset($link[256])) {
throw new \InvalidArgumentException('The given link is invalid');
}
- if (!in_array($requestType, ['GET', 'POST', 'PUT', 'DELETE'], true)) {
+ if (!in_array($requestType, [
+ self::TYPE_GET,
+ self::TYPE_POST,
+ self::TYPE_PUT,
+ self::TYPE_DELETE,
+ self::TYPE_WEB,
+ ], true)) {
throw new \InvalidArgumentException('The given request type is invalid');
}
$this->link = $link;
@@ -146,7 +145,7 @@ class Action implements IAction {
* @return string
* @since 8.2.0
*/
- public function getLink() {
+ public function getLink(): string {
return $this->link;
}
@@ -154,21 +153,21 @@ class Action implements IAction {
* @return string
* @since 8.2.0
*/
- public function getRequestType() {
+ public function getRequestType(): string {
return $this->requestType;
}
/**
* @return bool
*/
- public function isValid() {
+ public function isValid(): bool {
return $this->label !== '' && $this->link !== '';
}
/**
* @return bool
*/
- public function isValidParsed() {
+ public function isValidParsed(): bool {
return $this->labelParsed !== '' && $this->link !== '';
}
}
diff --git a/lib/private/Notification/Manager.php b/lib/private/Notification/Manager.php
index 4c3f7a2453c..fae0a66491e 100644
--- a/lib/private/Notification/Manager.php
+++ b/lib/private/Notification/Manager.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -25,6 +26,9 @@
namespace OC\Notification;
+use OCP\AppFramework\QueryException;
+use OCP\ILogger;
+use OCP\Notification\AlreadyProcessedException;
use OCP\Notification\IApp;
use OCP\Notification\IManager;
use OCP\Notification\INotification;
@@ -34,52 +38,39 @@ use OCP\RichObjectStrings\IValidator;
class Manager implements IManager {
/** @var IValidator */
protected $validator;
+ /** @var ILogger */
+ protected $logger;
/** @var IApp[] */
protected $apps;
+ /** @var string[] */
+ protected $appClasses;
/** @var INotifier[] */
protected $notifiers;
-
- /** @var array[] */
- protected $notifiersInfo;
-
- /** @var \Closure[] */
- protected $appsClosures;
-
- /** @var \Closure[] */
- protected $notifiersClosures;
-
- /** @var \Closure[] */
- protected $notifiersInfoClosures;
+ /** @var string[] */
+ protected $notifierClasses;
/** @var bool */
protected $preparingPushNotification;
- /**
- * Manager constructor.
- *
- * @param IValidator $validator
- */
- public function __construct(IValidator $validator) {
+ public function __construct(IValidator $validator,
+ ILogger $logger) {
$this->validator = $validator;
+ $this->logger = $logger;
$this->apps = [];
$this->notifiers = [];
- $this->notifiersInfo = [];
- $this->appsClosures = [];
- $this->notifiersClosures = [];
- $this->notifiersInfoClosures = [];
+ $this->appClasses = [];
+ $this->notifierClasses = [];
$this->preparingPushNotification = false;
}
-
/**
- * @param \Closure $service The service must implement IApp, otherwise a
+ * @param string $appClass The service must implement IApp, otherwise a
* \InvalidArgumentException is thrown later
- * @since 8.2.0
+ * @since 17.0.0
*/
- public function registerApp(\Closure $service) {
- $this->appsClosures[] = $service;
- $this->apps = [];
+ public function registerApp(string $appClass): void {
+ $this->appClasses[] = $appClass;
}
/**
@@ -87,76 +78,91 @@ class Manager implements IManager {
* \InvalidArgumentException is thrown later
* @param \Closure $info An array with the keys 'id' and 'name' containing
* the app id and the app name
+ * @deprecated 17.0.0 use registerNotifierService instead.
* @since 8.2.0 - Parameter $info was added in 9.0.0
*/
public function registerNotifier(\Closure $service, \Closure $info) {
- $this->notifiersClosures[] = $service;
- $this->notifiersInfoClosures[] = $info;
- $this->notifiers = [];
- $this->notifiersInfo = [];
+ $infoData = $info();
+ $this->logger->logException(new \InvalidArgumentException(
+ 'Notifier ' . $infoData['name'] . ' (id: ' . $infoData['id'] . ') is not considered because it is using the old way to register.'
+ ));
+ }
+
+ /**
+ * @param string $notifierService The service must implement INotifier, otherwise a
+ * \InvalidArgumentException is thrown later
+ * @since 17.0.0
+ */
+ public function registerNotifierService(string $notifierService): void {
+ $this->notifierClasses[] = $notifierService;
}
/**
* @return IApp[]
*/
protected function getApps(): array {
- if (!empty($this->apps)) {
+ if (empty($this->appClasses)) {
return $this->apps;
}
- $this->apps = [];
- foreach ($this->appsClosures as $closure) {
- $app = $closure();
+ foreach ($this->appClasses as $appClass) {
+ try {
+ $app = \OC::$server->query($appClass);
+ } catch (QueryException $e) {
+ $this->logger->logException($e, [
+ 'message' => 'Failed to load notification app class: ' . $appClass,
+ 'app' => 'notifications',
+ ]);
+ continue;
+ }
+
if (!($app instanceof IApp)) {
- throw new \InvalidArgumentException('The given notification app does not implement the IApp interface');
+ $this->logger->error('Notification app class ' . $appClass . ' is not implementing ' . IApp::class, [
+ 'app' => 'notifications',
+ ]);
+ continue;
}
+
$this->apps[] = $app;
}
+ $this->appClasses = [];
+
return $this->apps;
}
/**
* @return INotifier[]
*/
- protected function getNotifiers(): array {
- if (!empty($this->notifiers)) {
+ public function getNotifiers(): array {
+ if (empty($this->notifierClasses)) {
return $this->notifiers;
}
- $this->notifiers = [];
- foreach ($this->notifiersClosures as $closure) {
- $notifier = $closure();
- if (!($notifier instanceof INotifier)) {
- throw new \InvalidArgumentException('The given notifier does not implement the INotifier interface');
+ foreach ($this->notifierClasses as $notifierClass) {
+ try {
+ $notifier = \OC::$server->query($notifierClass);
+ } catch (QueryException $e) {
+ $this->logger->logException($e, [
+ 'message' => 'Failed to load notification notifier class: ' . $notifierClass,
+ 'app' => 'notifications',
+ ]);
+ continue;
}
- $this->notifiers[] = $notifier;
- }
- return $this->notifiers;
- }
+ if (!($notifier instanceof INotifier)) {
+ $this->logger->error('Notification notifier class ' . $notifierClass . ' is not implementing ' . INotifier::class, [
+ 'app' => 'notifications',
+ ]);
+ continue;
+ }
- /**
- * @return array[]
- */
- public function listNotifiers(): array {
- if (!empty($this->notifiersInfo)) {
- return $this->notifiersInfo;
+ $this->notifiers[] = $notifier;
}
- $this->notifiersInfo = [];
- foreach ($this->notifiersInfoClosures as $closure) {
- $notifier = $closure();
- if (!\is_array($notifier) || \count($notifier) !== 2 || !isset($notifier['id'], $notifier['name'])) {
- throw new \InvalidArgumentException('The given notifier information is invalid');
- }
- if (isset($this->notifiersInfo[$notifier['id']])) {
- throw new \InvalidArgumentException('The given notifier ID ' . $notifier['id'] . ' is already in use');
- }
- $this->notifiersInfo[$notifier['id']] = $notifier['name'];
- }
+ $this->notifierClasses = [];
- return $this->notifiersInfo;
+ return $this->notifiers;
}
/**
@@ -172,14 +178,14 @@ class Manager implements IManager {
* @since 8.2.0
*/
public function hasNotifiers(): bool {
- return !empty($this->notifiersClosures);
+ return !empty($this->notifiers) || !empty($this->notifierClasses);
}
/**
* @param bool $preparingPushNotification
* @since 14.0.0
*/
- public function setPreparingPushNotification($preparingPushNotification) {
+ public function setPreparingPushNotification(bool $preparingPushNotification): void {
$this->preparingPushNotification = $preparingPushNotification;
}
@@ -196,7 +202,7 @@ class Manager implements IManager {
* @throws \InvalidArgumentException When the notification is not valid
* @since 8.2.0
*/
- public function notify(INotification $notification) {
+ public function notify(INotification $notification): void {
if (!$notification->isValid()) {
throw new \InvalidArgumentException('The given notification is invalid');
}
@@ -212,13 +218,34 @@ class Manager implements IManager {
}
/**
+ * Identifier of the notifier, only use [a-z0-9_]
+ *
+ * @return string
+ * @since 17.0.0
+ */
+ public function getID(): string {
+ return 'core';
+ }
+
+ /**
+ * Human readable name describing the notifier
+ *
+ * @return string
+ * @since 17.0.0
+ */
+ public function getName(): string {
+ return 'core';
+ }
+
+ /**
* @param INotification $notification
* @param string $languageCode The code of the language that should be used to prepare the notification
* @return INotification
* @throws \InvalidArgumentException When the notification was not prepared by a notifier
+ * @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted
* @since 8.2.0
*/
- public function prepare(INotification $notification, $languageCode): INotification {
+ public function prepare(INotification $notification, string $languageCode): INotification {
$notifiers = $this->getNotifiers();
foreach ($notifiers as $notifier) {
@@ -226,6 +253,9 @@ class Manager implements IManager {
$notification = $notifier->prepare($notification, $languageCode);
} catch (\InvalidArgumentException $e) {
continue;
+ } catch (AlreadyProcessedException $e) {
+ $this->markProcessed($notification);
+ throw new \InvalidArgumentException('The given notification has been processed');
}
if (!($notification instanceof INotification) || !$notification->isValidParsed()) {
@@ -243,7 +273,7 @@ class Manager implements IManager {
/**
* @param INotification $notification
*/
- public function markProcessed(INotification $notification) {
+ public function markProcessed(INotification $notification): void {
$apps = $this->getApps();
foreach ($apps as $app) {
diff --git a/lib/private/Notification/Notification.php b/lib/private/Notification/Notification.php
index 47f415d15d3..e64c059db2a 100644
--- a/lib/private/Notification/Notification.php
+++ b/lib/private/Notification/Notification.php
@@ -1,5 +1,5 @@
<?php
-declare (strict_types = 1);
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -99,11 +99,6 @@ class Notification implements INotification {
/** @var bool */
protected $hasPrimaryParsedAction;
- /**
- * Constructor
- *
- * @param IValidator $richValidator
- */
public function __construct(IValidator $richValidator) {
$this->richValidator = $richValidator;
$this->app = '';
@@ -134,8 +129,8 @@ class Notification implements INotification {
* @throws \InvalidArgumentException if the app id is invalid
* @since 8.2.0
*/
- public function setApp(string $app) {
- if (trim($app) === '' || isset($app[32])) {
+ public function setApp(string $app): INotification {
+ if ($app === '' || isset($app[32])) {
throw new \InvalidArgumentException('The given app name is invalid');
}
$this->app = $app;
@@ -146,7 +141,7 @@ class Notification implements INotification {
* @return string
* @since 8.2.0
*/
- public function getApp() {
+ public function getApp(): string {
return $this->app;
}
@@ -156,8 +151,8 @@ class Notification implements INotification {
* @throws \InvalidArgumentException if the user id is invalid
* @since 8.2.0
*/
- public function setUser(string $user) {
- if (trim($user) === '' || isset($user[64])) {
+ public function setUser(string $user): INotification {
+ if ($user === '' || isset($user[64])) {
throw new \InvalidArgumentException('The given user id is invalid');
}
$this->user = $user;
@@ -168,7 +163,7 @@ class Notification implements INotification {
* @return string
* @since 8.2.0
*/
- public function getUser() {
+ public function getUser(): string {
return $this->user;
}
@@ -178,7 +173,7 @@ class Notification implements INotification {
* @throws \InvalidArgumentException if the $dateTime is invalid
* @since 9.0.0
*/
- public function setDateTime(\DateTime $dateTime) {
+ public function setDateTime(\DateTime $dateTime): INotification {
if ($dateTime->getTimestamp() === 0) {
throw new \InvalidArgumentException('The given date time is invalid');
}
@@ -190,7 +185,7 @@ class Notification implements INotification {
* @return \DateTime
* @since 9.0.0
*/
- public function getDateTime() {
+ public function getDateTime(): \DateTime {
return $this->dateTime;
}
@@ -201,13 +196,13 @@ class Notification implements INotification {
* @throws \InvalidArgumentException if the object type or id is invalid
* @since 8.2.0 - 9.0.0: Type of $id changed to string
*/
- public function setObject(string $type, $id) {
- if (trim($type) === '' || isset($type[64])) {
+ public function setObject(string $type, string $id): INotification {
+ if ($type === '' || isset($type[64])) {
throw new \InvalidArgumentException('The given object type is invalid');
}
$this->objectType = $type;
- if (!is_int($id) && (!is_string($id) || $id === '' || isset($id[64]))) {
+ if ($id === '' || isset($id[64])) {
throw new \InvalidArgumentException('The given object id is invalid');
}
$this->objectId = (string) $id;
@@ -218,7 +213,7 @@ class Notification implements INotification {
* @return string
* @since 8.2.0
*/
- public function getObjectType() {
+ public function getObjectType(): string {
return $this->objectType;
}
@@ -226,7 +221,7 @@ class Notification implements INotification {
* @return string
* @since 8.2.0 - 9.0.0: Return type changed to string
*/
- public function getObjectId() {
+ public function getObjectId(): string {
return $this->objectId;
}
@@ -237,8 +232,8 @@ class Notification implements INotification {
* @throws \InvalidArgumentException if the subject or parameters are invalid
* @since 8.2.0
*/
- public function setSubject(string $subject, array $parameters = []) {
- if (trim($subject) === '' || isset($subject[64])) {
+ public function setSubject(string $subject, array $parameters = []): INotification {
+ if ($subject === '' || isset($subject[64])) {
throw new \InvalidArgumentException('The given subject is invalid');
}
@@ -252,15 +247,15 @@ class Notification implements INotification {
* @return string
* @since 8.2.0
*/
- public function getSubject() {
+ public function getSubject(): string {
return $this->subject;
}
/**
- * @return string[]
+ * @return array
* @since 8.2.0
*/
- public function getSubjectParameters() {
+ public function getSubjectParameters(): array {
return $this->subjectParameters;
}
@@ -270,8 +265,8 @@ class Notification implements INotification {
* @throws \InvalidArgumentException if the subject is invalid
* @since 8.2.0
*/
- public function setParsedSubject(string $subject) {
- if (trim($subject) === '') {
+ public function setParsedSubject(string $subject): INotification {
+ if ($subject === '') {
throw new \InvalidArgumentException('The given parsed subject is invalid');
}
$this->subjectParsed = $subject;
@@ -282,7 +277,7 @@ class Notification implements INotification {
* @return string
* @since 8.2.0
*/
- public function getParsedSubject() {
+ public function getParsedSubject(): string {
return $this->subjectParsed;
}
@@ -293,8 +288,8 @@ class Notification implements INotification {
* @throws \InvalidArgumentException if the subject or parameters are invalid
* @since 11.0.0
*/
- public function setRichSubject(string $subject, array $parameters = []) {
- if (trim($subject) === '') {
+ public function setRichSubject(string $subject, array $parameters = []): INotification {
+ if ($subject === '') {
throw new \InvalidArgumentException('The given parsed subject is invalid');
}
@@ -308,7 +303,7 @@ class Notification implements INotification {
* @return string
* @since 11.0.0
*/
- public function getRichSubject() {
+ public function getRichSubject(): string {
return $this->subjectRich;
}
@@ -316,7 +311,7 @@ class Notification implements INotification {
* @return array[]
* @since 11.0.0
*/
- public function getRichSubjectParameters() {
+ public function getRichSubjectParameters(): array {
return $this->subjectRichParameters;
}
@@ -327,8 +322,8 @@ class Notification implements INotification {
* @throws \InvalidArgumentException if the message or parameters are invalid
* @since 8.2.0
*/
- public function setMessage(string $message, array $parameters = []) {
- if (trim($message) === '' || isset($message[64])) {
+ public function setMessage(string $message, array $parameters = []): INotification {
+ if ($message === '' || isset($message[64])) {
throw new \InvalidArgumentException('The given message is invalid');
}
@@ -342,15 +337,15 @@ class Notification implements INotification {
* @return string
* @since 8.2.0
*/
- public function getMessage() {
+ public function getMessage(): string {
return $this->message;
}
/**
- * @return string[]
+ * @return array
* @since 8.2.0
*/
- public function getMessageParameters() {
+ public function getMessageParameters(): array {
return $this->messageParameters;
}
@@ -360,8 +355,8 @@ class Notification implements INotification {
* @throws \InvalidArgumentException if the message is invalid
* @since 8.2.0
*/
- public function setParsedMessage(string $message) {
- if (trim($message) === '') {
+ public function setParsedMessage(string $message): INotification {
+ if ($message === '') {
throw new \InvalidArgumentException('The given parsed message is invalid');
}
$this->messageParsed = $message;
@@ -372,7 +367,7 @@ class Notification implements INotification {
* @return string
* @since 8.2.0
*/
- public function getParsedMessage() {
+ public function getParsedMessage(): string {
return $this->messageParsed;
}
@@ -383,8 +378,8 @@ class Notification implements INotification {
* @throws \InvalidArgumentException if the message or parameters are invalid
* @since 11.0.0
*/
- public function setRichMessage(string $message, array $parameters = []) {
- if (trim($message) === '') {
+ public function setRichMessage(string $message, array $parameters = []): INotification {
+ if ($message === '') {
throw new \InvalidArgumentException('The given parsed message is invalid');
}
@@ -398,7 +393,7 @@ class Notification implements INotification {
* @return string
* @since 11.0.0
*/
- public function getRichMessage() {
+ public function getRichMessage(): string {
return $this->messageRich;
}
@@ -406,7 +401,7 @@ class Notification implements INotification {
* @return array[]
* @since 11.0.0
*/
- public function getRichMessageParameters() {
+ public function getRichMessageParameters(): array {
return $this->messageRichParameters;
}
@@ -416,8 +411,8 @@ class Notification implements INotification {
* @throws \InvalidArgumentException if the link is invalid
* @since 8.2.0
*/
- public function setLink(string $link) {
- if (trim($link) === '' || isset($link[4000])) {
+ public function setLink(string $link): INotification {
+ if ($link === '' || isset($link[4000])) {
throw new \InvalidArgumentException('The given link is invalid');
}
$this->link = $link;
@@ -428,7 +423,7 @@ class Notification implements INotification {
* @return string
* @since 8.2.0
*/
- public function getLink() {
+ public function getLink(): string {
return $this->link;
}
@@ -438,8 +433,8 @@ class Notification implements INotification {
* @throws \InvalidArgumentException if the icon is invalid
* @since 11.0.0
*/
- public function setIcon(string $icon) {
- if (trim($icon) === '' || isset($icon[4000])) {
+ public function setIcon(string $icon): INotification {
+ if ($icon === '' || isset($icon[4000])) {
throw new \InvalidArgumentException('The given icon is invalid');
}
$this->icon = $icon;
@@ -450,7 +445,7 @@ class Notification implements INotification {
* @return string
* @since 11.0.0
*/
- public function getIcon() {
+ public function getIcon(): string {
return $this->icon;
}
@@ -458,7 +453,7 @@ class Notification implements INotification {
* @return IAction
* @since 8.2.0
*/
- public function createAction() {
+ public function createAction(): IAction {
return new Action();
}
@@ -468,7 +463,7 @@ class Notification implements INotification {
* @throws \InvalidArgumentException if the action is invalid
* @since 8.2.0
*/
- public function addAction(IAction $action) {
+ public function addAction(IAction $action): INotification {
if (!$action->isValid()) {
throw new \InvalidArgumentException('The given action is invalid');
}
@@ -489,7 +484,7 @@ class Notification implements INotification {
* @return IAction[]
* @since 8.2.0
*/
- public function getActions() {
+ public function getActions(): array {
return $this->actions;
}
@@ -499,7 +494,7 @@ class Notification implements INotification {
* @throws \InvalidArgumentException if the action is invalid
* @since 8.2.0
*/
- public function addParsedAction(IAction $action) {
+ public function addParsedAction(IAction $action): INotification {
if (!$action->isValidParsed()) {
throw new \InvalidArgumentException('The given parsed action is invalid');
}
@@ -524,7 +519,7 @@ class Notification implements INotification {
* @return IAction[]
* @since 8.2.0
*/
- public function getParsedActions() {
+ public function getParsedActions(): array {
return $this->actionsParsed;
}
@@ -532,7 +527,7 @@ class Notification implements INotification {
* @return bool
* @since 8.2.0
*/
- public function isValid() {
+ public function isValid(): bool {
return
$this->isValidCommon()
&&
@@ -544,7 +539,7 @@ class Notification implements INotification {
* @return bool
* @since 8.2.0
*/
- public function isValidParsed() {
+ public function isValidParsed(): bool {
if ($this->getRichSubject() !== '' || !empty($this->getRichSubjectParameters())) {
try {
$this->richValidator->validate($this->getRichSubject(), $this->getRichSubjectParameters());
@@ -568,10 +563,7 @@ class Notification implements INotification {
;
}
- /**
- * @return bool
- */
- protected function isValidCommon() {
+ protected function isValidCommon(): bool {
return
$this->getApp() !== ''
&&
diff --git a/lib/private/Server.php b/lib/private/Server.php
index ccdb31c3e82..64180f1cd7c 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -900,7 +900,8 @@ class Server extends ServerContainer implements IServerContainer {
});
$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
return new Manager(
- $c->query(IValidator::class)
+ $c->query(IValidator::class),
+ $c->getLogger()
);
});
$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);