diff options
author | Joas Schilling <nickvergessen@owncloud.com> | 2016-01-21 09:49:37 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2016-01-22 08:47:21 +0100 |
commit | 3cca8498cbbd4f04fea3db06976707fbfa13c7aa (patch) | |
tree | c7886cf2892395f0b09f2a908d0ced2f78492b36 /lib/private/notification/manager.php | |
parent | 50b303f3add4cc7ff8747f0e0fc4d0ac885fcd76 (diff) | |
download | nextcloud-server-3cca8498cbbd4f04fea3db06976707fbfa13c7aa.tar.gz nextcloud-server-3cca8498cbbd4f04fea3db06976707fbfa13c7aa.zip |
Make it possible to get a list of notifiers for a potential settings page
Diffstat (limited to 'lib/private/notification/manager.php')
-rw-r--r-- | lib/private/notification/manager.php | 45 |
1 files changed, 40 insertions, 5 deletions
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 */ |