Skip to content

Commit

Permalink
Merge pull request #942 from FriendsOfSymfony/tyx-feature/exception-h…
Browse files Browse the repository at this point in the history
…andler-to-service

Tyx feature/exception handler to service
  • Loading branch information
lsmith77 committed Jan 19, 2015
2 parents 71f2ed7 + fd6ca90 commit 07af90e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Controller/ExceptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions Resources/config/view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parameter key="fos_rest.serializer.exclusion_strategy.version" />
<parameter key="fos_rest.serializer.exclusion_strategy.groups"/>
<parameter key="fos_rest.view_handler.jsonp.callback_param"/>
<parameter key="fos_rest.view.exception_wrapper_handler" />
<parameter key="fos_rest.view.exception_wrapper_handler">FOS\RestBundle\View\ExceptionWrapperHandler</parameter>
<parameter key="fos_rest.view_handler.default.class">FOS\RestBundle\View\ViewHandler</parameter>
<parameter key="fos_rest.view_handler.jsonp.class">FOS\RestBundle\View\JsonpHandler</parameter>
<parameter key="fos_rest.serializer.exception_wrapper_serialize_handler.class">FOS\RestBundle\Serializer\ExceptionWrapperSerializeHandler</parameter>
Expand Down Expand Up @@ -41,7 +41,7 @@
<argument>%fos_rest.view_handler.jsonp.callback_param%</argument>
</service>

<service id="fos_rest.view.exception_wrapper_handler" class="%fos_rest.view.exception_wrapper_handler%" />
<service id="fos_rest.view.exception_wrapper_handler" class="%fos_rest.view.exception_wrapper_handler%"/>

<service id="fos_rest.serializer.exception_wrapper_serialize_handler" class="%fos_rest.serializer.exception_wrapper_serialize_handler.class%">
<tag name="jms_serializer.subscribing_handler" />
Expand Down
35 changes: 20 additions & 15 deletions Resources/doc/configuration-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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<version>[0-9\.]+)/'
1 change: 1 addition & 0 deletions Tests/DependencyInjection/FOSRestExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions Tests/View/ViewHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -309,15 +309,15 @@ 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(
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();
}
}
Expand Down
2 changes: 1 addition & 1 deletion View/ViewHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 07af90e

Please sign in to comment.