diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-22 10:24:46 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-22 10:24:46 +0100 |
commit | e2e5eedb40a15ef3a6971e2145abec24873c4400 (patch) | |
tree | af99d19fd668a69504e86f0f45e97566b57099a9 /lib/private | |
parent | 67c79faae07aec79cc56456e0b666cb9a875f11f (diff) | |
parent | 3cca8498cbbd4f04fea3db06976707fbfa13c7aa (diff) | |
download | nextcloud-server-e2e5eedb40a15ef3a6971e2145abec24873c4400.tar.gz nextcloud-server-e2e5eedb40a15ef3a6971e2145abec24873c4400.zip |
Merge pull request #21824 from owncloud/list-of-notifiers
Make it possible to get a list of notifiers for a potential settings …
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/notification/imanager.php | 12 | ||||
-rw-r--r-- | lib/private/notification/manager.php | 45 |
2 files changed, 50 insertions, 7 deletions
diff --git a/lib/private/notification/imanager.php b/lib/private/notification/imanager.php index 0e9504a1f6e..2f8e3ba39fc 100644 --- a/lib/private/notification/imanager.php +++ b/lib/private/notification/imanager.php @@ -43,10 +43,18 @@ interface IManager extends IApp, INotifier { /** * @param \Closure $service The service must implement INotifier, otherwise a * \InvalidArgumentException is thrown later + * @param \Closure $info An array with the keys 'id' and 'name' containing + * the app id and the app name * @return null - * @since 8.2.0 + * @since 8.2.0 - Parameter $info was added in 9.0.0 + */ + public function registerNotifier(\Closure $service, \Closure $info); + + /** + * @return array App ID => App Name + * @since 9.0.0 */ - public function registerNotifier(\Closure $service); + public function listNotifiers(); /** * @return INotification diff --git a/lib/private/notification/manager.php b/lib/private/notification/manager.php index a8f1ec349ce..239b5bfe5c7 100644 --- a/lib/private/notification/manager.php +++ b/lib/private/notification/manager.php @@ -29,17 +29,25 @@ class Manager implements IManager { /** @var INotifier */ protected $notifiers; - /** @var \Closure */ + /** @var array[] */ + protected $notifiersInfo; + + /** @var \Closure[] */ protected $appsClosures; - /** @var \Closure */ + /** @var \Closure[] */ protected $notifiersClosures; + /** @var \Closure[] */ + protected $notifiersInfoClosures; + public function __construct() { $this->apps = []; $this->notifiers = []; + $this->notifiersInfo = []; $this->appsClosures = []; $this->notifiersClosures = []; + $this->notifiersInfoClosures = []; } /** @@ -56,12 +64,16 @@ class Manager implements IManager { /** * @param \Closure $service The service must implement INotifier, otherwise a * \InvalidArgumentException is thrown later + * @param \Closure $info An array with the keys 'id' and 'name' containing + * the app id and the app name * @return null - * @since 8.2.0 + * @since 8.2.0 - Parameter $info was added in 9.0.0 */ - public function registerNotifier(\Closure $service) { + public function registerNotifier(\Closure $service, \Closure $info) { $this->notifiersClosures[] = $service; + $this->notifiersInfoClosures[] = $info; $this->notifiers = []; + $this->notifiersInfo = []; } /** @@ -96,7 +108,7 @@ class Manager implements IManager { foreach ($this->notifiersClosures as $closure) { $notifier = $closure(); if (!($notifier instanceof INotifier)) { - throw new \InvalidArgumentException('The given notification app does not implement the INotifier interface'); + throw new \InvalidArgumentException('The given notifier does not implement the INotifier interface'); } $this->notifiers[] = $notifier; } @@ -105,6 +117,29 @@ class Manager implements IManager { } /** + * @return array[] + */ + public function listNotifiers() { + if (!empty($this->notifiersInfo)) { + return $this->notifiersInfo; + } + + $this->notifiersInfo = []; + foreach ($this->notifiersInfoClosures as $closure) { + $notifier = $closure(); + if (!is_array($notifier) || sizeof($notifier) !== 2 || !isset($notifier['id']) || !isset($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']; + } + + return $this->notifiersInfo; + } + + /** * @return INotification * @since 8.2.0 */ |