You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Registry.php 2.4KB

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