1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Victoire\Bundle\I18nBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
7
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
8
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
9
|
|
|
use Symfony\Component\HttpKernel\Bundle\Bundle; |
10
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* This is the class that loads and manages your bundle configuration. |
14
|
|
|
* |
15
|
|
|
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} |
16
|
|
|
*/ |
17
|
|
|
class VictoireI18nExtension extends Extension implements PrependExtensionInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
public function load(array $configs, ContainerBuilder $container) |
23
|
|
|
{ |
24
|
|
|
$configuration = new Configuration(); |
25
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
26
|
|
|
|
27
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
28
|
|
|
$loader->load('services.yml'); |
29
|
|
|
|
30
|
|
|
$container->setParameter( |
31
|
|
|
'victoire_i18n.available_locales', $config['available_locales'] |
32
|
|
|
); |
33
|
|
|
$container->setParameter( |
34
|
|
|
'victoire_i18n.locale_pattern_table', $config['locale_pattern_table'] |
35
|
|
|
); |
36
|
|
|
$container->setParameter( |
37
|
|
|
'victoire_i18n.victoire_locale', $config['victoire_locale'] |
38
|
|
|
); |
39
|
|
|
$container->setParameter( |
40
|
|
|
'victoire_i18n.users_locale.domains', $config['users_locale_domains'] |
41
|
|
|
); |
42
|
|
|
$container->setParameter( |
43
|
|
|
'victoire_i18n.locale_pattern', $config['locale_pattern'] |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
|
public function prepend(ContainerBuilder $container) |
51
|
|
|
{ |
52
|
|
|
// automatically enable gedmo_translatable doctrine extension (BasePage I18n) |
53
|
|
|
foreach ($container->getExtensions() as $name => $extension) { |
54
|
|
|
switch ($name) { |
55
|
|
|
case 'doctrine': |
56
|
|
|
$container->prependExtensionConfig($name, [ |
57
|
|
|
'orm' => [ |
58
|
|
|
'mappings' => [ |
59
|
|
|
'gedmo_translatable' => [ |
60
|
|
|
'type' => 'annotation', |
61
|
|
|
'prefix' => 'Gedmo\Translatable\Entity', |
62
|
|
|
'dir' => '%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity', |
63
|
|
|
'is_bundle' => false, |
64
|
|
|
], |
65
|
|
|
], |
66
|
|
|
], |
67
|
|
|
]); |
68
|
|
|
break; |
69
|
|
|
case 'stof_doctrine_extensions': |
70
|
|
|
$container->prependExtensionConfig($name, [ |
71
|
|
|
'persist_default_translation' => true, |
72
|
|
|
'orm' => [ |
73
|
|
|
'default' => [ |
74
|
|
|
'translatable' => true, |
75
|
|
|
], |
76
|
|
|
], |
77
|
|
|
]); |
78
|
|
|
break; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|