1 | <?php |
||
29 | class TranslationExtension extends Extension |
||
30 | { |
||
31 | /** |
||
32 | * {@inheritdoc} |
||
33 | */ |
||
34 | 1 | public function load(array $configs, ContainerBuilder $container) |
|
35 | { |
||
36 | 1 | $configuration = new Configuration($container); |
|
37 | 1 | $config = $this->processConfiguration($configuration, $configs); |
|
38 | 1 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
39 | |||
40 | 1 | $loader->load('services.yml'); |
|
41 | 1 | $loader->load('extractors.yml'); |
|
42 | |||
43 | // Add major version to extractor |
||
44 | 1 | $container->getDefinition('php_translation.extractor.php.visitor.FormTypeChoices') |
|
45 | 1 | ->addMethodCall('setSymfonyMajorVersion', [Kernel::MAJOR_VERSION]); |
|
46 | |||
47 | 1 | $container->setParameter('php_translation.locales', $config['locales']); |
|
48 | 1 | $container->setParameter('php_translation.default_locale', isset($config['default_locale']) ? $config['default_locale'] : $container->getParameter('kernel.default_locale')); |
|
49 | |||
50 | 1 | if ($config['webui']['enabled']) { |
|
51 | 1 | $this->enableWebUi($container, $config); |
|
|
|||
52 | 1 | } |
|
53 | |||
54 | 1 | if ($config['symfony_profiler']['enabled']) { |
|
55 | $loader->load('symfony_profiler.yml'); |
||
56 | $this->enableSymfonyProfiler($container, $config); |
||
57 | } |
||
58 | |||
59 | 1 | if ($config['edit_in_place']['enabled']) { |
|
60 | 1 | $loader->load('edit_in_place.yml'); |
|
61 | 1 | $this->enableEditInPlace($container, $config); |
|
62 | 1 | } |
|
63 | |||
64 | 1 | if ($config['auto_add_missing_translations']['enabled']) { |
|
65 | $loader->load('auto_add.yml'); |
||
66 | $container->getDefinition('php_translator.auto_adder') |
||
67 | ->replaceArgument(0, new Reference('php_translation.storage.'.$config['auto_add_missing_translations']['config_name'])); |
||
68 | } |
||
69 | |||
70 | 1 | if ($config['fallback_translation']['enabled']) { |
|
71 | $loader->load('auto_translation.yml'); |
||
72 | $this->enableFallbackAutoTranslator($container, $config); |
||
73 | } |
||
74 | |||
75 | 1 | $first = null; |
|
76 | 1 | foreach ($config['configs'] as $name => &$c) { |
|
77 | if ($first === null || $name === 'default') { |
||
78 | $first = $name; |
||
79 | } |
||
80 | if (empty($c['project_root'])) { |
||
81 | $c['project_root'] = dirname($container->getParameter('kernel.root_dir')); |
||
82 | } |
||
83 | |||
84 | $storageDefinition = $container->register('php_translation.storage.'.$name, StorageService::class); |
||
85 | |||
86 | // Register a file storage |
||
87 | $def = new DefinitionDecorator('php_translation.single_storage.file.abstract'); |
||
88 | $def->replaceArgument(2, $c['output_dir']) |
||
89 | ->addTag('php_translation.storage', ['type' => 'local', 'name' => $name]); |
||
90 | $container->setDefinition('php_translation.single_storage.file.'.$name, $def); |
||
91 | |||
92 | // Add storages |
||
93 | if (!empty($c['remote_storage'])) { |
||
94 | foreach ($c['remote_storage'] as $serviceId) { |
||
95 | $storageDefinition->addMethodCall('addRemoteStorage', [new Reference($serviceId)]); |
||
96 | } |
||
97 | } |
||
98 | if (!empty($c['local_storage'])) { |
||
99 | foreach ($c['local_storage'] as $serviceId) { |
||
100 | $storageDefinition->addMethodCall('addLocalStorage', [new Reference($serviceId)]); |
||
101 | } |
||
102 | } |
||
103 | 1 | } |
|
104 | |||
105 | 1 | if ($first !== null) { |
|
106 | // Create some aliases for the default storage |
||
107 | $container->setAlias('php_translation.storage', 'php_translation.storage.'.$first); |
||
108 | $container->setAlias('php_translation.storage.default', 'php_translation.storage.'.$first); |
||
109 | } |
||
110 | |||
111 | 1 | $container->getDefinition('php_translation.configuration_manager') |
|
112 | 1 | ->replaceArgument(0, $config['configs']); |
|
113 | 1 | } |
|
114 | |||
115 | private function enableWebUi(ContainerBuilder $container, $config) |
||
118 | |||
119 | private function enableEditInPlace(ContainerBuilder $container, $config) |
||
136 | |||
137 | private function enableSymfonyProfiler(ContainerBuilder $container, $config) |
||
141 | |||
142 | private function enableFallbackAutoTranslator(ContainerBuilder $container, $config) |
||
152 | |||
153 | public function getAlias() |
||
157 | } |
||
158 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: