Skip to content

Commit ceb10f9

Browse files
committed
Merge pull request #1035 from FriendsOfSymfony/phramz-patch-2
includes #1020 as well as a test
2 parents 941569e + 4c49328 commit ceb10f9

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

DependencyInjection/Configuration.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,18 @@ private function addFormatListenerSection(ArrayNodeDefinition $rootNode)
201201
->fixXmlConfig('rule', 'rules')
202202
->addDefaultsIfNotSet()
203203
->canBeUnset()
204+
->beforeNormalization()
205+
->ifTrue(function ($v) {
206+
// check if we got an assoc array in rules
207+
return isset($v['rules'])
208+
&& is_array($v['rules'])
209+
&& array_keys($v['rules']) !== range(0, count($v['rules']) - 1);
210+
})
211+
->then(function($v) {
212+
$v['rules'] = array($v['rules']);
213+
return $v;
214+
})
215+
->end()
204216
->children()
205217
->arrayNode('rules')
206218
->cannotBeOverwritten()

Tests/DependencyInjection/FOSRestExtensionTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,33 @@ public function testLoadFormatListenerWithDefaults()
167167
$this->assertFalse($this->container->hasDefinition('fos_rest.format_listener'));
168168
}
169169

170+
public function testLoadFormatListenerWithSingleRule()
171+
{
172+
$config = array(
173+
'fos_rest' => array('format_listener' => array(
174+
'rules' => array('path' => '/')
175+
)),
176+
);
177+
$this->extension->load($config, $this->container);
178+
179+
$this->assertTrue($this->container->hasDefinition('fos_rest.format_listener'));
180+
}
181+
182+
public function testLoadFormatListenerWithMultipleRule()
183+
{
184+
$config = array(
185+
'fos_rest' => array('format_listener' => array(
186+
'rules' => array(
187+
array('path' => '/foo'),
188+
array('path' => '/')
189+
)
190+
)),
191+
);
192+
$this->extension->load($config, $this->container);
193+
194+
$this->assertTrue($this->container->hasDefinition('fos_rest.format_listener'));
195+
}
196+
170197
public function testLoadServicesWithDefaults()
171198
{
172199
$this->extension->load(array(), $this->container);

0 commit comments

Comments
 (0)