Manager.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2023, Thomas Citharel <nextcloud@tcit.fr>
  5. *
  6. * @author Thomas Citharel <nextcloud@tcit.fr>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  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, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OC\Push;
  24. use OC\AppFramework\Bootstrap\Coordinator;
  25. use OCP\Push\IManager;
  26. use OCP\Push\IProvider;
  27. use Psr\Container\ContainerExceptionInterface;
  28. use Psr\Log\LoggerInterface;
  29. /**
  30. * @since 28.0.0
  31. */
  32. class Manager implements IManager {
  33. public function __construct(private LoggerInterface $logger, private Coordinator $coordinator) { }
  34. /**
  35. * @return IProvider[]
  36. */
  37. public function getPushNotifierServices(): array {
  38. $notifierServices = [];
  39. $notifierServiceRegistrations = $this->coordinator->getRegistrationContext()->getPushNotifierServices();
  40. if (empty($notifierServiceRegistrations)) {
  41. return $notifierServices;
  42. }
  43. foreach ($notifierServiceRegistrations as $notifierServiceRegistration) {
  44. $serviceClass = $notifierServiceRegistration->getService();
  45. try {
  46. $notifierService = \OC::$server->get($serviceClass);
  47. } catch (ContainerExceptionInterface $e) {
  48. $this->logger->error('Failed to load push notification service class: ' . $serviceClass, [
  49. 'exception' => $e,
  50. 'app' => 'notifications',
  51. ]);
  52. continue;
  53. }
  54. if (!($notifierService instanceof IProvider)) {
  55. $this->logger->error('Push notification notifier class ' . $serviceClass . ' is not implementing ' . IProvider::class, [
  56. 'app' => 'notifications',
  57. ]);
  58. continue;
  59. }
  60. $notifierServices[] = $notifierService;
  61. }
  62. return $notifierServices;
  63. }
  64. }