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

EventSubscriberPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 15 5
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