ProviderManager.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OC\Collaboration\Resources;
  8. use OCP\AppFramework\QueryException;
  9. use OCP\Collaboration\Resources\IProvider;
  10. use OCP\Collaboration\Resources\IProviderManager;
  11. use OCP\IServerContainer;
  12. use Psr\Log\LoggerInterface;
  13. class ProviderManager implements IProviderManager {
  14. /** @var string[] */
  15. protected array $providers = [];
  16. /** @var IProvider[] */
  17. protected array $providerInstances = [];
  18. public function __construct(
  19. protected IServerContainer $serverContainer,
  20. protected LoggerInterface $logger,
  21. ) {
  22. }
  23. public function getResourceProviders(): array {
  24. if ($this->providers !== []) {
  25. foreach ($this->providers as $provider) {
  26. try {
  27. $this->providerInstances[] = $this->serverContainer->query($provider);
  28. } catch (QueryException $e) {
  29. $this->logger->error("Could not query resource provider $provider: " . $e->getMessage(), [
  30. 'exception' => $e,
  31. ]);
  32. }
  33. }
  34. $this->providers = [];
  35. }
  36. return $this->providerInstances;
  37. }
  38. public function registerResourceProvider(string $provider): void {
  39. $this->providers[] = $provider;
  40. }
  41. }