9
9
* file that was distributed with this source code.
10
10
*/
11
11
12
-
13
12
namespace Symfony \Cmf \Bundle \BlogBundle \DependencyInjection ;
14
13
14
+ use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
15
15
use Symfony \Component \DependencyInjection \ContainerBuilder ;
16
16
use Symfony \Component \Config \FileLocator ;
17
17
use Symfony \Component \HttpKernel \DependencyInjection \Extension ;
18
18
use Symfony \Component \DependencyInjection \Loader \XmlFileLoader ;
19
-
20
19
use Symfony \Cmf \Bundle \RoutingBundle \Routing \DynamicRouter ;
21
20
22
21
/**
23
- * This is the class that loads and manages your bundle configuration
22
+ * This is the class that loads and manages your bundle configuration.
24
23
*
25
24
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
26
25
*/
@@ -38,25 +37,29 @@ public function load(array $configs, ContainerBuilder $container)
38
37
$ loader ->load ('services.xml ' );
39
38
40
39
if (isset ($ config ['persistence ' ]['phpcr ' ])) {
41
- $ this ->loadPhpcrPersistence ($ config , $ loader , $ container );
40
+ $ this ->loadPhpcrPersistence ($ config[ ' persistence ' ][ ' phpcr ' ] , $ loader , $ container );
42
41
}
43
42
44
- if (isset ( $ config [ ' sonata_admin ' ]) && $ config ['sonata_admin ' ]['enabled ' ]) {
45
- $ this ->loadSonataAdmin ($ config , $ loader , $ container );
43
+ if ($ config ['sonata_admin ' ]['enabled ' ]) {
44
+ $ this ->loadSonataAdmin ($ config[ ' sonata_admin ' ] , $ loader , $ container );
46
45
}
47
46
48
- if (isset ( $ config ['integrate_menu ' ]) && $ config [ ' integrate_menu ' ]['enabled ' ]) {
49
- $ this ->loadMenuIntegration ($ config , $ loader , $ container );
47
+ if ($ config ['menu ' ]['enabled ' ]) {
48
+ $ this ->loadMenu ($ config[ ' menu ' ] , $ loader , $ container );
50
49
}
51
50
52
- $ this ->loadPaginationIntegration ($ config , $ container );
51
+ if (!$ this ->handlePagination ($ config ['pagination ' ], $ loader , $ container )) {
52
+ // this parameter is used in the cmf_blog.blog_controller service definition, so
53
+ // it must be defined until it's a viable option to use the expression language instead
54
+ $ container ->setParameter ($ this ->getAlias ().'.pagination.posts_per_page ' , 0 );
55
+ }
53
56
}
54
57
55
- protected function loadPhpcrPersistence ($ config , XmlFileLoader $ loader , ContainerBuilder $ container )
58
+ private function loadPhpcrPersistence ($ config , XmlFileLoader $ loader , ContainerBuilder $ container )
56
59
{
57
- $ container ->setParameter ($ this ->getAlias ().'.blog_basepath ' , $ config ['persistence ' ][ ' phpcr ' ][ ' blog_basepath ' ]);
60
+ $ container ->setParameter ($ this ->getAlias ().'.blog_basepath ' , $ config ['blog_basepath ' ]);
58
61
59
- foreach ($ config ['persistence ' ][ ' phpcr ' ][ ' class ' ] as $ type => $ classFqn ) {
62
+ foreach ($ config ['class ' ] as $ type => $ classFqn ) {
60
63
$ container ->setParameter (
61
64
$ param = sprintf ('cmf_blog.phpcr.%s.class ' , $ type ),
62
65
$ classFqn
@@ -67,47 +70,64 @@ protected function loadPhpcrPersistence($config, XmlFileLoader $loader, Containe
67
70
$ loader ->load ('doctrine-phpcr.xml ' );
68
71
}
69
72
70
- protected function loadSonataAdmin (array $ config , XmlFileLoader $ loader , ContainerBuilder $ container )
73
+ private function loadSonataAdmin (array $ config , XmlFileLoader $ loader , ContainerBuilder $ container )
71
74
{
72
75
$ bundles = $ container ->getParameter ('kernel.bundles ' );
73
76
if (!isset ($ bundles ['SonataDoctrinePHPCRAdminBundle ' ])) {
74
- return ;
77
+ if ('auto ' === $ config ['enabled ' ]) {
78
+ return ;
79
+ }
80
+
81
+ throw new InvalidConfigurationException ('Explicitly enabled sonata admin integration but SonataDoctrinePHPCRAdminBundle is not loaded ' );
75
82
}
76
83
77
84
$ loader ->load ('admin.xml ' );
78
85
}
79
86
80
- protected function loadMenuIntegration (array $ config , XmlFileLoader $ loader , ContainerBuilder $ container )
87
+ private function loadMenu (array $ config , XmlFileLoader $ loader , ContainerBuilder $ container )
81
88
{
82
89
$ bundles = $ container ->getParameter ('kernel.bundles ' );
83
90
if (!isset ($ bundles ['CmfMenuBundle ' ])) {
84
- return ;
91
+ if ('auto ' === $ config ['enabled ' ]) {
92
+ return ;
93
+ }
94
+
95
+ throw new InvalidConfigurationException ('Explicitly enabled menu integration but CmfMenuBundle is not loaded ' );
85
96
}
86
97
87
- if (empty ($ config ['integrate_menu ' ][ ' content_key ' ])) {
98
+ if (empty ($ config ['content_key ' ])) {
88
99
if (!class_exists ('Symfony \\Cmf \\Bundle \\RoutingBundle \\Routing \\DynamicRouter ' )) {
89
- throw new \RuntimeException ('You need to set the content_key when not using the CmfRoutingBundle DynamicRouter ' );
100
+ if ('auto ' === $ config ['enabled ' ]) {
101
+ return ;
102
+ }
103
+
104
+ throw new InvalidConfigurationException ('You need to set the content_key when not using the CmfRoutingBundle DynamicRouter ' );
90
105
}
91
106
$ contentKey = DynamicRouter::CONTENT_KEY ;
92
107
} else {
93
- $ contentKey = $ config ['integrate_menu ' ][ ' content_key ' ];
108
+ $ contentKey = $ config ['content_key ' ];
94
109
}
95
110
96
- $ container ->setParameter (' cmf_blog .content_key ' , $ contentKey );
111
+ $ container ->setParameter ($ this -> getAlias (). ' .content_key ' , $ contentKey );
97
112
98
113
$ loader ->load ('menu.xml ' );
99
114
}
100
115
101
- protected function loadPaginationIntegration (array $ config , ContainerBuilder $ container )
116
+ private function handlePagination (array $ config, XmlFileLoader $ loader , ContainerBuilder $ container )
102
117
{
103
- if (isset ($ config ['pagination ' ]) && $ config ['pagination ' ]['enabled ' ]) {
104
- $ container ->setParameter ($ this ->getAlias ().'.pagination.enabled ' , true );
105
- $ container ->setParameter ($ this ->getAlias ().'.pagination.posts_per_page ' , $ config ['pagination ' ]['posts_per_page ' ]);
106
- } else {
107
- // this parameter is used in the cmf_blog.blog_controller service definition, so
108
- // it must be defined until it's a viable option to use the expression language instead
109
- $ container ->setParameter ($ this ->getAlias ().'.pagination.posts_per_page ' , 0 );
118
+ if (!$ config ['enabled ' ]) {
119
+ return false ;
110
120
}
121
+ if (!isset ($ bundles ['KnpPaginatorBundle ' ])) {
122
+ if ('auto ' === $ config ['enabled ' ]) {
123
+ return false ;
124
+ }
125
+
126
+ throw new InvalidConfigurationException ('Explicitly enabled pagination but KnpPaginatorBundle is not loaded ' );
127
+ }
128
+ $ container ->setParameter ($ this ->getAlias ().'.pagination.posts_per_page ' , $ config ['pagination ' ]['posts_per_page ' ]);
129
+
130
+ return true ;
111
131
}
112
132
113
133
/**
0 commit comments