diff options
author | Joas Schilling <coding@schilljs.com> | 2016-11-04 11:33:33 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2016-11-16 09:25:45 +0100 |
commit | b2248efd75e1a1b56624a12d37f4828ea30d32f8 (patch) | |
tree | ae5bad619fbff3a4e7c2529fde7f9ed7b075feaf | |
parent | 72f0d9981eca7b1be5832ea2d1a0cbd9526e85a4 (diff) | |
download | nextcloud-server-b2248efd75e1a1b56624a12d37f4828ea30d32f8.tar.gz nextcloud-server-b2248efd75e1a1b56624a12d37f4828ea30d32f8.zip |
Allow to register Providers
Signed-off-by: Joas Schilling <coding@schilljs.com>
-rw-r--r-- | lib/private/Activity/Event.php | 12 | ||||
-rw-r--r-- | lib/private/Activity/Manager.php | 35 | ||||
-rw-r--r-- | lib/private/App/InfoParser.php | 6 | ||||
-rw-r--r-- | lib/private/legacy/app.php | 5 | ||||
-rw-r--r-- | lib/public/Activity/IManager.php | 13 | ||||
-rw-r--r-- | lib/public/Activity/IProvider.php | 39 |
6 files changed, 104 insertions, 6 deletions
diff --git a/lib/private/Activity/Event.php b/lib/private/Activity/Event.php index a830cc4857e..73bde7f19b2 100644 --- a/lib/private/Activity/Event.php +++ b/lib/private/Activity/Event.php @@ -158,8 +158,8 @@ class Event implements IEvent { * @since 8.2.0 */ public function setAuthor($author) { - if (!is_string($author) || $author === '' || isset($author[64])) { - throw new \InvalidArgumentException('The given author user is invalid'); + if (!is_string($author) || isset($author[64])) { + throw new \InvalidArgumentException('The given author user is invalid'. serialize($author)); } $this->author = (string) $author; return $this; @@ -205,7 +205,7 @@ class Event implements IEvent { * @since 8.2.0 */ public function setSubject($subject, array $parameters = []) { - if (!is_string($subject) || $subject === '' || isset($subject[255])) { + if (!is_string($subject) || isset($subject[255])) { throw new \InvalidArgumentException('The given subject is invalid'); } $this->subject = (string) $subject; @@ -325,7 +325,7 @@ class Event implements IEvent { * @since 9.2.0 */ public function setParsedMessage($message) { - if (!is_string($message) || $message === '') { + if (!is_string($message)) { throw new \InvalidArgumentException('The given parsed message is invalid'); } $this->messageParsed = $message; @@ -348,7 +348,7 @@ class Event implements IEvent { * @since 9.2.0 */ public function setRichMessage($message, array $parameters = []) { - if (!is_string($message) || $message === '') { + if (!is_string($message)) { throw new \InvalidArgumentException('The given parsed message is invalid'); } $this->messageRich = $message; @@ -388,7 +388,7 @@ class Event implements IEvent { * @since 8.2.0 */ public function setObject($objectType, $objectId, $objectName = '') { - if (!is_string($objectType) || $objectType === '' || isset($objectType[255])) { + if (!is_string($objectType) || isset($objectType[255])) { throw new \InvalidArgumentException('The given object type is invalid'); } if (!is_int($objectId)) { diff --git a/lib/private/Activity/Manager.php b/lib/private/Activity/Manager.php index c0e75b12091..04a8dd96a45 100644 --- a/lib/private/Activity/Manager.php +++ b/lib/private/Activity/Manager.php @@ -30,6 +30,7 @@ use OCP\Activity\IEvent; use OCP\Activity\IExtension; use OCP\Activity\IFilter; use OCP\Activity\IManager; +use OCP\Activity\IProvider; use OCP\Activity\ISetting; use OCP\IConfig; use OCP\IRequest; @@ -313,6 +314,40 @@ class Manager implements IManager { } /** @var string[] */ + protected $providerClasses; + + /** @var IProvider[] */ + protected $providers; + + /** + * @param string $provider Class must implement OCA\Activity\IProvider + * @return void + */ + public function registerProvider($provider) { + $this->providerClasses[$provider] = false; + } + + /** + * @return IProvider[] + * @throws \InvalidArgumentException + */ + public function getProviders() { + foreach ($this->providerClasses as $class => $false) { + /** @var IProvider $provider */ + $provider = \OC::$server->query($class); + + if (!$provider instanceof IProvider) { + throw new \InvalidArgumentException('Invalid activity provider registered'); + } + + $this->providers[] = $provider; + + unset($this->providerClasses[$class]); + } + return $this->providers; + } + + /** @var string[] */ protected $settingsClasses; /** @var ISetting[] */ diff --git a/lib/private/App/InfoParser.php b/lib/private/App/InfoParser.php index 6fc1ef47b09..47ce28e6e98 100644 --- a/lib/private/App/InfoParser.php +++ b/lib/private/App/InfoParser.php @@ -119,6 +119,9 @@ class InfoParser { if (!array_key_exists('settings', $array['activity'])) { $array['activity']['settings'] = []; } + if (!array_key_exists('providers', $array['activity'])) { + $array['activity']['providers'] = []; + } if (array_key_exists('types', $array)) { if (is_array($array['types'])) { @@ -159,6 +162,9 @@ class InfoParser { if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) { $array['activity']['settings'] = $array['activity']['settings']['setting']; } + if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) { + $array['activity']['providers'] = $array['activity']['providers']['provider']; + } if(!is_null($this->cache)) { $this->cache->set($fileCacheKey, json_encode($array)); diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index 156985d0c5a..33b18c0c6a2 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -174,6 +174,11 @@ class OC_App { \OC::$server->getActivityManager()->registerSetting($setting); } } + if (!empty($info['activity']['providers'])) { + foreach ($info['activity']['providers'] as $provider) { + \OC::$server->getActivityManager()->registerProvider($provider); + } + } } /** diff --git a/lib/public/Activity/IManager.php b/lib/public/Activity/IManager.php index ded83bcc922..48071729ed1 100644 --- a/lib/public/Activity/IManager.php +++ b/lib/public/Activity/IManager.php @@ -145,6 +145,19 @@ interface IManager { public function getSettings(); /** + * @param string $provider Class must implement OCA\Activity\IProvider + * @return void + * @since 9.2.0 + */ + public function registerProvider($provider); + + /** + * @return IProvider[] + * @since 9.2.0 + */ + public function getProviders(); + + /** * @param string $id * @return ISetting * @throws \InvalidArgumentException when the setting was not found diff --git a/lib/public/Activity/IProvider.php b/lib/public/Activity/IProvider.php new file mode 100644 index 00000000000..6e4b9b16271 --- /dev/null +++ b/lib/public/Activity/IProvider.php @@ -0,0 +1,39 @@ +<?php +/** + * @copyright Copyright (c) 2016 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\Activity; + +/** + * Interface IProvider + * + * @package OCP\Activity + * @since 9.2.0 + */ +interface IProvider { + /** + * @param IEvent $event + * @param IEvent|null $previousEvent + * @return IEvent + * @throws \InvalidArgumentException + * @since 9.2.0 + */ + public function parse(IEvent $event, IEvent $previousEvent = null); +} |