Skip to content

Commit

Permalink
Allow to use Symfony's serializer even with JMS Serializer enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
sroze committed Jun 23, 2015
1 parent 9fe38af commit a99e50b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions DependencyInjection/Compiler/SerializerConfigurationPass.php
Expand Up @@ -28,14 +28,20 @@ public function process(ContainerBuilder $container)
return;
}

if (!$container->has('serializer') && !$container->has('jms_serializer.serializer')) {
throw new \InvalidArgumentException('Neither a service called "jms_serializer.serializer" nor "serializer" is available and no serializer is explicitly configured. You must either enable the JMSSerializerBundle, enable the FrameworkBundle serializer or configure a custom serializer.');
}

if ($container->has('jms_serializer.serializer')) {
$container->setAlias('fos_rest.serializer', 'jms_serializer.serializer');
$container->removeDefinition('fos_rest.serializer.exception_wrapper_normalizer');
} elseif ($container->has('serializer')) {
$container->setAlias('fos_rest.serializer', 'serializer');
} else {
$container->removeDefinition('fos_rest.serializer.exception_wrapper_serialize_handler');
}

if ($container->has('serializer')) {
$container->setAlias('fos_rest.serializer', 'serializer');
} else {
throw new \InvalidArgumentException('Neither a service called "jms_serializer.serializer" nor "serializer" is available and no serializer is explicitly configured. You must either enable the JMSSerializerBundle, enable the FrameworkBundle serializer or configure a custom serializer.');
$container->removeDefinition('fos_rest.serializer.exception_wrapper_normalizer');
}
}
}
Expand Up @@ -70,7 +70,7 @@ public function testShouldConfigureJMSSerializer()

$container->expects($this->once())
->method('setAlias')
->with($this->equalTo('fos_rest.serializer'), $this->equalTo('jms_serializer.serializer'));
->with($this->equalTo('fos_rest.serializer'), $this->equalTo('serializer'));

$container->expects($this->once())
->method('removeDefinition')
Expand Down

0 comments on commit a99e50b

Please sign in to comment.