|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the ONGR package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) NFQ Technologies UAB <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace ONGR\TranslationsBundle\DependencyInjection\Compiler; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
17
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* TranslatorPass to load translations loaders. |
|
21
|
|
|
*/ |
|
22
|
|
|
class TranslatorPass implements CompilerPassInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
3 |
|
public function process(ContainerBuilder $container) |
|
28
|
|
|
{ |
|
29
|
3 |
|
$formats = $container->getParameter('ongr_translations.formats'); |
|
30
|
3 |
|
$loadersContainer = new Definition('Symfony\Component\HttpFoundation\ParameterBag'); |
|
31
|
|
|
|
|
32
|
3 |
|
foreach ($container->findTaggedServiceIds('translation.loader') as $id => $attributes) { |
|
33
|
3 |
|
if (!empty($formats)) { |
|
34
|
2 |
|
if (array_intersect($attributes[0], $formats)) { |
|
35
|
2 |
|
$this->addLoader($loadersContainer, $attributes, $id); |
|
36
|
|
|
} |
|
37
|
|
|
} else { |
|
38
|
3 |
|
$this->addLoader($loadersContainer, $attributes, $id); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
3 |
|
$container->setDefinition('ongr_translations.loaders_container', $loadersContainer); |
|
43
|
|
|
|
|
44
|
3 |
|
$this->setImportLoadersContainer($container, $loadersContainer); |
|
45
|
3 |
|
$this->setExportLoadersContainer($container, $loadersContainer); |
|
46
|
3 |
|
$this->setComponentDirectories($container); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Adds loader to LoadersContainer definition. |
|
51
|
|
|
* |
|
52
|
|
|
* @param Definition $loadersContainer |
|
53
|
|
|
* @param array $attributes |
|
54
|
|
|
* @param string $id |
|
55
|
3 |
|
*/ |
|
56
|
|
|
public function addLoader($loadersContainer, $attributes, $id) |
|
57
|
3 |
|
{ |
|
58
|
3 |
|
$loadersContainer->addMethodCall( |
|
59
|
3 |
|
'set', |
|
60
|
|
|
[$attributes[0]['alias'], new Reference($id)] |
|
61
|
3 |
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Set import service LoadersContainer. |
|
66
|
|
|
* |
|
67
|
|
|
* @param ContainerBuilder $container |
|
68
|
|
|
* @param Definition $loadersContainer |
|
69
|
3 |
|
*/ |
|
70
|
|
|
public function setImportLoadersContainer(ContainerBuilder $container, $loadersContainer) |
|
71
|
3 |
|
{ |
|
72
|
1 |
|
if ($container->hasDefinition('ongr_translations.file_import')) { |
|
73
|
|
|
$container->findDefinition('ongr_translations.file_import')->replaceArgument(0, $loadersContainer); |
|
74
|
3 |
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Set export service LoadersContainer. |
|
79
|
|
|
* |
|
80
|
|
|
* @param ContainerBuilder $container |
|
81
|
|
|
* @param Definition $loadersContainer |
|
82
|
3 |
|
*/ |
|
83
|
|
|
public function setExportLoadersContainer(ContainerBuilder $container, $loadersContainer) |
|
84
|
3 |
|
{ |
|
85
|
1 |
|
if ($container->hasDefinition('ongr_translations.export')) { |
|
86
|
|
|
$container->findDefinition('ongr_translations.export')->replaceArgument(0, $loadersContainer); |
|
87
|
3 |
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param ContainerBuilder $container |
|
92
|
|
|
*/ |
|
93
|
|
|
private function setComponentDirectories(ContainerBuilder $container) |
|
94
|
|
|
{ |
|
95
|
|
|
$container->setParameter( |
|
96
|
|
|
'ongr_translations.component_directories', |
|
97
|
|
|
[ |
|
98
|
|
|
'Symfony\Component\Validator\ValidatorBuilder', |
|
99
|
|
|
'Symfony\Component\Form\Form', |
|
100
|
|
|
] |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|