Skip to content

Commit e620c99

Browse files
committed
Merge pull request #1055 from FriendsOfSymfony/version_regexp
fix regression in handling for version_regex
2 parents 2d13ee1 + 1ff1e10 commit e620c99

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

DependencyInjection/Configuration.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ private function addFormatListenerSection(ArrayNodeDefinition $rootNode)
251251
})
252252
->end()
253253
->canBeEnabled()
254+
->validate()
255+
->ifTrue(function ($v) { return empty($v['rules']) && !empty($v['media_type']['enabled']); })
256+
->thenInvalid('To enable the "media_type" setting, a "rules" setting must also needs to be defined for the "format_listener"')
257+
->end()
254258
->children()
255259
->scalarNode('service')->defaultNull()->end()
256260
->arrayNode('rules')
@@ -273,18 +277,13 @@ private function addFormatListenerSection(ArrayNodeDefinition $rootNode)
273277
->end()
274278
->end()
275279
->arrayNode('media_type')
276-
->children()
277-
->arrayNode('version_regex')
278-
->canBeEnabled()
279-
->beforeNormalization()
280-
->ifString()->then(function($v) { return array('enabled' => true, 'regex' => $v); })
281-
->end()
282-
->children()
283-
->scalarNode('service')->defaultNull()->end()
284-
->scalarNode('regex')->defaultValue('/(v|version)=(?P<version>[0-9\.]+)/')->end()
285-
->end()
286-
->end()
287-
->end()
280+
->canBeEnabled()
281+
->beforeNormalization()
282+
->ifString()->then(function($v) { return array('enabled' => true, 'version_regex' => $v); })
283+
->end()
284+
->children()
285+
->scalarNode('service')->defaultNull()->end()
286+
->scalarNode('version_regex')->defaultValue('/(v|version)=(?P<version>[0-9\.]+)/')->end()
288287
->end()
289288
->end()
290289
->end()

Tests/DependencyInjection/FOSRestExtensionTest.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function testLoadFormatListenerWithSingleRule()
171171
{
172172
$config = array(
173173
'fos_rest' => array('format_listener' => array(
174-
'rules' => array('path' => '/')
174+
'rules' => array('path' => '/'),
175175
)),
176176
);
177177
$this->extension->load($config, $this->container);
@@ -207,7 +207,7 @@ public function testLoadFormatListenerWithMultipleRule()
207207
'fos_rest' => array('format_listener' => array(
208208
'rules' => array(
209209
array('path' => '/foo'),
210-
array('path' => '/')
210+
array('path' => '/'),
211211
)
212212
)),
213213
);
@@ -216,6 +216,32 @@ public function testLoadFormatListenerWithMultipleRule()
216216
$this->assertTrue($this->container->hasDefinition('fos_rest.format_listener'));
217217
}
218218

219+
public function testLoadFormatListenerMediaType()
220+
{
221+
$config = array(
222+
'fos_rest' => array('format_listener' => array(
223+
'rules' => array('path' => '/'),
224+
'media_type' => true,
225+
)),
226+
);
227+
$this->extension->load($config, $this->container);
228+
229+
$this->assertTrue($this->container->hasDefinition('fos_rest.version_listener'));
230+
}
231+
232+
/**
233+
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
234+
*/
235+
public function testLoadFormatListenerMediaTypeNoRules()
236+
{
237+
$config = array(
238+
'fos_rest' => array('format_listener' => array(
239+
'media_type' => true,
240+
)),
241+
);
242+
$this->extension->load($config, $this->container);
243+
}
244+
219245
public function testLoadServicesWithDefaults()
220246
{
221247
$this->extension->load(array(), $this->container);

0 commit comments

Comments
 (0)