mirror of
https://github.com/nextcloud/server.git
synced 2026-11-24 15:04:18 +01:00
Assisted-by: ClaudeCode:claude-opus-5 Signed-off-by: Carl Schwan <carl@carlschwan.eu>
75 lines
1.9 KiB
PHP
75 lines
1.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OC\Search;
|
|
|
|
use NCU\Search\IAccountScopedSearchProvider;
|
|
use NCU\Search\IAccountScopedSearchProviderRegistry;
|
|
use OC\AppFramework\Bootstrap\Coordinator;
|
|
use Psr\Container\ContainerInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
use Throwable;
|
|
|
|
final class AccountScopedSearchProviderRegistry implements IAccountScopedSearchProviderRegistry {
|
|
/** @var array<non-empty-lowercase-string, IAccountScopedSearchProvider>|null */
|
|
private ?array $providers = null;
|
|
|
|
public function __construct(
|
|
private readonly Coordinator $coordinator,
|
|
private readonly ContainerInterface $container,
|
|
private readonly LoggerInterface $logger,
|
|
) {
|
|
}
|
|
|
|
#[\Override]
|
|
public function getProviders(): array {
|
|
return $this->load();
|
|
}
|
|
|
|
#[\Override]
|
|
public function getProvider(string $id): ?IAccountScopedSearchProvider {
|
|
return $this->load()[$id] ?? null;
|
|
}
|
|
|
|
/**
|
|
* @return array<non-empty-lowercase-string, IAccountScopedSearchProvider>
|
|
*/
|
|
private function load(): array {
|
|
if ($this->providers !== null) {
|
|
return $this->providers;
|
|
}
|
|
|
|
$context = $this->coordinator->getRegistrationContext();
|
|
if ($context === null) {
|
|
// Not cached: nothing is registered yet this early in boot.
|
|
return [];
|
|
}
|
|
|
|
$providers = [];
|
|
foreach ($context->getAccountScopedSearchProviders() as $registration) {
|
|
try {
|
|
/** @var IAccountScopedSearchProvider $provider */
|
|
$provider = $this->container->get($registration->getService());
|
|
} catch (Throwable $e) {
|
|
$this->logger->error('Could not load an account-scoped search provider', [
|
|
'exception' => $e,
|
|
'app' => $registration->getAppId(),
|
|
]);
|
|
|
|
continue;
|
|
}
|
|
$providers[$provider->getId()] = $provider;
|
|
}
|
|
|
|
$this->providers = $providers;
|
|
|
|
return $providers;
|
|
}
|
|
}
|