Skip to content

Commit

Permalink
Merge pull request #1034 from FriendsOfSymfony/is_decodeable
Browse files Browse the repository at this point in the history
Make it possible to override listener services, add extension point to body listener
  • Loading branch information
lsmith77 committed May 14, 2015
2 parents 7cb532f + a3ee6d7 commit d20cbc4
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 71 deletions.
76 changes: 62 additions & 14 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
class Configuration implements ConfigurationInterface
{
private $forceOptionValues = array(false, true, 'force');
public static $forceOptionValues = array(false, true, 'force');

/**
* Generates the configuration tree.
Expand All @@ -42,18 +42,37 @@ public function getConfigTreeBuilder()
->children()
->scalarNode('disable_csrf_role')->defaultNull()->end()
->arrayNode('access_denied_listener')
->useAttributeAsKey('name')
->prototype('boolean')->end()
->canBeEnabled()
->beforeNormalization()
->ifArray()->then(function($v) { if (!empty($v) && empty($v['formats'])) { unset($v['enabled']); $v = array('enabled' => true, 'formats' => $v); } return $v; })
->end()
->fixXmlConfig('format', 'formats')
->children()
->scalarNode('service')->defaultNull()->end()
->arrayNode('formats')
->useAttributeAsKey('name')
->prototype('boolean')->end()
->end()
->end()
->end()
->scalarNode('unauthorized_challenge')->defaultNull()->end()
->scalarNode('param_fetcher_listener')->defaultFalse()
->arrayNode('param_fetcher_listener')
->validate()
->ifNotInArray($this->forceOptionValues)
->thenInvalid('The param_fetcher_listener option does not support %s. Please choose one of '.json_encode($this->forceOptionValues))
->ifNotInArray(Configuration::$forceOptionValues)
->thenInvalid('The param_fetcher_listener option does not support %s. Please choose one of '.json_encode(Configuration::$forceOptionValues))
->end()
->canBeEnabled()
->children()
->scalarNode('service')->defaultNull()->end()
->end()
->end()
->scalarNode('cache_dir')->cannotBeEmpty()->defaultValue('%kernel.cache_dir%/fos_rest')->end()
->scalarNode('allowed_methods_listener')->defaultFalse()->end()
->arrayNode('allowed_methods_listener')
->canBeEnabled()
->children()
->scalarNode('service')->defaultNull()->end()
->end()
->end()
->arrayNode('routing_loader')
->addDefaultsIfNotSet()
->children()
Expand Down Expand Up @@ -124,8 +143,18 @@ private function addViewSection(ArrayNodeDefinition $rootNode)
->prototype('boolean')->end()
->end()
->arrayNode('mime_types')
->useAttributeAsKey('name')
->prototype('variable')->end()
->canBeEnabled()
->beforeNormalization()
->ifArray()->then(function($v) { if (!empty($v) && empty($v['formats'])) { unset($v['enabled']); $v = array('enabled' => true, 'formats' => $v); } return $v; })
->end()
->fixXmlConfig('format', 'formats')
->children()
->scalarNode('service')->defaultNull()->end()
->arrayNode('formats')
->useAttributeAsKey('name')
->prototype('variable')->end()
->end()
->end()
->end()
->arrayNode('formats')
->useAttributeAsKey('name')
Expand All @@ -137,10 +166,18 @@ private function addViewSection(ArrayNodeDefinition $rootNode)
->defaultValue(array('html' => true))
->prototype('boolean')->end()
->end()
->scalarNode('view_response_listener')->defaultFalse()
->arrayNode('view_response_listener')
->beforeNormalization()
->ifString()->then(function($v) { return array('enabled' => true, 'mode' => $v); })
->end()
->validate()
->ifNotInArray($this->forceOptionValues)
->thenInvalid('The view_response_listener option does not support %s. Please choose one of '.json_encode($this->forceOptionValues))
->ifTrue(function ($v) { return !in_array($v['mode'], Configuration::$forceOptionValues); })
->thenInvalid('The view_response_listener "mode" does not support %s. Please choose one of '.json_encode(Configuration::$forceOptionValues))
->end()
->canBeEnabled()
->children()
->scalarNode('service')->defaultNull()->end()
->scalarNode('mode')->defaultFalse()->end()
->end()
->end()
->scalarNode('failed_validation')->defaultValue(Codes::HTTP_BAD_REQUEST)->end()
Expand Down Expand Up @@ -168,7 +205,9 @@ private function addBodyListenerSection(ArrayNodeDefinition $rootNode)
->fixXmlConfig('decoder', 'decoders')
->addDefaultsIfNotSet()
->canBeUnset()
->canBeDisabled()
->children()
->scalarNode('service')->defaultNull()->end()
->scalarNode('default_format')->defaultNull()->end()
->booleanNode('throw_exception_on_unsupported_content_type')
->defaultFalse()
Expand Down Expand Up @@ -213,7 +252,9 @@ private function addFormatListenerSection(ArrayNodeDefinition $rootNode)
return $v;
})
->end()
->canBeEnabled()
->children()
->scalarNode('service')->defaultNull()->end()
->arrayNode('rules')
->cannotBeOverwritten()
->prototype('array')
Expand All @@ -235,8 +276,15 @@ private function addFormatListenerSection(ArrayNodeDefinition $rootNode)
->end()
->arrayNode('media_type')
->children()
->scalarNode('version_regex')
->defaultValue('/(v|version)=(?P<version>[0-9\.]+)/')
->arrayNode('version_regex')
->canBeEnabled()
->beforeNormalization()
->ifString()->then(function($v) { return array('enabled' => true, 'regex' => $v); })
->end()
->children()
->scalarNode('service')->defaultNull()->end()
->scalarNode('regex')->defaultValue('/(v|version)=(?P<version>[0-9\.]+)/')->end()
->end()
->end()
->end()
->end()
Expand Down
Loading

3 comments on commit d20cbc4

@nass600
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi guys.

My param_fetcher_listener: force config is breaking after this commit due to expecting an array input and looking for changes in the documentation didn't find any thing until I reach this.

Maybe a change in the documentation for param fetcher is missing, explaining the new structure and how to reproduce the force behaviour.

Thanks

@SymonSays
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey,

Just had the same problem as nass600, had to revert back to the previous version. Can you please have a look at it, I think more and more people will have problems with this.

Thanks and keep up the good work!

@vkartaviy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same problem with this commit, it looks like Configuration bug...

Please sign in to comment.