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