Completed
Pull Request — 3.2 (#289)
by
unknown
10:16
created

EventSubscriberPass::process()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 9
nc 5
nop 1
1
<?php
2
3
namespace Drupal\DrupalExtension\Compiler;
4
5
use Symfony\Component\DependencyInjection\Reference,
6
    Symfony\Component\DependencyInjection\ContainerBuilder,
7
    Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
9
/**
10
 * Event subscribers pass - registers all available event subscribers.
11
 */
12
class EventSubscriberPass implements CompilerPassInterface {
13
  /**
14
   * Processes container.
15
   *
16
   * @param ContainerBuilder $container
17
   */
18
  public function process(ContainerBuilder $container) {
19
    if (!$container->hasDefinition('drupal.event_dispatcher')) {
20
      return;
21
    }
22
    $dispatcherDefinition = $container->getDefinition('drupal.event_dispatcher');
23
24
    foreach ($container->findTaggedServiceIds('drupal.event_subscriber') as $id => $attributes) {
25
      foreach ($attributes as $attribute) {
26
        $priority = isset($attribute['priority']) ? intval($attribute['priority']) : 0;
27
        $dispatcherDefinition->addMethodCall(
28
          'addSubscriber', array(new Reference($id), $priority)
29
        );
30
      }
31
    }
32
  }
33
}
34