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