Skip to content

Commit 5228bb9

Browse files
feat: integrate plugins with hooks runner and client registration
- Make hooks property mutable to support plugin hooks - Add plugin registration logic in static start method - Create EnvironmentMetadata instances for each client - Follow Android PR patterns for plugin ordering and registration - Support multiple client scenarios with respective credentials Co-Authored-By: [email protected] <[email protected]>
1 parent 6d2e5f8 commit 5228bb9

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

LaunchDarkly/LaunchDarkly/LDClient.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public class LDClient {
273273

274274
let config: LDConfig
275275
let service: DarklyServiceProvider
276-
let hooks: [Hook]
276+
var hooks: [Hook]
277277
private(set) var context: LDContext
278278

279279
/**
@@ -807,6 +807,26 @@ public class LDClient {
807807
}
808808
}
809809

810+
for (name, mobileKey) in mobileKeys {
811+
if let instance = LDClient.instances?[name] {
812+
let sdkMetadata = SdkMetadata(name: ReportingConsts.sdkName, version: ReportingConsts.sdkVersion)
813+
let environmentMetadata = EnvironmentMetadata(
814+
applicationInfo: instance.environmentReporter.applicationInfo,
815+
sdkMetadata: sdkMetadata,
816+
credential: mobileKey
817+
)
818+
819+
for plugin in config.plugins {
820+
let pluginHooks = plugin.getHooks(metadata: environmentMetadata)
821+
instance.hooks.append(contentsOf: pluginHooks)
822+
}
823+
824+
for plugin in config.plugins {
825+
plugin.register(client: instance, metadata: environmentMetadata)
826+
}
827+
}
828+
}
829+
810830
completionCheck()
811831
}
812832

@@ -894,7 +914,7 @@ public class LDClient {
894914

895915
private init(serviceFactory: ClientServiceCreating, configuration: LDConfig, startContext: LDContext?, completion: (() -> Void)? = nil) {
896916
self.serviceFactory = serviceFactory
897-
self.hooks = configuration.hooks
917+
self.hooks = Array(configuration.hooks)
898918
environmentReporter = self.serviceFactory.makeEnvironmentReporter(config: configuration)
899919
flagCache = self.serviceFactory.makeFeatureFlagCache(mobileKey: configuration.mobileKey, maxCachedContexts: configuration.maxCachedContexts)
900920
flagStore = self.serviceFactory.makeFlagStore()

0 commit comments

Comments
 (0)