1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\TranslatorBundle\DependencyInjection\Compiler; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
6
|
|
|
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; |
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
8
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
9
|
|
|
|
10
|
|
|
class KunstmaanTranslatorCompilerPass implements CompilerPassInterface |
11
|
|
|
{ |
12
|
|
|
public function process(ContainerBuilder $container) |
13
|
|
|
{ |
14
|
|
|
$loaderRefs = array(); |
15
|
|
|
$loaderAliases = array(); |
|
|
|
|
16
|
|
|
$exporterRefs = array(); |
17
|
|
|
|
18
|
|
|
foreach ($container->findTaggedServiceIds('translation.loader', true) as $id => $attributes) { |
19
|
|
|
$loaderRefs[$id] = new Reference($id); |
20
|
|
|
$loaders[$id][] = $attributes[0]['alias']; |
|
|
|
|
21
|
|
|
if (isset($attributes[0]['legacy-alias'])) { |
22
|
|
|
$loaders[$id][] = $attributes[0]['legacy-alias']; |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
if ($container->hasDefinition('kunstmaan_translator.service.importer.importer')) { |
27
|
|
|
$definition = $container->getDefinition('kunstmaan_translator.service.importer.importer'); |
28
|
|
|
foreach ($loaders as $id => $formats) { |
|
|
|
|
29
|
|
|
foreach ($formats as $format) { |
30
|
|
|
$definition->addMethodCall('addLoader', array($format, $loaderRefs[$id])); |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
if ($container->hasDefinition('kunstmaan_translator.service.translator.translator')) { |
36
|
|
|
//Create custom ServiceLocator to inject in the translator |
37
|
|
|
$serviceIds = array_merge($loaderRefs, ['request_stack' => new Reference('request_stack')]); |
38
|
|
|
$serviceLocator = ServiceLocatorTagPass::register($container, $serviceIds); |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
$container->getDefinition('kunstmaan_translator.service.translator.translator') |
42
|
|
|
->replaceArgument(0, $serviceLocator) |
43
|
|
|
->replaceArgument(3, $loaders); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
// add all exporter into the translation exporter |
47
|
|
|
foreach ($container->findTaggedServiceIds('translation.exporter') as $id => $attributes) { |
48
|
|
|
$exporterRefs[$attributes[0]['alias']] = new Reference($id); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if ($container->hasDefinition('kunstmaan_translator.service.exporter.exporter')) { |
52
|
|
|
$container->getDefinition('kunstmaan_translator.service.exporter.exporter')->addMethodCall('setExporters', array($exporterRefs)); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.