1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
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 Sylius\Bundle\ThemeBundle\Translation\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\Exception\OutOfBoundsException; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Kamil Kokot <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
final class TranslatorResourceProviderPass implements CompilerPassInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* {@inheritdoc} |
26
|
|
|
*/ |
27
|
|
|
public function process(ContainerBuilder $container) |
28
|
|
|
{ |
29
|
|
|
try { |
30
|
|
|
$symfonyTranslator = $container->findDefinition('translator.default'); |
31
|
|
|
$syliusResourceProvider = $container->findDefinition('sylius.theme.translation.resource_provider.default'); |
|
|
|
|
32
|
|
|
} catch (\InvalidArgumentException $exception) { |
33
|
|
|
return; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$symfonyResourcesFiles = $this->extractResourcesFilesFromSymfonyTranslator($symfonyTranslator); |
|
|
|
|
37
|
|
|
|
38
|
|
|
$syliusResourceProvider->replaceArgument(0, array_merge( |
39
|
|
|
$syliusResourceProvider->getArgument(0), |
40
|
|
|
$symfonyResourcesFiles |
41
|
|
|
)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param Definition $symfonyTranslator |
46
|
|
|
* |
47
|
|
|
* @return array |
48
|
|
|
*/ |
49
|
|
|
private function extractResourcesFilesFromSymfonyTranslator(Definition $symfonyTranslator) |
50
|
|
|
{ |
51
|
|
|
try { |
52
|
|
|
$options = $symfonyTranslator->getArgument(3); |
53
|
|
|
|
54
|
|
|
if (!array_key_exists('resource_files', $options)) { |
55
|
|
|
$options = $symfonyTranslator->getArgument(4); |
56
|
|
|
} |
57
|
|
|
} catch (OutOfBoundsException $exception) { |
58
|
|
|
$options = []; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$languagesFiles = isset($options['resource_files']) ? $options['resource_files'] : []; |
62
|
|
|
|
63
|
|
|
$resourceFiles = []; |
64
|
|
|
foreach ($languagesFiles as $language => $files) { |
65
|
|
|
foreach ($files as $file) { |
66
|
|
|
$resourceFiles[] = $file; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $resourceFiles; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.