|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Bundle\InfoMessages\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\DependencyInjection\ChildDefinition; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
7
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
|
8
|
|
|
use Symfony\Component\Config\FileLocator; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
|
10
|
|
|
|
|
11
|
|
|
class InfoMessagesExtension extends Extension |
|
12
|
|
|
{ |
|
13
|
|
|
const ABSTRACT_SERVICE_DEFINITION_ID = 'eXpansion.info_messages.config.messages.abstract'; |
|
14
|
|
|
|
|
15
|
|
|
const CONFIG_PATH_PREFIX = 'eXpansion/Messages/InfoMessages/'; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Loads a specific configuration. |
|
19
|
|
|
* |
|
20
|
|
|
* @param array $configs An array of configuration values |
|
21
|
|
|
* @param ContainerBuilder $container A ContainerBuilder instance |
|
22
|
|
|
* |
|
23
|
|
|
* @throws \InvalidArgumentException When provided tag is not defined in this extension |
|
24
|
|
|
*/ |
|
25
|
|
|
public function load(array $configs, ContainerBuilder $container) |
|
26
|
|
|
{ |
|
27
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
28
|
|
|
$loader->load('configs.yml'); |
|
29
|
|
|
$loader->load('plugins.yml'); |
|
30
|
|
|
|
|
31
|
|
|
$locales = $container->getParameter('expansion.core.supported_locales'); |
|
32
|
|
|
$defaultMessages = $container->getParameter('eXpansion_info_messages_default'); |
|
33
|
|
|
|
|
34
|
|
|
foreach ($locales as $locale) { |
|
35
|
|
|
$id = "eXpansion.info_messages.config.messages.$locale"; |
|
36
|
|
|
|
|
37
|
|
|
$service = $container->setDefinition($id, new ChildDefinition(self::ABSTRACT_SERVICE_DEFINITION_ID)) |
|
38
|
|
|
->replaceArgument('$path', self::CONFIG_PATH_PREFIX . "$locale") |
|
39
|
|
|
->replaceArgument('$name', "expansion_info_messages.config.messages.$locale.name") |
|
40
|
|
|
->addTag("expansion.config"); |
|
41
|
|
|
|
|
42
|
|
|
if (isset($defaultMessages[$locale])) { |
|
43
|
|
|
$service->replaceArgument('$defaultValue', $defaultMessages[$locale]); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|