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.

49 lines
1.6 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 ConditionsManagerPass
  9. */
  10. class ConditionsManagerPass implements CompilerPassInterface
  11. {
  12. /**
  13. * @var ContainerBuilder
  14. */
  15. protected $container;
  16. /**
  17. * @param ContainerBuilder $container
  18. */
  19. public function process(ContainerBuilder $container)
  20. {
  21. if (!$container->has('rule_engine.orchestrator')) {
  22. return;
  23. }
  24. $evaluator = $container->findDefinition('rule_engine.orchestrator');
  25. $conditionsManagers = $container->findTaggedServiceIds('rule_engine.conditions_manager');
  26. $entities = [];
  27. foreach ($conditionsManagers as $serviceId => $tags) {
  28. foreach ($tags as $attributes) {
  29. if (isset($attributes['entity'])) {
  30. if (isset($entities[$attributes['entity']])) {
  31. throw new LogicException(
  32. sprintf('Duplicate conditions manager for entity "%s" found!', $attributes['entity'])
  33. );
  34. }
  35. $entities[$attributes['entity']] = $attributes['entity'];
  36. $evaluator->addMethodCall(
  37. 'setEntityConditionsManager',
  38. [$attributes['entity'], new Reference($serviceId)]
  39. );
  40. }
  41. }
  42. }
  43. }
  44. }