forked from KnpLabs/KnpMenuBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKnpMenuExtension.php
79 lines (66 loc) · 2.66 KB
/
KnpMenuExtension.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace Knp\Bundle\MenuBundle\DependencyInjection;
use Knp\Menu\Factory\ExtensionInterface;
use Knp\Menu\ItemInterface;
use Knp\Menu\Matcher\Voter\VoterInterface;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
class KnpMenuExtension extends Extension implements PrependExtensionInterface
{
/**
* Handles the knp_menu configuration.
*
* @param array $configs The configurations being loaded
*/
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('menu.xml');
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
foreach ($config['providers'] as $builder => $enabled) {
if ($enabled) {
$container->getDefinition(\sprintf('knp_menu.menu_provider.%s', $builder))->addTag('knp_menu.provider');
}
}
if (isset($config['twig'])) {
$loader->load('twig.xml');
$container->setParameter('knp_menu.renderer.twig.template', $config['twig']['template']);
}
if ($config['templating']) {
trigger_deprecation('knplabs/knp-menu-bundle', '3.3', 'Using the templating component is deprecated since version 3.3, this option will be removed in version 4.');
$loader->load('templating.xml');
}
$container->setParameter('knp_menu.default_renderer', $config['default_renderer']);
$container->registerForAutoconfiguration(VoterInterface::class)
->addTag('knp_menu.voter');
$container->registerForAutoconfiguration(ExtensionInterface::class)
->addTag('knp_menu.factory_extension');
}
/**
* {@inheritdoc}
*/
public function getNamespace(): string
{
return 'http://knplabs.com/schema/dic/menu';
}
/**
* {@inheritdoc}
*/
public function getXsdValidationBasePath(): string
{
return __DIR__.'/../Resources/config/schema';
}
public function prepend(ContainerBuilder $container): void
{
if (!$container->hasExtension('twig')) {
return;
}
$refl = new \ReflectionClass(ItemInterface::class);
$path = \dirname($refl->getFileName()).'/Resources/views';
$container->prependExtensionConfig('twig', ['paths' => [$path]]);
}
}