Skip to content

Commit eea3b66

Browse files
committed
Fixed whitespace handling for settings.
In XML, a value may contain whitespace. This should be trimmed if the whitespace is not important.
1 parent 5f1b95d commit eea3b66

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

DependencyInjection/CmfRoutingExtension.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function load(array $configs, ContainerBuilder $container)
4040
// add the routers defined in the configuration mapping
4141
$router = $container->getDefinition($this->getAlias() . '.router');
4242
foreach ($config['chain']['routers_by_id'] as $id => $priority) {
43-
$router->addMethodCall('add', array(new Reference($id), $priority));
43+
$router->addMethodCall('add', array(new Reference($id), trim($priority)));
4444
}
4545

4646
$this->setupFormTypes($config, $container, $loader);
@@ -68,6 +68,13 @@ public function setupFormTypes(array $config, ContainerBuilder $container, Loade
6868
*/
6969
private function setupDynamicRouter(array $config, ContainerBuilder $container, LoaderInterface $loader)
7070
{
71+
// strip whitespace (XML support)
72+
foreach (array('controllers_by_type', 'controllers_by_class', 'templates_by_class', 'route_filters_by_id') as $option) {
73+
$config[$option] = array_map(function ($value) {
74+
return trim($value);
75+
}, $config[$option]);
76+
}
77+
7178
$container->setParameter($this->getAlias() . '.generic_controller', $config['generic_controller']);
7279
$container->setParameter($this->getAlias() . '.controllers_by_type', $config['controllers_by_type']);
7380
$container->setParameter($this->getAlias() . '.controllers_by_class', $config['controllers_by_class']);

Tests/Unit/DependencyInjection/CmfRoutingExtensionTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,46 @@ function ($call) {
135135
$this->assertEquals($providedRouters, $routersAdded);
136136
}
137137

138+
public function testWhitespaceInPriorities()
139+
{
140+
$config = array(
141+
array(
142+
'dynamic' => array(
143+
'route_provider_service_id' => 'test_route_provider_service',
144+
'enabled' => true,
145+
'controllers_by_type' => array(
146+
'Acme\Foo' => '
147+
acme_main.controller:indexAction
148+
'
149+
),
150+
),
151+
'chain' => array(
152+
'routers_by_id' => array(
153+
'acme_test.router' => '
154+
100
155+
',
156+
),
157+
),
158+
)
159+
);
160+
161+
$builder = $this->getBuilder($config);
162+
163+
$methodCalls = $builder->getDefinition('cmf_routing.router')->getMethodCalls();
164+
$addMethodCalls = array_filter(
165+
$methodCalls,
166+
function ($call) {
167+
return 'add' == $call[0];
168+
}
169+
);
170+
171+
$this->assertCount(1, $addMethodCalls);
172+
173+
$methodCall = current($addMethodCalls);
174+
175+
$this->assertSame('100', $methodCall[1][1]);
176+
177+
$controllers = $builder->getParameter('cmf_routing.controllers_by_type');
178+
$this->assertSame('acme_main.controller:indexAction', $controllers['Acme\Foo']);
179+
}
138180
}

0 commit comments

Comments
 (0)