]> source.dussan.org Git - nextcloud-server.git/commitdiff
Allow to register Providers
authorJoas Schilling <coding@schilljs.com>
Fri, 4 Nov 2016 10:33:33 +0000 (11:33 +0100)
committerJoas Schilling <coding@schilljs.com>
Wed, 16 Nov 2016 08:25:45 +0000 (09:25 +0100)
Signed-off-by: Joas Schilling <coding@schilljs.com>
lib/private/Activity/Event.php
lib/private/Activity/Manager.php
lib/private/App/InfoParser.php
lib/private/legacy/app.php
lib/public/Activity/IManager.php
lib/public/Activity/IProvider.php [new file with mode: 0644]

index a830cc4857ec314c5669da0a79f1a86a0ca786a8..73bde7f19b2f705f652f1b46e766e42c83ddd0bb 100644 (file)
@@ -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)) {
index c0e75b12091691398f676ff1f43cfb0bb12da0df..04a8dd96a45c31e7979119c6ba8c111a20523454 100644 (file)
@@ -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;
@@ -312,6 +313,40 @@ class Manager implements IManager {
                throw new \InvalidArgumentException('Requested filter does not exist');
        }
 
+       /** @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;
 
index 6fc1ef47b09485fcdbd3a82511f9f277fe889935..47ce28e6e987dc3c345f76b73cf51dc05e108d57 100644 (file)
@@ -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));
index 156985d0c5a92ffdf4ecea4ac78113fdce174b45..33b18c0c6a2ff2ec4afd5f35453e1a8b2463aeb3 100644 (file)
@@ -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);
+                       }
+               }
        }
 
        /**
index ded83bcc922b80b813291672690c9e6d4f26b9b9..48071729ed16ca7f2770a27f6170afdc18dd3764 100644 (file)
@@ -144,6 +144,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
diff --git a/lib/public/Activity/IProvider.php b/lib/public/Activity/IProvider.php
new file mode 100644 (file)
index 0000000..6e4b9b1
--- /dev/null
@@ -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);
+}