@@ -34,47 +34,47 @@ |
||
34 | 34 | */ |
35 | 35 | interface IRegistry { |
36 | 36 | |
37 | - /** |
|
38 | - * Register a subscription instance. In case it is called multiple times an |
|
39 | - * exception is thrown |
|
40 | - * |
|
41 | - * @param ISubscription $subscription |
|
42 | - * @throws AlreadyRegisteredException |
|
43 | - * |
|
44 | - * @since 17.0.0 |
|
45 | - * @deprecated 20.0.0 use registerService |
|
46 | - */ |
|
47 | - public function register(ISubscription $subscription): void; |
|
37 | + /** |
|
38 | + * Register a subscription instance. In case it is called multiple times an |
|
39 | + * exception is thrown |
|
40 | + * |
|
41 | + * @param ISubscription $subscription |
|
42 | + * @throws AlreadyRegisteredException |
|
43 | + * |
|
44 | + * @since 17.0.0 |
|
45 | + * @deprecated 20.0.0 use registerService |
|
46 | + */ |
|
47 | + public function register(ISubscription $subscription): void; |
|
48 | 48 | |
49 | - /** |
|
50 | - * Register a subscription handler. The service has to implement the ISubscription interface. |
|
51 | - * In case this is called multiple times an exception is thrown. |
|
52 | - * |
|
53 | - * @param string $subscriptionService |
|
54 | - * @throws AlreadyRegisteredException |
|
55 | - * |
|
56 | - * @since 20.0.0 |
|
57 | - */ |
|
58 | - public function registerService(string $subscriptionService): void; |
|
49 | + /** |
|
50 | + * Register a subscription handler. The service has to implement the ISubscription interface. |
|
51 | + * In case this is called multiple times an exception is thrown. |
|
52 | + * |
|
53 | + * @param string $subscriptionService |
|
54 | + * @throws AlreadyRegisteredException |
|
55 | + * |
|
56 | + * @since 20.0.0 |
|
57 | + */ |
|
58 | + public function registerService(string $subscriptionService): void; |
|
59 | 59 | |
60 | - /** |
|
61 | - * Fetches the list of app IDs that are supported by the subscription |
|
62 | - * |
|
63 | - * @since 17.0.0 |
|
64 | - */ |
|
65 | - public function delegateGetSupportedApps(): array; |
|
60 | + /** |
|
61 | + * Fetches the list of app IDs that are supported by the subscription |
|
62 | + * |
|
63 | + * @since 17.0.0 |
|
64 | + */ |
|
65 | + public function delegateGetSupportedApps(): array; |
|
66 | 66 | |
67 | - /** |
|
68 | - * Indicates if a valid subscription is available |
|
69 | - * |
|
70 | - * @since 17.0.0 |
|
71 | - */ |
|
72 | - public function delegateHasValidSubscription(): bool; |
|
67 | + /** |
|
68 | + * Indicates if a valid subscription is available |
|
69 | + * |
|
70 | + * @since 17.0.0 |
|
71 | + */ |
|
72 | + public function delegateHasValidSubscription(): bool; |
|
73 | 73 | |
74 | - /** |
|
75 | - * Indicates if the subscription has extended support |
|
76 | - * |
|
77 | - * @since 17.0.0 |
|
78 | - */ |
|
79 | - public function delegateHasExtendedSupport(): bool; |
|
74 | + /** |
|
75 | + * Indicates if the subscription has extended support |
|
76 | + * |
|
77 | + * @since 17.0.0 |
|
78 | + */ |
|
79 | + public function delegateHasExtendedSupport(): bool; |
|
80 | 80 | } |
@@ -37,98 +37,98 @@ |
||
37 | 37 | |
38 | 38 | class Registry implements IRegistry { |
39 | 39 | |
40 | - /** @var ISubscription */ |
|
41 | - private $subscription = null; |
|
42 | - |
|
43 | - /** @var string */ |
|
44 | - private $subscriptionService = null; |
|
45 | - |
|
46 | - /** @var IConfig */ |
|
47 | - private $config; |
|
48 | - |
|
49 | - /** @var IServerContainer */ |
|
50 | - private $container; |
|
51 | - |
|
52 | - public function __construct(IConfig $config, IServerContainer $container) { |
|
53 | - $this->config = $config; |
|
54 | - $this->container = $container; |
|
55 | - } |
|
56 | - |
|
57 | - private function getSubscription(): ?ISubscription { |
|
58 | - if ($this->subscription === null && $this->subscriptionService !== null) { |
|
59 | - try { |
|
60 | - $this->subscription = $this->container->query($this->subscriptionService); |
|
61 | - } catch (QueryException $e) { |
|
62 | - // Ignore this |
|
63 | - } |
|
64 | - } |
|
65 | - |
|
66 | - return $this->subscription; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Register a subscription instance. In case it is called multiple times the |
|
71 | - * first one is used. |
|
72 | - * |
|
73 | - * @param ISubscription $subscription |
|
74 | - * @throws AlreadyRegisteredException |
|
75 | - * |
|
76 | - * @since 17.0.0 |
|
77 | - */ |
|
78 | - public function register(ISubscription $subscription): void { |
|
79 | - if ($this->subscription !== null || $this->subscriptionService !== null) { |
|
80 | - throw new AlreadyRegisteredException(); |
|
81 | - } |
|
82 | - $this->subscription = $subscription; |
|
83 | - } |
|
84 | - |
|
85 | - public function registerService(string $subscriptionService): void { |
|
86 | - if ($this->subscription !== null || $this->subscriptionService !== null) { |
|
87 | - throw new AlreadyRegisteredException(); |
|
88 | - } |
|
89 | - |
|
90 | - $this->subscriptionService = $subscriptionService; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Fetches the list of app IDs that are supported by the subscription |
|
96 | - * |
|
97 | - * @since 17.0.0 |
|
98 | - */ |
|
99 | - public function delegateGetSupportedApps(): array { |
|
100 | - if ($this->getSubscription() instanceof ISupportedApps) { |
|
101 | - return $this->getSubscription()->getSupportedApps(); |
|
102 | - } |
|
103 | - return []; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Indicates if a valid subscription is available |
|
108 | - * |
|
109 | - * @since 17.0.0 |
|
110 | - */ |
|
111 | - public function delegateHasValidSubscription(): bool { |
|
112 | - // Allow overwriting this manually for environments where the subscription information cannot be fetched |
|
113 | - if ($this->config->getSystemValueBool('has_valid_subscription')) { |
|
114 | - return true; |
|
115 | - } |
|
116 | - |
|
117 | - if ($this->getSubscription() instanceof ISubscription) { |
|
118 | - return $this->getSubscription()->hasValidSubscription(); |
|
119 | - } |
|
120 | - return false; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Indicates if the subscription has extended support |
|
125 | - * |
|
126 | - * @since 17.0.0 |
|
127 | - */ |
|
128 | - public function delegateHasExtendedSupport(): bool { |
|
129 | - if ($this->getSubscription() instanceof ISubscription && method_exists($this->subscription, 'hasExtendedSupport')) { |
|
130 | - return $this->getSubscription()->hasExtendedSupport(); |
|
131 | - } |
|
132 | - return false; |
|
133 | - } |
|
40 | + /** @var ISubscription */ |
|
41 | + private $subscription = null; |
|
42 | + |
|
43 | + /** @var string */ |
|
44 | + private $subscriptionService = null; |
|
45 | + |
|
46 | + /** @var IConfig */ |
|
47 | + private $config; |
|
48 | + |
|
49 | + /** @var IServerContainer */ |
|
50 | + private $container; |
|
51 | + |
|
52 | + public function __construct(IConfig $config, IServerContainer $container) { |
|
53 | + $this->config = $config; |
|
54 | + $this->container = $container; |
|
55 | + } |
|
56 | + |
|
57 | + private function getSubscription(): ?ISubscription { |
|
58 | + if ($this->subscription === null && $this->subscriptionService !== null) { |
|
59 | + try { |
|
60 | + $this->subscription = $this->container->query($this->subscriptionService); |
|
61 | + } catch (QueryException $e) { |
|
62 | + // Ignore this |
|
63 | + } |
|
64 | + } |
|
65 | + |
|
66 | + return $this->subscription; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Register a subscription instance. In case it is called multiple times the |
|
71 | + * first one is used. |
|
72 | + * |
|
73 | + * @param ISubscription $subscription |
|
74 | + * @throws AlreadyRegisteredException |
|
75 | + * |
|
76 | + * @since 17.0.0 |
|
77 | + */ |
|
78 | + public function register(ISubscription $subscription): void { |
|
79 | + if ($this->subscription !== null || $this->subscriptionService !== null) { |
|
80 | + throw new AlreadyRegisteredException(); |
|
81 | + } |
|
82 | + $this->subscription = $subscription; |
|
83 | + } |
|
84 | + |
|
85 | + public function registerService(string $subscriptionService): void { |
|
86 | + if ($this->subscription !== null || $this->subscriptionService !== null) { |
|
87 | + throw new AlreadyRegisteredException(); |
|
88 | + } |
|
89 | + |
|
90 | + $this->subscriptionService = $subscriptionService; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Fetches the list of app IDs that are supported by the subscription |
|
96 | + * |
|
97 | + * @since 17.0.0 |
|
98 | + */ |
|
99 | + public function delegateGetSupportedApps(): array { |
|
100 | + if ($this->getSubscription() instanceof ISupportedApps) { |
|
101 | + return $this->getSubscription()->getSupportedApps(); |
|
102 | + } |
|
103 | + return []; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Indicates if a valid subscription is available |
|
108 | + * |
|
109 | + * @since 17.0.0 |
|
110 | + */ |
|
111 | + public function delegateHasValidSubscription(): bool { |
|
112 | + // Allow overwriting this manually for environments where the subscription information cannot be fetched |
|
113 | + if ($this->config->getSystemValueBool('has_valid_subscription')) { |
|
114 | + return true; |
|
115 | + } |
|
116 | + |
|
117 | + if ($this->getSubscription() instanceof ISubscription) { |
|
118 | + return $this->getSubscription()->hasValidSubscription(); |
|
119 | + } |
|
120 | + return false; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Indicates if the subscription has extended support |
|
125 | + * |
|
126 | + * @since 17.0.0 |
|
127 | + */ |
|
128 | + public function delegateHasExtendedSupport(): bool { |
|
129 | + if ($this->getSubscription() instanceof ISubscription && method_exists($this->subscription, 'hasExtendedSupport')) { |
|
130 | + return $this->getSubscription()->hasExtendedSupport(); |
|
131 | + } |
|
132 | + return false; |
|
133 | + } |
|
134 | 134 | } |