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
|
|
|
|