diff --git a/Controller/ExceptionController.php b/Controller/ExceptionController.php index 6b7b18c29..172528cdc 100644 --- a/Controller/ExceptionController.php +++ b/Controller/ExceptionController.php @@ -41,7 +41,7 @@ class ExceptionController extends ContainerAware protected function createExceptionWrapper(array $parameters) { /** @var ExceptionWrapperHandlerInterface $exceptionWrapperHandler */ - $exceptionWrapperHandler = $this->container->get('fos_rest.view.exception_wrapper_handler'); + $exceptionWrapperHandler = $this->container->get('fos_rest.exception_handler'); return $exceptionWrapperHandler->wrap($parameters); } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 4a3a0d582..9c0283649 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -76,6 +76,7 @@ public function getConfigTreeBuilder() ->scalarNode('templating')->defaultValue('templating')->end() ->scalarNode('serializer')->defaultNull()->end() ->scalarNode('view_handler')->defaultValue('fos_rest.view_handler.default')->end() + ->scalarNode('exception_handler')->defaultValue('fos_rest.view.exception_wrapper_handler')->end() ->scalarNode('inflector')->defaultValue('fos_rest.inflector.doctrine')->end() ->scalarNode('validator')->defaultValue('validator')->end() ->end() @@ -144,7 +145,7 @@ private function addViewSection(ArrayNodeDefinition $rootNode) ->end() ->scalarNode('failed_validation')->defaultValue(Codes::HTTP_BAD_REQUEST)->end() ->scalarNode('empty_content')->defaultValue(Codes::HTTP_NO_CONTENT)->end() - ->scalarNode('exception_wrapper_handler')->defaultValue('FOS\RestBundle\View\ExceptionWrapperHandler')->end() + ->scalarNode('exception_wrapper_handler')->defaultNull()->end() ->booleanNode('serialize_null')->defaultFalse()->end() ->arrayNode('jsonp_handler') ->canBeUnset() diff --git a/Resources/config/view.xml b/Resources/config/view.xml index fbacf5f13..071ac568d 100644 --- a/Resources/config/view.xml +++ b/Resources/config/view.xml @@ -8,7 +8,7 @@ - + FOS\RestBundle\View\ExceptionWrapperHandler FOS\RestBundle\View\ViewHandler FOS\RestBundle\View\JsonpHandler FOS\RestBundle\Serializer\ExceptionWrapperSerializeHandler @@ -41,7 +41,7 @@ %fos_rest.view_handler.jsonp.callback_param% - + diff --git a/Resources/doc/configuration-reference.rst b/Resources/doc/configuration-reference.rst index 3f659ca94..ccafb7e48 100644 --- a/Resources/doc/configuration-reference.rst +++ b/Resources/doc/configuration-reference.rst @@ -25,6 +25,7 @@ Full default configuration templating: templating serializer: null view_handler: fos_rest.view_handler.default + exception_handler: fos_rest.view.exception_wrapper_handler inflector: fos_rest.inflector.doctrine validator: validator serializer: @@ -52,13 +53,15 @@ Full default configuration view_response_listener: false failed_validation: 400 empty_content: 204 - exception_wrapper_handler: FOS\RestBundle\View\ExceptionWrapperHandler + exception_wrapper_handler: null serialize_null: false jsonp_handler: callback_param: callback callback_filter: '/(^[a-z0-9_]+$)|(^YUI\.Env\.JSONP\._[0-9]+$)/i' mime_type: application/javascript+jsonp exception: + enabled: false + exception_controller: null codes: # Prototype @@ -68,29 +71,31 @@ Full default configuration # Prototype name: ~ body_listener: - default_format: null + default_format: null throw_exception_on_unsupported_content_type: false decoders: # Prototype name: ~ - array_normalizer: null + array_normalizer: + service: null + forms: false format_listener: rules: - # Prototype array - - - # URL path info - path: null + # URL path info + path: null - # URL host name - host: null + # URL host name + host: null - # Method for URL - methods: null - prefer_extension: true - fallback_format: html - exception_fallback_format: ~ - priorities: [] + # Method for URL + methods: null + stop: false + prefer_extension: true + fallback_format: html + exception_fallback_format: null + priorities: [] media_type: version_regex: '/(v|version)=(?P[0-9\.]+)/' + diff --git a/Tests/DependencyInjection/FOSRestExtensionTest.php b/Tests/DependencyInjection/FOSRestExtensionTest.php index 010d40d5a..0faa58655 100644 --- a/Tests/DependencyInjection/FOSRestExtensionTest.php +++ b/Tests/DependencyInjection/FOSRestExtensionTest.php @@ -172,6 +172,7 @@ public function testLoadServicesWithDefaults() $this->extension->load(array(), $this->container); $this->assertAlias('fos_rest.view_handler.default', 'fos_rest.view_handler'); + $this->assertAlias('fos_rest.view.exception_wrapper_handler', 'fos_rest.exception_handler'); } public function testLoadFormatsWithDefaults() diff --git a/Tests/View/ViewHandlerTest.php b/Tests/View/ViewHandlerTest.php index 06e3f5a83..eb53f4fce 100644 --- a/Tests/View/ViewHandlerTest.php +++ b/Tests/View/ViewHandlerTest.php @@ -209,7 +209,7 @@ public function testShouldReturnErrorResponseWhenDataContainsFormAndFormIsNotVal ; $container->set('fos_rest.serializer', $serializer); - $container->set('fos_rest.view.exception_wrapper_handler', new ExceptionWrapperHandler()); + $container->set('fos_rest.exception_handler', new ExceptionWrapperHandler()); //test $viewHandler = new ViewHandler(null, $expectedFailedValidationCode = Codes::HTTP_I_AM_A_TEAPOT); @@ -309,7 +309,7 @@ private function setupMockedSerializer($container, $expected) ->method('get') ->with($this->logicalOr( $this->equalTo('fos_rest.serializer'), - $this->equalTo('fos_rest.view.exception_wrapper_handler') + $this->equalTo('fos_rest.exception_handler') )) ->will( $this->returnCallback( @@ -317,7 +317,7 @@ function ($method) use ($serializer) { switch ($method) { case 'fos_rest.serializer': return $serializer; - case 'fos_rest.view.exception_wrapper_handler': + case 'fos_rest.exception_handler': return new ExceptionWrapperHandler(); } } diff --git a/View/ViewHandler.php b/View/ViewHandler.php index 3cfc7ccdf..5fd706e41 100644 --- a/View/ViewHandler.php +++ b/View/ViewHandler.php @@ -500,7 +500,7 @@ private function getDataFromView(View $view) } /** @var ExceptionWrapperHandlerInterface $exceptionWrapperHandler */ - $exceptionWrapperHandler = $this->container->get('fos_rest.view.exception_wrapper_handler'); + $exceptionWrapperHandler = $this->container->get('fos_rest.exception_handler'); return $exceptionWrapperHandler->wrap( array(