-
Notifications
You must be signed in to change notification settings - Fork 699
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use symfony decoration for jms serializer handler registry
- Loading branch information
Showing
5 changed files
with
58 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
DependencyInjection/Compiler/JMSHandlerRegistryV4DecorationPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSRestBundle package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\RestBundle\DependencyInjection\Compiler; | ||
|
||
use FOS\RestBundle\Serializer\JMSHandlerRegistryV2; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* Decorates the handler registry from JMSSerializerBundle. | ||
* | ||
* It works as HandlerRegistryDecorationPass but uses the symfony built-in decoration mechanism. | ||
* This way of decoration is possible only starting from jms/serializer-bundle:4.0 . | ||
* | ||
* @author Asmir Mustafic <[email protected]> | ||
* | ||
* @internal | ||
*/ | ||
class JMSHandlerRegistryV4DecorationPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
// skip if jms/serializer-bundle is not installed or < 4.0 | ||
if (!$container->has('jms_serializer.handler_registry') || !$container->has('jms_serializer.handler_registry.service_locator')) { | ||
return; | ||
} | ||
|
||
$fosRestHandlerRegistry = new Definition( | ||
JMSHandlerRegistryV2::class, | ||
[ | ||
new Reference('fos_rest.serializer.jms_handler_registry.inner'), | ||
] | ||
); | ||
|
||
$fosRestHandlerRegistry->setDecoratedService('jms_serializer.handler_registry'); | ||
$container->setDefinition('fos_rest.serializer.jms_handler_registry', $fosRestHandlerRegistry); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters