Skip to content

[FrameworkBundle] Register the DataUriNormalizer #17631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Serializer\Normalizer\DataUriNormalizer;
use Symfony\Component\Validator\Validation;

/**
Expand Down Expand Up @@ -894,6 +895,13 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
return;
}

if (class_exists('Symfony\Component\Serializer\Normalizer\DataUriNormalizer')) {
// Run after serializer.normalizer.object
$definition = $container->register('serializer.normalizer.data_uri', DataUriNormalizer::class);
$definition->setPublic(false);
$definition->addTag('serializer.normalizer', ['priority' => -920]);
}

$loader->load('serializer.xml');
$chainLoader = $container->getDefinition('serializer.mapping.chain_loader');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Serializer\Normalizer\DataUriNormalizer;

abstract class FrameworkExtensionTest extends TestCase
{
Expand Down Expand Up @@ -453,6 +454,21 @@ public function testRegisterSerializerExtractor()
$this->assertEquals(array('priority' => -999), $tag[0]);
}

public function testDataUriNormalizerRegistered()
{
if (!class_exists('Symfony\Component\Serializer\Normalizer\DataUriNormalizer')) {
$this->markTestSkipped('The DataUriNormalizer has been introduced in the Serializer Component version 3.1.');
}

$container = $this->createContainerFromFile('full');

$definition = $container->getDefinition('serializer.normalizer.data_uri');
$tag = $definition->getTag('serializer.normalizer');

$this->assertEquals(DataUriNormalizer::class, $definition->getClass());
$this->assertEquals(-920, $tag[0]['priority']);
}

public function testAssetHelperWhenAssetsAreEnabled()
{
$container = $this->createContainerFromFile('full');
Expand Down