6
6
7
7
use Setono \SyliusMeilisearchPlugin \Config \Index ;
8
8
use Setono \SyliusMeilisearchPlugin \Document \Document ;
9
- use Setono \SyliusMeilisearchPlugin \Exception \ NonExistingIndexerException ;
9
+ use Setono \SyliusMeilisearchPlugin \Indexer \ IndexerInterface ;
10
10
use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
11
+ use Symfony \Component \DependencyInjection \Compiler \ServiceLocatorTagPass ;
11
12
use Symfony \Component \DependencyInjection \ContainerBuilder ;
12
13
use Symfony \Component \DependencyInjection \Definition ;
13
14
use Symfony \Component \DependencyInjection \Reference ;
@@ -20,27 +21,26 @@ public function process(ContainerBuilder $container): void
20
21
return ;
21
22
}
22
23
23
- $ indexers = array_keys ($ container ->findTaggedServiceIds ('setono_sylius_meilisearch.indexer ' ));
24
24
$ indexRegistry = $ container ->getDefinition ('setono_sylius_meilisearch.config.index_registry ' );
25
25
26
26
/** @var array<string, array{document: class-string<Document>, indexer: string, entities: list<class-string>, prefix: string}> $indexes */
27
27
$ indexes = $ container ->getParameter ('setono_sylius_meilisearch.indexes ' );
28
28
29
29
foreach ($ indexes as $ indexName => $ index ) {
30
- if (!in_array ($ index ['indexer ' ], $ indexers , true )) {
31
- throw NonExistingIndexerException::fromServiceId ($ index ['indexer ' ], $ indexers );
32
- }
30
+ $ indexServiceId = sprintf ('setono_sylius_meilisearch.index.%s ' , $ indexName );
33
31
34
- $ indexDefinitionName = sprintf ('setono_sylius_meilisearch.index.%s ' , $ indexName );
35
- $ container ->setDefinition ($ indexDefinitionName , new Definition (Index::class, [
32
+ $ container ->setDefinition ($ indexServiceId , new Definition (Index::class, [
36
33
$ indexName ,
37
34
$ index ['document ' ],
38
- new Reference ($ index ['indexer ' ]),
39
35
$ index ['entities ' ],
36
+ ServiceLocatorTagPass::register ($ container , [IndexerInterface::class => new Reference ($ index ['indexer ' ])]),
40
37
$ index ['prefix ' ],
41
38
]));
42
39
43
- $ indexRegistry ->addMethodCall ('add ' , [new Reference ($ indexDefinitionName )]);
40
+ $ indexRegistry ->addMethodCall ('add ' , [new Reference ($ indexServiceId )]);
41
+
42
+ $ indexer = $ container ->getDefinition ($ index ['indexer ' ]);
43
+ $ indexer ->setArgument ('$index ' , new Reference ($ indexServiceId ));
44
44
}
45
45
}
46
46
}
0 commit comments