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