@@ -21,52 +21,70 @@ final class IntegrationConfigurator
2121 ];
2222
2323 /**
24- * @var IntegrationInterface[]
24+ * @var IntegrationInterface[]|callable|mixed
2525 */
26- private $ userIntegrations ;
26+ private $ userConfig ;
2727
2828 /**
2929 * @var bool
3030 */
3131 private $ registerErrorHandler ;
3232
3333 /**
34- * @param IntegrationInterface[] $userIntegrations
34+ * @param IntegrationInterface[]|callable $userConfig Array of integrations or a callable that filters/returns integrations
3535 */
36- public function __construct (array $ userIntegrations , bool $ registerErrorHandler )
36+ public function __construct ($ userConfig , bool $ registerErrorHandler )
3737 {
38- $ this ->userIntegrations = $ userIntegrations ;
38+ $ this ->userConfig = $ userConfig ;
3939 $ this ->registerErrorHandler = $ registerErrorHandler ;
4040 }
4141
4242 /**
43- * @see IntegrationRegistry::getIntegrationsToSetup()
44- *
4543 * @param IntegrationInterface[] $defaultIntegrations
4644 *
4745 * @return IntegrationInterface[]
46+ *
47+ * @see IntegrationRegistry::getIntegrationsToSetup()
4848 */
4949 public function __invoke (array $ defaultIntegrations ): array
5050 {
51- $ integrations = [];
52-
53- $ userIntegrationsClasses = array_map ('get_class ' , $ this ->userIntegrations );
54- $ pickedIntegrationsClasses = [];
55-
51+ $ filteredDefaults = [];
5652 foreach ($ defaultIntegrations as $ defaultIntegration ) {
5753 $ integrationClassName = \get_class ($ defaultIntegration );
5854
5955 if (!$ this ->registerErrorHandler && isset (self ::ERROR_HANDLER_INTEGRATIONS [$ integrationClassName ])) {
6056 continue ;
6157 }
6258
59+ $ filteredDefaults [] = $ defaultIntegration ;
60+ }
61+
62+ if (\is_callable ($ this ->userConfig )) {
63+ $ result = ($ this ->userConfig )($ filteredDefaults );
64+
65+ if (!\is_array ($ result )) {
66+ return [];
67+ }
68+
69+ return $ result ;
70+ }
71+
72+ $ integrations = [];
73+ /** @var IntegrationInterface[] $userIntegrations */
74+ $ userIntegrations = \is_array ($ this ->userConfig ) ? $ this ->userConfig : [];
75+ $ userIntegrationsClasses = array_map ('get_class ' , $ userIntegrations );
76+ $ pickedIntegrationsClasses = [];
77+
78+ foreach ($ filteredDefaults as $ defaultIntegration ) {
79+ $ integrationClassName = \get_class ($ defaultIntegration );
80+
6381 if (!\in_array ($ integrationClassName , $ userIntegrationsClasses , true ) && !isset ($ pickedIntegrationsClasses [$ integrationClassName ])) {
6482 $ integrations [] = $ defaultIntegration ;
6583 $ pickedIntegrationsClasses [$ integrationClassName ] = true ;
6684 }
6785 }
6886
69- foreach ($ this -> userIntegrations as $ userIntegration ) {
87+ foreach ($ userIntegrations as $ userIntegration ) {
7088 $ integrationClassName = \get_class ($ userIntegration );
7189
7290 if (!isset ($ pickedIntegrationsClasses [$ integrationClassName ])) {
0 commit comments