Licitator 1.0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.4 KiB

5 years ago
  1. <?php
  2. namespace Zitec\RuleEngineBundle\DependencyInjection\Compiler;
  3. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  4. use Symfony\Component\DependencyInjection\ContainerBuilder;
  5. use Symfony\Component\DependencyInjection\Exception\LogicException;
  6. use Symfony\Component\DependencyInjection\Reference;
  7. /**
  8. * Class RuleEnginePass
  9. * Compiler pass that aggregates expression language function providers and autocomplete implementations.
  10. */
  11. class AutocompletePass implements CompilerPassInterface
  12. {
  13. /**
  14. * @param ContainerBuilder $container
  15. */
  16. public function process(ContainerBuilder $container)
  17. {
  18. if (!$container->has('rule_engine.autocomplete')) {
  19. return;
  20. }
  21. $dataSources = [];
  22. $dataSourceServices = $container->findTaggedServiceIds('rule_engine.autocomplete.data_source');
  23. foreach ($dataSourceServices as $serviceId => $tags) {
  24. foreach ($tags as $attributes) {
  25. $dataSourceKey = $attributes['key'];
  26. if (isset($dataSources[$dataSourceKey])) {
  27. throw new LogicException(sprintf('Duplicate data source key "%s" found!', $dataSourceKey));
  28. }
  29. $dataSources[$dataSourceKey] = new Reference($serviceId);
  30. continue 2;
  31. }
  32. }
  33. $definition = $container->findDefinition('rule_engine.autocomplete');
  34. $definition->setArguments([$dataSources]);
  35. }
  36. }