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.

NotificationProviderManager.php 2.5KB

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