Skip to content

Commit bc6fdd8

Browse files
xabbuhlsmith77
authored andcommitted
remove unusable handler when JMS serializer is not present
1 parent d72f3a4 commit bc6fdd8

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSRestBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace FOS\RestBundle\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
15+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16+
17+
/**
18+
* Checks if the JMS serializer is available to be able to use the ExceptionWrapperSerializeHandler.
19+
*
20+
* @author Christian Flothmann <[email protected]>
21+
*/
22+
class ExceptionWrapperHandlerPass implements CompilerPassInterface
23+
{
24+
public function process(ContainerBuilder $container)
25+
{
26+
if (!$container->has('fos_rest.serializer.exception_wrapper_serialize_handler')) {
27+
return;
28+
}
29+
30+
if (interface_exists('JMS\Serializer\Handler\SubscribingHandlerInterface')) {
31+
return;
32+
}
33+
34+
$container->removeDefinition('fos_rest.serializer.exception_wrapper_serialize_handler');
35+
}
36+
}

FOSRestBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\HttpKernel\Bundle\Bundle;
1616
use FOS\RestBundle\DependencyInjection\Compiler\SerializerConfigurationPass;
1717
use FOS\RestBundle\DependencyInjection\Compiler\ConfigurationCheckPass;
18+
use FOS\RestBundle\DependencyInjection\Compiler\ExceptionWrapperHandlerPass;
1819
use FOS\RestBundle\DependencyInjection\Compiler\FormatListenerRulesPass;
1920
use FOS\RestBundle\DependencyInjection\Compiler\TwigExceptionPass;
2021

@@ -33,5 +34,6 @@ public function build(ContainerBuilder $container)
3334
$container->addCompilerPass(new ConfigurationCheckPass());
3435
$container->addCompilerPass(new FormatListenerRulesPass());
3536
$container->addCompilerPass(new TwigExceptionPass());
37+
$container->addCompilerPass(new ExceptionWrapperHandlerPass());
3638
}
3739
}

Tests/FOSRestBundleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function testBuild()
2525
$container = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerBuilder')
2626
->setMethods(array('addCompilerPass'))
2727
->getMock();
28-
$container->expects($this->exactly(4))
28+
$container->expects($this->exactly(5))
2929
->method('addCompilerPass')
3030
->with($this->isInstanceOf('\Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface'));
3131

0 commit comments

Comments
 (0)