1 | <?php |
||
24 | class StoragePass implements CompilerPassInterface |
||
25 | { |
||
26 | /** |
||
27 | * @var Definition[] |
||
28 | */ |
||
29 | private $definitions; |
||
30 | |||
31 | 3 | public function process(ContainerBuilder $container) |
|
32 | { |
||
33 | 3 | $services = $container->findTaggedServiceIds('php_translation.storage'); |
|
34 | 3 | foreach ($services as $id => $tags) { |
|
35 | 2 | foreach ($tags as $tag) { |
|
36 | 2 | if (!isset($tag['name'])) { |
|
37 | $tag['name'] = 'default'; |
||
38 | } |
||
39 | 2 | if (!isset($tag['type'])) { |
|
40 | throw new \LogicException('The tag "php_translation.storage" must have a "type".'); |
||
41 | } |
||
42 | |||
43 | 2 | $def = $this->getDefinition($container, $tag['name']); |
|
44 | 2 | switch ($tag['type']) { |
|
45 | 2 | case 'remote': |
|
46 | 1 | $def->addMethodCall('addRemoteStorage', [new Reference($id)]); |
|
47 | 1 | break; |
|
48 | 1 | case 'local': |
|
49 | 1 | $def->addMethodCall('addLocalStorage', [new Reference($id)]); |
|
50 | 1 | break; |
|
51 | default: |
||
52 | throw new \LogicException(sprintf('The tag "php_translation.storage" must have a "type" of value "local" or "remote". Value "%s" was provided', $tag['type'])); |
||
53 | 2 | } |
|
54 | 2 | } |
|
55 | 3 | } |
|
56 | 3 | } |
|
57 | |||
58 | /** |
||
59 | * @param ContainerBuilder $container |
||
60 | * |
||
61 | * @return Definition |
||
62 | */ |
||
63 | 2 | private function getDefinition(ContainerBuilder $container, $name) |
|
71 | } |
||
72 |