1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Lug package. |
5
|
|
|
* |
6
|
|
|
* (c) Eric GELOEN <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please read the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Lug\Bundle\TranslationBundle\DependencyInjection\Compiler; |
13
|
|
|
|
14
|
|
|
use Lug\Component\Translation\Factory\TranslatableFactory; |
15
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
17
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author GeLo <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class ConfigureFactoryPass implements CompilerPassInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
2 |
|
public function process(ContainerBuilder $container) |
28
|
|
|
{ |
29
|
2 |
|
foreach ($container->findTaggedServiceIds('lug.factory') as $service => $attributes) { |
30
|
2 |
|
$factory = $container->getDefinition($service); |
31
|
|
|
|
32
|
2 |
|
if (!is_a($factory->getClass(), TranslatableFactory::class, true)) { |
33
|
1 |
|
continue; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$factory |
37
|
1 |
|
->addArgument(new Reference('lug.translation.context.locale')) |
38
|
1 |
|
->addArgument($this->getTranslationFactory($attributes[0]['resource'], $container)); |
39
|
2 |
|
} |
40
|
2 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param string $resource |
44
|
|
|
* @param ContainerBuilder $container |
45
|
|
|
* |
46
|
|
|
* @return Reference |
47
|
|
|
*/ |
48
|
1 |
|
private function getTranslationFactory($resource, ContainerBuilder $container) |
49
|
|
|
{ |
50
|
1 |
|
$translation = null; |
51
|
|
|
|
52
|
1 |
|
foreach ($container->getDefinition('lug.resource.'.$resource)->getMethodCalls() as $methodCall) { |
53
|
1 |
|
if ($methodCall[0] === 'addRelation' && $methodCall[1][0] === 'translation') { |
54
|
1 |
|
$translation = $container->getDefinition((string) $methodCall[1][1])->getArgument(0); |
55
|
1 |
|
} |
56
|
1 |
|
} |
57
|
|
|
|
58
|
1 |
|
return new Reference('lug.factory.'.$translation); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|