Allow to register Providers

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2016-11-04 11:33:33 +01:00
parent 72f0d9981e
commit b2248efd75
No known key found for this signature in database
GPG Key ID: E166FD8976B3BAC8
6 changed files with 104 additions and 6 deletions

View 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)) {

View 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;

View 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));

View 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);
}
}
}
/**

View 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

View File

@ -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);
}