File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed
DependencyInjection/Compiler Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1515use Symfony \Component \HttpKernel \Bundle \Bundle ;
1616use FOS \RestBundle \DependencyInjection \Compiler \SerializerConfigurationPass ;
1717use FOS \RestBundle \DependencyInjection \Compiler \ConfigurationCheckPass ;
18+ use FOS \RestBundle \DependencyInjection \Compiler \ExceptionWrapperHandlerPass ;
1819use FOS \RestBundle \DependencyInjection \Compiler \FormatListenerRulesPass ;
1920use 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}
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments