src/Eccube/DependencyInjection/Compiler/AutoConfigurationTagPass.php line 44

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of EC-CUBE
  4. *
  5. * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6. *
  7. * http://www.ec-cube.co.jp/
  8. *
  9. * For the full copyright and license information, please view the LICENSE
  10. * file that was distributed with this source code.
  11. */
  12. namespace Eccube\DependencyInjection\Compiler;
  13. use Doctrine\Common\EventSubscriber;
  14. use Symfony\Component\DependencyInjection\ChildDefinition;
  15. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  16. use Symfony\Component\DependencyInjection\ContainerBuilder;
  17. use Symfony\Component\DependencyInjection\Definition;
  18. /**
  19. * サービスタグの自動設定を行う
  20. *
  21. * 以下のタグは自動設定が行われないため, 自動設定対象になるように処理する
  22. *
  23. * - doctrine.event_subscriber
  24. *
  25. * PluginPassで無効なプラグインのタグは解除されるため, PluginPassより先行して実行する必要がある
  26. */
  27. class AutoConfigurationTagPass implements CompilerPassInterface
  28. {
  29. public function process(ContainerBuilder $container)
  30. {
  31. foreach ($container->getDefinitions() as $id => $definition) {
  32. $this->configureDoctrineEventSubscriberTag($definition);
  33. $this->configureRateLimiterTag($id, $definition);
  34. }
  35. }
  36. protected function configureDoctrineEventSubscriberTag(Definition $definition)
  37. {
  38. $class = $definition->getClass();
  39. if (!is_subclass_of($class, EventSubscriber::class)) {
  40. return;
  41. }
  42. if ($definition->hasTag('doctrine.event_subscriber')) {
  43. return;
  44. }
  45. $definition->addTag('doctrine.event_subscriber');
  46. }
  47. protected function configureRateLimiterTag($id, Definition $definition)
  48. {
  49. if (\str_starts_with($id, 'limiter')
  50. && $definition instanceof ChildDefinition
  51. && $definition->getParent() === 'limiter'
  52. && !$definition->hasTag('eccube_rate_limiter')) {
  53. $definition->addTag('eccube_rate_limiter');
  54. }
  55. }
  56. }