-
-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #906 from schmittjoh/instances3
Allow multiple serializer instances
- Loading branch information
Showing
34 changed files
with
965 additions
and
259 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
*~ | ||
composer.lock | ||
/vendor/ | ||
/.phpcs-cache |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JMS\SerializerBundle\DependencyInjection\Compiler; | ||
|
||
use JMS\SerializerBundle\DependencyInjection\DIUtils; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* This step changes the service decoration targets to match the serializer instance | ||
* In this way when calling | ||
* | ||
* $container->getDefinition('xxx') | ||
* ->setDecoratedService('jms_serializer.object_constructor') | ||
* | ||
* You do not need to worry to which serializer instance jms_serializer.object_constructor refers to. | ||
* | ||
* @internal | ||
*/ | ||
final class AdjustDecorationPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
DIUtils::adjustDecorators($container); | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JMS\SerializerBundle\DependencyInjection\Compiler; | ||
|
||
use JMS\SerializerBundle\DependencyInjection\ScopedContainer; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class AssignVisitorsPass extends PerInstancePass | ||
{ | ||
protected function processInstance(ScopedContainer $container): void | ||
{ | ||
$def = $container->getDefinition('jms_serializer.serializer'); | ||
$serializers = []; | ||
foreach ($container->findTaggedServiceIds('jms_serializer.serialization_visitor') as $id => $multipleTags) { | ||
foreach ($multipleTags as $attributes) { | ||
$serializers[$attributes['format']] = new Reference($id); | ||
} | ||
} | ||
|
||
$def->replaceArgument(2, $serializers); | ||
|
||
$deserializers = []; | ||
foreach ($container->findTaggedServiceIds('jms_serializer.deserialization_visitor') as $id => $multipleTags) { | ||
foreach ($multipleTags as $attributes) { | ||
$deserializers[$attributes['format']] = new Reference($id); | ||
} | ||
} | ||
|
||
$def->replaceArgument(3, $deserializers); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JMS\SerializerBundle\DependencyInjection\Compiler; | ||
|
||
use JMS\SerializerBundle\DependencyInjection\ScopedContainer; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
abstract class PerInstancePass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
foreach (self::getSerializers($container) as $scopedContainer) { | ||
$this->processInstance($scopedContainer); | ||
} | ||
} | ||
|
||
/** | ||
* @param ContainerBuilder $container | ||
* | ||
* @return ScopedContainer[] | ||
*/ | ||
private static function getSerializers(ContainerBuilder $container): array | ||
{ | ||
$serializers = []; | ||
|
||
foreach ($container->findTaggedServiceIds('jms_serializer.serializer') as $serializerId => $serializerAttributes) { | ||
foreach ($serializerAttributes as $serializerAttribute) { | ||
$serializers[$serializerId] = new ScopedContainer($container, $serializerAttribute['name']); | ||
} | ||
} | ||
|
||
return $serializers; | ||
} | ||
|
||
abstract protected function processInstance(ScopedContainer $container): void; | ||
} |
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
Oops, something went wrong.