Skip to content

Commit fe9df00

Browse files
committed
Merge pull request #171 from WouterJ/fix_xml_whitespace
Improved whitespace handling by Extension
2 parents 0b23d2a + eea3b66 commit fe9df00

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
@@ -37,7 +37,7 @@ public function load(array $configs, ContainerBuilder $container)
3737
// add the routers defined in the configuration mapping
3838
$router = $container->getDefinition($this->getAlias() . '.router');
3939
foreach ($config['chain']['routers_by_id'] as $id => $priority) {
40-
$router->addMethodCall('add', array(new Reference($id), $priority));
40+
$router->addMethodCall('add', array(new Reference($id), trim($priority)));
4141
}
4242

4343
$this->setupFormTypes($config, $container, $loader);
@@ -65,6 +65,13 @@ public function setupFormTypes(array $config, ContainerBuilder $container, Loade
6565
*/
6666
private function setupDynamicRouter(array $config, ContainerBuilder $container, LoaderInterface $loader)
6767
{
68+
// strip whitespace (XML support)
69+
foreach (array('controllers_by_type', 'controllers_by_class', 'templates_by_class', 'route_filters_by_id') as $option) {
70+
$config[$option] = array_map(function ($value) {
71+
return trim($value);
72+
}, $config[$option]);
73+
}
74+
6875
$container->setParameter($this->getAlias() . '.generic_controller', $config['generic_controller']);
6976
$container->setParameter($this->getAlias() . '.controllers_by_type', $config['controllers_by_type']);
7077
$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)