1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alpixel\Bundle\MenuBundle\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\DependencyInjection\Extension; |
10
|
|
|
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* This is the class that loads and manages your bundle configuration. |
14
|
|
|
* |
15
|
|
|
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html |
16
|
|
|
*/ |
17
|
|
|
class AlpixelMenuExtension extends Extension implements PrependExtensionInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
public function load(array $configs, ContainerBuilder $container) |
23
|
|
|
{ |
24
|
|
|
if (!$container->hasParameter('default_locale')) { |
25
|
|
|
throw new UndefinedOptionsException('The default locale parameter must be defined under parameters in your symfony configuration'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$configuration = new Configuration(); |
29
|
|
|
$this->processConfiguration($configuration, $configs); |
30
|
|
|
|
31
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
32
|
|
|
$loader->load('services.yml'); |
33
|
|
|
|
34
|
|
|
$menuBuilder = $container->getDefinition('alpixel_menu.builder'); |
35
|
|
|
$menuBuilder->addMethodCall('setDefaultLocale', [$container->getParameter('default_locale')]); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function prepend(ContainerBuilder $container) |
39
|
|
|
{ |
40
|
|
|
$parser = new Parser(); |
41
|
|
|
$config = $parser->parse(file_get_contents(__DIR__ . '/../Resources/config/config.yml')); |
42
|
|
|
|
43
|
|
|
foreach ($config as $key => $configuration) { |
44
|
|
|
$container->prependExtensionConfig($key, $configuration); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|