forked from symfony-cmf/blog-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCmfBlogExtension.php
105 lines (88 loc) · 3.36 KB
/
CmfBlogExtension.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Bundle\BlogBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter;
/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class CmfBlogExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.xml');
$loader->load('initializer-phpcr.xml');
if ($config['use_sonata_admin']) {
$this->loadSonataAdmin($config, $loader, $container);
}
if ($config['integrate_menu']['enabled']) {
$this->loadMenuIntegration($config, $loader, $container);
}
foreach ($config['class'] as $type => $classFqn) {
$container->setParameter(
$param = sprintf('cmf_blog.%s_class', $type),
$classFqn
);
}
}
private function loadSonataAdmin($config, XmlFileLoader $loader, ContainerBuilder $container)
{
$bundles = $container->getParameter('kernel.bundles');
if ('auto' === $config['use_sonata_admin'] && !isset($bundles['SonataDoctrinePHPCRAdminBundle'])) {
return;
}
$loader->load('admin.xml');
$container->setParameter($this->getAlias() . '.blog_basepath', $config['blog_basepath']);
}
private function loadMenuIntegration($config, XmlFileLoader $loader, ContainerBuilder $container)
{
$bundles = $container->getParameter('kernel.bundles');
if ('auto' === $config['integrate_menu']['enabled'] && !isset($bundles['CmfMenuBundle'])) {
return;
}
if (empty($config['integrate_menu']['content_key'])) {
if (!class_exists('Symfony\\Cmf\\Bundle\\RoutingBundle\\Routing\\DynamicRouter')) {
if ('auto' === $config['integrate_menu']) {
return;
}
throw new \RuntimeException('You need to set the content_key when not using the CmfRoutingBundle DynamicRouter');
}
$contentKey = DynamicRouter::CONTENT_KEY;
} else {
$contentKey = $config['integrate_menu']['content_key'];
}
$container->setParameter('cmf_blog.content_key', $contentKey);
$loader->load('menu.xml');
}
/**
* Returns the base path for the XSD files.
*
* @return string The XSD base path
*/
public function getXsdValidationBasePath()
{
return __DIR__.'/../Resources/config/schema';
}
public function getNamespace()
{
return 'http://cmf.symfony.com/schema/dic/blog';
}
}