|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* @author Morris Jobke <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @license GNU AGPL version 3 or any later version |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
10
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
11
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
12
|
|
|
* License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace OC\Support\Subscription; |
|
25
|
|
|
|
|
26
|
|
|
use OCP\Support\Subscription\Exception\AlreadyRegisteredException; |
|
27
|
|
|
use OCP\Support\Subscription\IRegistry; |
|
28
|
|
|
use OCP\Support\Subscription\ISubscription; |
|
29
|
|
|
use OCP\Support\Subscription\ISupportedApps; |
|
30
|
|
|
|
|
31
|
|
|
class Registry implements IRegistry { |
|
32
|
|
|
|
|
33
|
|
|
/** @var ISubscription */ |
|
34
|
|
|
private $subscription = null; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Register a subscription instance. In case it is called multiple times the |
|
38
|
|
|
* first one is used. |
|
39
|
|
|
* |
|
40
|
|
|
* @param ISubscription $subscription |
|
41
|
|
|
* @throws AlreadyRegisteredException |
|
42
|
|
|
* |
|
43
|
|
|
* @since 17.0.0 |
|
44
|
|
|
*/ |
|
45
|
|
|
public function register(ISubscription $subscription): void { |
|
46
|
|
|
if ($this->subscription !== null) { |
|
47
|
|
|
throw new AlreadyRegisteredException(); |
|
48
|
|
|
} |
|
49
|
|
|
$this->subscription = $subscription; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Fetches the list of app IDs that are supported by the subscription |
|
54
|
|
|
* |
|
55
|
|
|
* @since 17.0.0 |
|
56
|
|
|
*/ |
|
57
|
|
|
public function delegateGetSupportedApps(): array { |
|
58
|
|
|
if ($this->subscription instanceof ISupportedApps) { |
|
59
|
|
|
return $this->subscription->getSupportedApps(); |
|
60
|
|
|
} |
|
61
|
|
|
return []; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Indicates if a valid subscription is available |
|
66
|
|
|
* |
|
67
|
|
|
* @since 17.0.0 |
|
68
|
|
|
*/ |
|
69
|
|
|
public function delegateHasValidSubscription(): bool { |
|
70
|
|
|
if ($this->subscription instanceof ISubscription) { |
|
|
|
|
|
|
71
|
|
|
return $this->subscription->hasValidSubscription(); |
|
72
|
|
|
} |
|
73
|
|
|
return false; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|