From 28d8d15a98df5adeec970b0cfc6fb50937aca8e2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 13 Jul 2018 10:11:41 +0200 Subject: [PATCH 1/2] Allow notifiers to know whether we are preparing push notifications Signed-off-by: Joas Schilling --- lib/private/Notification/Manager.php | 20 ++++++++++++++++++++ lib/public/Notification/IManager.php | 12 ++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/private/Notification/Manager.php b/lib/private/Notification/Manager.php index bf0e8abadb..69c24e4f9e 100644 --- a/lib/private/Notification/Manager.php +++ b/lib/private/Notification/Manager.php @@ -53,6 +53,9 @@ class Manager implements IManager { /** @var \Closure[] */ protected $notifiersInfoClosures; + /** @var bool */ + protected $preparingPushNotification; + /** * Manager constructor. * @@ -66,6 +69,7 @@ class Manager implements IManager { $this->appsClosures = []; $this->notifiersClosures = []; $this->notifiersInfoClosures = []; + $this->preparingPushNotification = false; } /** @@ -171,6 +175,22 @@ class Manager implements IManager { return !empty($this->notifiersClosures); } + /** + * @param bool $preparingPushNotification + * @since 14.0.0 + */ + public function setPreparingPushNotification($preparingPushNotification) { + $this->preparingPushNotification = $preparingPushNotification; + } + + /** + * @return bool + * @since 14.0.0 + */ + public function isPreparingPushNotification(): bool { + return $this->preparingPushNotification; + } + /** * @param INotification $notification * @throws \InvalidArgumentException When the notification is not valid diff --git a/lib/public/Notification/IManager.php b/lib/public/Notification/IManager.php index cbc48142cb..003e5f1bad 100644 --- a/lib/public/Notification/IManager.php +++ b/lib/public/Notification/IManager.php @@ -62,4 +62,16 @@ interface IManager extends IApp, INotifier { * @since 9.0.0 */ public function hasNotifiers(); + + /** + * @param bool $preparingPushNotification + * @since 14.0.0 + */ + public function setPreparingPushNotification($preparingPushNotification); + + /** + * @return bool + * @since 14.0.0 + */ + public function isPreparingPushNotification(); } From 79b540ecc39202154d2374a96a1d255091b39f22 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 13 Jul 2018 10:13:49 +0200 Subject: [PATCH 2/2] Add return types and fully qualified function calls Signed-off-by: Joas Schilling --- lib/private/Notification/Manager.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/private/Notification/Manager.php b/lib/private/Notification/Manager.php index 69c24e4f9e..4c3f7a2453 100644 --- a/lib/private/Notification/Manager.php +++ b/lib/private/Notification/Manager.php @@ -99,7 +99,7 @@ class Manager implements IManager { /** * @return IApp[] */ - protected function getApps() { + protected function getApps(): array { if (!empty($this->apps)) { return $this->apps; } @@ -119,7 +119,7 @@ class Manager implements IManager { /** * @return INotifier[] */ - protected function getNotifiers() { + protected function getNotifiers(): array { if (!empty($this->notifiers)) { return $this->notifiers; } @@ -139,7 +139,7 @@ class Manager implements IManager { /** * @return array[] */ - public function listNotifiers() { + public function listNotifiers(): array { if (!empty($this->notifiersInfo)) { return $this->notifiersInfo; } @@ -147,7 +147,7 @@ class Manager implements IManager { $this->notifiersInfo = []; foreach ($this->notifiersInfoClosures as $closure) { $notifier = $closure(); - if (!is_array($notifier) || count($notifier) !== 2 || !isset($notifier['id']) || !isset($notifier['name'])) { + 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']])) { @@ -163,7 +163,7 @@ class Manager implements IManager { * @return INotification * @since 8.2.0 */ - public function createNotification() { + public function createNotification(): INotification { return new Notification($this->validator); } @@ -171,7 +171,7 @@ class Manager implements IManager { * @return bool * @since 8.2.0 */ - public function hasNotifiers() { + public function hasNotifiers(): bool { return !empty($this->notifiersClosures); } @@ -218,7 +218,7 @@ class Manager implements IManager { * @throws \InvalidArgumentException When the notification was not prepared by a notifier * @since 8.2.0 */ - public function prepare(INotification $notification, $languageCode) { + public function prepare(INotification $notification, $languageCode): INotification { $notifiers = $this->getNotifiers(); foreach ($notifiers as $notifier) { @@ -255,7 +255,7 @@ class Manager implements IManager { * @param INotification $notification * @return int */ - public function getCount(INotification $notification) { + public function getCount(INotification $notification): int { $apps = $this->getApps(); $count = 0;