99 * file that was distributed with this source code.
1010 */
1111
12-
1312namespace Symfony \Cmf \Bundle \BlogBundle \DependencyInjection ;
1413
14+ use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
1515use Symfony \Component \DependencyInjection \ContainerBuilder ;
1616use Symfony \Component \Config \FileLocator ;
1717use Symfony \Component \HttpKernel \DependencyInjection \Extension ;
1818use Symfony \Component \DependencyInjection \Loader \XmlFileLoader ;
19-
2019use Symfony \Cmf \Bundle \RoutingBundle \Routing \DynamicRouter ;
2120
2221/**
23- * This is the class that loads and manages your bundle configuration
22+ * This is the class that loads and manages your bundle configuration.
2423 *
2524 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
2625 */
@@ -38,25 +37,29 @@ public function load(array $configs, ContainerBuilder $container)
3837 $ loader ->load ('services.xml ' );
3938
4039 if (isset ($ config ['persistence ' ]['phpcr ' ])) {
41- $ this ->loadPhpcrPersistence ($ config , $ loader , $ container );
40+ $ this ->loadPhpcrPersistence ($ config[ ' persistence ' ][ ' phpcr ' ] , $ loader , $ container );
4241 }
4342
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 );
4645 }
4746
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 );
5049 }
5150
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+ }
5356 }
5457
55- protected function loadPhpcrPersistence ($ config , XmlFileLoader $ loader , ContainerBuilder $ container )
58+ private function loadPhpcrPersistence ($ config , XmlFileLoader $ loader , ContainerBuilder $ container )
5659 {
57- $ container ->setParameter ($ this ->getAlias ().'.blog_basepath ' , $ config ['persistence ' ][ ' phpcr ' ][ ' blog_basepath ' ]);
60+ $ container ->setParameter ($ this ->getAlias ().'.blog_basepath ' , $ config ['blog_basepath ' ]);
5861
59- foreach ($ config ['persistence ' ][ ' phpcr ' ][ ' class ' ] as $ type => $ classFqn ) {
62+ foreach ($ config ['class ' ] as $ type => $ classFqn ) {
6063 $ container ->setParameter (
6164 $ param = sprintf ('cmf_blog.phpcr.%s.class ' , $ type ),
6265 $ classFqn
@@ -67,47 +70,64 @@ protected function loadPhpcrPersistence($config, XmlFileLoader $loader, Containe
6770 $ loader ->load ('doctrine-phpcr.xml ' );
6871 }
6972
70- protected function loadSonataAdmin (array $ config , XmlFileLoader $ loader , ContainerBuilder $ container )
73+ private function loadSonataAdmin (array $ config , XmlFileLoader $ loader , ContainerBuilder $ container )
7174 {
7275 $ bundles = $ container ->getParameter ('kernel.bundles ' );
7376 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 ' );
7582 }
7683
7784 $ loader ->load ('admin.xml ' );
7885 }
7986
80- protected function loadMenuIntegration (array $ config , XmlFileLoader $ loader , ContainerBuilder $ container )
87+ private function loadMenu (array $ config , XmlFileLoader $ loader , ContainerBuilder $ container )
8188 {
8289 $ bundles = $ container ->getParameter ('kernel.bundles ' );
8390 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 ' );
8596 }
8697
87- if (empty ($ config ['integrate_menu ' ][ ' content_key ' ])) {
98+ if (empty ($ config ['content_key ' ])) {
8899 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 ' );
90105 }
91106 $ contentKey = DynamicRouter::CONTENT_KEY ;
92107 } else {
93- $ contentKey = $ config ['integrate_menu ' ][ ' content_key ' ];
108+ $ contentKey = $ config ['content_key ' ];
94109 }
95110
96- $ container ->setParameter (' cmf_blog .content_key ' , $ contentKey );
111+ $ container ->setParameter ($ this -> getAlias (). ' .content_key ' , $ contentKey );
97112
98113 $ loader ->load ('menu.xml ' );
99114 }
100115
101- protected function loadPaginationIntegration (array $ config , ContainerBuilder $ container )
116+ private function handlePagination (array $ config, XmlFileLoader $ loader , ContainerBuilder $ container )
102117 {
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 ;
110120 }
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 ;
111131 }
112132
113133 /**
0 commit comments