Skip to content

Commit

Permalink
set ConnectionFactoryDecorator parent class to ConnectionFactory for …
Browse files Browse the repository at this point in the history
…compatibility

fix json model type override on multiple calls
  • Loading branch information
pfilsx committed Feb 27, 2023
1 parent 9c566ca commit c16e00c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ public function process(ContainerBuilder $container): void
}

if (count($types) === 0) {
$container->removeDefinition('pfilsx.postgresql_doctrine_bundle.connection_wrapper');
$container->removeDefinition('pfilsx.postgresql_doctrine_bundle.connection_decorator');

return;
}

$connectionWrapperDef = $container->getDefinition('pfilsx.postgresql_doctrine_bundle.connection_wrapper');
$connectionWrapperDef = $container->getDefinition('pfilsx.postgresql_doctrine_bundle.connection_decorator');
$connectionWrapperDef
->setDecoratedService('doctrine.dbal.connection_factory')
->setArgument(1, $types)
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Symfony\Component\Serializer\Debug\TraceableNormalizer;
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;

class JsonModelConnectionFactoryWrapper
class JsonModelConnectionFactoryDecorator extends ConnectionFactory
{
private ConnectionFactory $innerFactory;
private array $typesMap;
Expand Down Expand Up @@ -42,7 +42,7 @@ private function initializeTypes(): void
JsonModelTypeRegistry::setObjectNormalizer($this->objectNormalizer);
}
foreach ($this->typesMap as $name => $className) {
JsonModelTypeRegistry::addType($name, $className);
JsonModelTypeRegistry::addType($name, $className, true);
}

JsonModelTypeRegistry::registerTypes();
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<tag name="doctrine.middleware"/>
</service>

<service id="pfilsx.postgresql_doctrine_bundle.connection_wrapper" class="Pfilsx\PostgreSQLDoctrineBundle\JsonModelConnectionFactoryWrapper">
<service id="pfilsx.postgresql_doctrine_bundle.connection_decorator" decorates="doctrine.dbal.connection_factory" class="Pfilsx\PostgreSQLDoctrineBundle\JsonModelConnectionFactoryDecorator">
<argument type="service" id=".inner"/>
<argument/>
<argument type="service" id="serializer.normalizer.object" on-invalid="null"/>
Expand Down

0 comments on commit c16e00c

Please sign in to comment.