Completed
Pull Request — 3.1 (#290)
by
unknown
09:17
created

DriverPass   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 3
dl 0
loc 42
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C process() 0 37 11
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
 * Drupal\DrupalExtension container compilation pass.
11
 */
12
class DriverPass implements CompilerPassInterface {
13
  /**
14
   * Register Drupal drivers.
15
   */
16
  public function process(ContainerBuilder $container) {
17
    if (!$container->hasDefinition('drupal.drupal')) {
18
      return;
19
    }
20
21
    $drupalDefinition = $container->getDefinition('drupal.drupal');
22
    foreach ($container->findTaggedServiceIds('drupal.driver') as $id => $attributes) {
23
      foreach ($attributes as $attribute) {
24
        if (isset($attribute['alias']) && $name = $attribute['alias']) {
25
          $drupalDefinition->addMethodCall(
26
            'registerDriver', array($name, new Reference($id))
27
          );
28
        }
29
      }
30
31
      // If this is Drupal Driver, then a core controller needs to be
32
      // instantiated as well.
33
      if ('drupal.driver.drupal' === $id) {
34
        $drupalDriverDefinition = $container->getDefinition($id);
35
        $availableCores = array();
36
        foreach ($container->findTaggedServiceIds('drupal.core') as $coreId => $coreAttributes) {
37
          foreach ($coreAttributes as $attribute) {
38
            if (isset($attribute['alias']) && $name = $attribute['alias']) {
39
              $availableCores[$name] = $container->getDefinition($coreId);
40
            }
41
          }
42
        }
43
        $drupalDriverDefinition->addMethodCall(
44
          'setCore', array($availableCores)
45
        );
46
      }
47
    }
48
49
    $drupalDefinition->addMethodCall(
50
      'setDefaultDriverName', array($container->getParameter('drupal.drupal.default_driver'))
51
    );
52
  }
53
}
54