Skip to content

Commit 080f7b0

Browse files
committed
Merge pull request #167 from symfony-cmf/validate-generic-controller
validate generic_controller in di extension and reformat code
2 parents 639d666 + 54e2584 commit 080f7b0

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Changelog
22
=========
33

4+
* **2013-08-09**: dynamic.generic_controller is now defaulting to null instead
5+
of the controller from CmfContentBundle. CmfCoreBundle is prepending the
6+
CmfContentBundle generic controller if that bundle is present. If you do not
7+
have Core and Content, you need to configure the value explicitly if you want
8+
routes specifying a template to use the generic controller or have
9+
template_by_class mapping configuration.
10+
411
1.1.0-RC2
512
---------
613

DependencyInjection/CmfRoutingExtension.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,8 @@ private function setupDynamicRouter(array $config, ContainerBuilder $container,
7272
$container->setParameter($this->getAlias() . '.controllers_by_type', $config['controllers_by_type']);
7373
$container->setParameter($this->getAlias() . '.controllers_by_class', $config['controllers_by_class']);
7474
$container->setParameter($this->getAlias() . '.templates_by_class', $config['templates_by_class']);
75-
// if the content class defines the template, we also need to make sure we use the generic controller for those routes
76-
$controllerForTemplates = array();
77-
foreach ($config['templates_by_class'] as $key => $value) {
78-
$controllerForTemplates[$key] = $config['generic_controller'];
79-
}
80-
$container->setParameter($this->getAlias() . '.defined_templates_class', $controllerForTemplates);
8175
$container->setParameter($this->getAlias() . '.uri_filter_regexp', $config['uri_filter_regexp']);
76+
8277
$locales = false;
8378
if (isset($config['locales'])) {
8479
$locales = $config['locales'];
@@ -131,9 +126,21 @@ private function setupDynamicRouter(array $config, ContainerBuilder $container,
131126
if (!empty($config['controllers_by_class'])) {
132127
$dynamic->addMethodCall('addRouteEnhancer', array(new Reference($this->getAlias() . '.enhancer_controllers_by_class')));
133128
}
134-
if (!empty($config['generic_controller']) && !empty($config['templates_by_class'])) {
135-
$dynamic->addMethodCall('addRouteEnhancer', array(new Reference($this->getAlias() . '.enhancer_controller_for_templates_by_class')));
129+
130+
if (!empty($config['templates_by_class'])) {
136131
$dynamic->addMethodCall('addRouteEnhancer', array(new Reference($this->getAlias() . '.enhancer_templates_by_class')));
132+
133+
if (null === $config['generic_controller']) {
134+
throw new InvalidConfigurationException('If you configure templates_by_class, you need to configure a generic_router. If you are sure you do not need a generic router, set the field to false to disable explicitly.');
135+
} elseif (is_string($config['generic_controller'])) {
136+
// if the content class defines the template, we also need to make sure we use the generic controller for those routes
137+
$controllerForTemplates = array();
138+
foreach ($config['templates_by_class'] as $key => $value) {
139+
$controllerForTemplates[$key] = $config['generic_controller'];
140+
}
141+
$container->setParameter($this->getAlias() . '.defined_templates_class', $controllerForTemplates);
142+
$dynamic->addMethodCall('addRouteEnhancer', array(new Reference($this->getAlias() . '.enhancer_controller_for_templates_by_class')));
143+
}
137144
}
138145
if (!empty($config['route_filters_by_id'])) {
139146
$matcher = $container->getDefinition('cmf_routing.nested_matcher');

0 commit comments

Comments
 (0)