1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alpixel\Bundle\MenuBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Config\FileLocator; |
6
|
|
|
use Symfony\Component\Yaml\Parser; |
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
8
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
9
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
10
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
11
|
|
|
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* This is the class that loads and manages your bundle configuration. |
15
|
|
|
* |
16
|
|
|
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html |
17
|
|
|
*/ |
18
|
|
|
class AlpixelMenuExtension extends Extension implements PrependExtensionInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* {@inheritdoc} |
22
|
|
|
*/ |
23
|
|
|
public function load(array $configs, ContainerBuilder $container) |
24
|
|
|
{ |
25
|
|
|
if (!$container->hasParameter('default_locale')) { |
26
|
|
|
throw new UndefinedOptionsException('The default locale parameter must be defined under parameters in your symfony configuration'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
$configuration = new Configuration(); |
30
|
|
|
$this->processConfiguration($configuration, $configs); |
31
|
|
|
|
32
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
33
|
|
|
$loader->load('services.yml'); |
34
|
|
|
|
35
|
|
|
$menuBuilder = $container->getDefinition('alpixel_menu.builder'); |
36
|
|
|
$menuBuilder->addMethodCall('setDefaultLocale', [$container->getParameter('default_locale')]); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function prepend(ContainerBuilder $container) |
40
|
|
|
{ |
41
|
|
|
$parser = new Parser(); |
42
|
|
|
$config = $parser->parse(file_get_contents(__DIR__ . '/../Resources/config/config.yml')); |
43
|
|
|
|
44
|
|
|
foreach ($config as $key => $configuration) { |
|
|
|
|
45
|
|
|
$container->prependExtensionConfig($key, $configuration); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.