1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) 2019, Thomas Citharel |
5
|
|
|
* @copyright Copyright (c) 2019, Georg Ehrke |
6
|
|
|
* |
7
|
|
|
* @author Thomas Citharel <[email protected]> |
8
|
|
|
* @author Georg Ehrke <[email protected]> |
9
|
|
|
* |
10
|
|
|
* @license AGPL-3.0 |
11
|
|
|
* |
12
|
|
|
* This code is free software: you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
14
|
|
|
* as published by the Free Software Foundation. |
15
|
|
|
* |
16
|
|
|
* This program is distributed in the hope that it will be useful, |
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19
|
|
|
* GNU Affero General Public License for more details. |
20
|
|
|
* |
21
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
23
|
|
|
* |
24
|
|
|
*/ |
25
|
|
|
namespace OCA\DAV\CalDAV\Reminder; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Class NotificationProviderManager |
29
|
|
|
* |
30
|
|
|
* @package OCA\DAV\CalDAV\Reminder |
31
|
|
|
*/ |
32
|
|
|
class NotificationProviderManager { |
33
|
|
|
|
34
|
|
|
/** @var INotificationProvider[] */ |
35
|
|
|
private $providers = []; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Checks whether a provider for a given ACTION exists |
39
|
|
|
* |
40
|
|
|
* @param string $type |
41
|
|
|
* @return bool |
42
|
|
|
*/ |
43
|
|
|
public function hasProvider(string $type):bool { |
44
|
|
|
return (\in_array($type, ReminderService::REMINDER_TYPES, true) |
45
|
|
|
&& isset($this->providers[$type])); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get provider for a given ACTION |
50
|
|
|
* |
51
|
|
|
* @param string $type |
52
|
|
|
* @return INotificationProvider |
53
|
|
|
* @throws NotificationProvider\ProviderNotAvailableException |
54
|
|
|
* @throws NotificationTypeDoesNotExistException |
55
|
|
|
*/ |
56
|
|
|
public function getProvider(string $type):INotificationProvider { |
57
|
|
|
if (in_array($type, ReminderService::REMINDER_TYPES, true)) { |
58
|
|
|
if (isset($this->providers[$type])) { |
59
|
|
|
return $this->providers[$type]; |
60
|
|
|
} |
61
|
|
|
throw new NotificationProvider\ProviderNotAvailableException($type); |
62
|
|
|
} |
63
|
|
|
throw new NotificationTypeDoesNotExistException($type); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Registers a new provider |
68
|
|
|
* |
69
|
|
|
* @param string $providerClassName |
70
|
|
|
* @throws \OCP\AppFramework\QueryException |
71
|
|
|
*/ |
72
|
|
|
public function registerProvider(string $providerClassName):void { |
73
|
|
|
$provider = \OC::$server->query($providerClassName); |
74
|
|
|
|
75
|
|
|
if (!$provider instanceof INotificationProvider) { |
76
|
|
|
throw new \InvalidArgumentException('Invalid notification provider registered'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$this->providers[$provider::NOTIFICATION_TYPE] = $provider; |
|
|
|
|
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|