summaryrefslogtreecommitdiffstats
path: root/lib/private/Search
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2020-07-14 10:21:39 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-07-14 15:33:32 +0200
commitf03f88b437511ef29bad9e13c0d1a16e24c50bc8 (patch)
treeecd6c742ff19fb1bdbfe95e1bc08147df92680c2 /lib/private/Search
parent7b82895982f9fcac8aa04fa9d650bd1113f638c2 (diff)
downloadnextcloud-server-f03f88b437511ef29bad9e13c0d1a16e24c50bc8.tar.gz
nextcloud-server-f03f88b437511ef29bad9e13c0d1a16e24c50bc8.zip
Delegate bootstrap registration lazily
* Keep the registration context * Expose the context object for other components * Ensure registration is only run once Search providers are migrated for demonstration. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/Search')
-rw-r--r--lib/private/Search/SearchComposer.php40
1 files changed, 16 insertions, 24 deletions
diff --git a/lib/private/Search/SearchComposer.php b/lib/private/Search/SearchComposer.php
index ae4350ca5cc..61bbbbc969b 100644
--- a/lib/private/Search/SearchComposer.php
+++ b/lib/private/Search/SearchComposer.php
@@ -26,7 +26,7 @@ declare(strict_types=1);
namespace OC\Search;
use InvalidArgumentException;
-use OCP\AppFramework\Bootstrap\IRegistrationContext;
+use OC\AppFramework\Bootstrap\Coordinator;
use OCP\AppFramework\QueryException;
use OCP\ILogger;
use OCP\IServerContainer;
@@ -57,37 +57,24 @@ use function array_map;
*/
class SearchComposer {
- /** @var string[] */
- private $lazyProviders = [];
-
/** @var IProvider[] */
private $providers = [];
+ /** @var Coordinator */
+ private $bootstrapCoordinator;
+
/** @var IServerContainer */
private $container;
/** @var ILogger */
private $logger;
- public function __construct(IServerContainer $container,
+ public function __construct(Coordinator $bootstrapCoordinator,
+ IServerContainer $container,
ILogger $logger) {
$this->container = $container;
$this->logger = $logger;
- }
-
- /**
- * Register a search provider lazily
- *
- * Registers the fully-qualified class name of an implementation of an
- * IProvider. The service will only be queried on demand. Apps will register
- * the providers through the registration context object.
- *
- * @see IRegistrationContext::registerSearchProvider()
- *
- * @param string $class
- */
- public function registerProvider(string $class): void {
- $this->lazyProviders[] = $class;
+ $this->bootstrapCoordinator = $bootstrapCoordinator;
}
/**
@@ -96,11 +83,17 @@ class SearchComposer {
* If a provider can't be loaded we log it but the operation continues nevertheless
*/
private function loadLazyProviders(): void {
- $classes = $this->lazyProviders;
- foreach ($classes as $class) {
+ $context = $this->bootstrapCoordinator->getRegistrationContext();
+ if ($context === null) {
+ // Too early, nothing registered yet
+ return;
+ }
+
+ $registrations = $context->getSearchProviders();
+ foreach ($registrations as $registration) {
try {
/** @var IProvider $provider */
- $provider = $this->container->query($class);
+ $provider = $this->container->query($registration['class']);
$this->providers[$provider->getId()] = $provider;
} catch (QueryException $e) {
// Log an continue. We can be fault tolerant here.
@@ -110,7 +103,6 @@ class SearchComposer {
]);
}
}
- $this->lazyProviders = [];
}
/**