Skip to content

Commit d4f00b9

Browse files
committed
feature #21293 [FrameworkBundle][Serializer] Move SerializerPass to the Serializer (chalasr)
This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle][Serializer] Move SerializerPass to the Serializer | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Part of #21284 Commits ------- 95cf5084c0 [FrameworkBundle][Serializer] Move SerializerPass to the Serializer
2 parents 4df2924 + 126dd2c commit d4f00b9

File tree

5 files changed

+16
-32
lines changed

5 files changed

+16
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ CHANGELOG
1313
* Added `GlobalVariables::getToken()`
1414
* Deprecated `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass`. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
1515
* Added configurable paths for validation files
16+
* Deprecated `SerializerPass`, use `Symfony\Component\Serializer\DependencyInjection\SerializerPass` instead.
1617

1718
3.2.0
1819
-----

DependencyInjection/Compiler/SerializerPass.php

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,18 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14-
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
15-
use Symfony\Component\DependencyInjection\ContainerBuilder;
16-
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17-
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
14+
@trigger_error(sprintf('The %s class is deprecated since version 3.3 and will be removed in 4.0. Use Symfony\Component\Serializer\DependencyInjection\SerializerPass instead.', SerializerPass::class), E_USER_DEPRECATED);
15+
16+
use Symfony\Component\Serializer\DependencyInjection\SerializerPass as BaseSerializerPass;
1817

1918
/**
2019
* Adds all services with the tags "serializer.encoder" and "serializer.normalizer" as
2120
* encoders and normalizers to the Serializer service.
2221
*
22+
* @deprecated since version 3.3, to be removed in 4.0. Use {@link BaseSerializerPass} instead.
23+
*
2324
* @author Javier Lopez <f12loalf@gmail.com>
2425
*/
25-
class SerializerPass implements CompilerPassInterface
26+
class SerializerPass extends BaseSerializerPass
2627
{
27-
use PriorityTaggedServiceTrait;
28-
29-
public function process(ContainerBuilder $container)
30-
{
31-
if (!$container->hasDefinition('serializer')) {
32-
return;
33-
}
34-
35-
// Looks for all the services tagged "serializer.normalizer" and adds them to the Serializer service
36-
$normalizers = $this->findAndSortTaggedServices('serializer.normalizer', $container);
37-
38-
if (empty($normalizers)) {
39-
throw new RuntimeException('You must tag at least one service as "serializer.normalizer" to use the Serializer service');
40-
}
41-
$container->getDefinition('serializer')->replaceArgument(0, $normalizers);
42-
43-
// Looks for all the services tagged "serializer.encoders" and adds them to the Serializer service
44-
$encoders = $this->findAndSortTaggedServices('serializer.encoder', $container);
45-
if (empty($encoders)) {
46-
throw new RuntimeException('You must tag at least one service as "serializer.encoder" to use the Serializer service');
47-
}
48-
$container->getDefinition('serializer')->replaceArgument(1, $encoders);
49-
}
5028
}

FrameworkBundle.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CompilerDebugDumpPass;
3434
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationExtractorPass;
3535
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationDumperPass;
36-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass;
3736
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
3837
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass;
3938
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ValidateWorkflowsPass;
4039
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
40+
use Symfony\Component\Serializer\DependencyInjection\SerializerPass;
4141
use Symfony\Component\Debug\ErrorHandler;
4242
use Symfony\Component\DependencyInjection\ContainerBuilder;
4343
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
@@ -95,7 +95,9 @@ public function build(ContainerBuilder $container)
9595
$container->addCompilerPass(new TranslationExtractorPass());
9696
$container->addCompilerPass(new TranslationDumperPass());
9797
$container->addCompilerPass(new FragmentRendererPass(), PassConfig::TYPE_AFTER_REMOVING);
98-
$container->addCompilerPass(new SerializerPass());
98+
if (class_exists(SerializerPass::class)) {
99+
$container->addCompilerPass(new SerializerPass());
100+
}
99101
$container->addCompilerPass(new PropertyInfoPass());
100102
$container->addCompilerPass(new ControllerArgumentValueResolverPass());
101103
$container->addCompilerPass(new CachePoolPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 32);

Tests/DependencyInjection/Compiler/SerializerPassTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
/**
1818
* Tests for the SerializerPass class.
1919
*
20+
* @group legacy
21+
*
2022
* @author Javier Lopez <f12loalf@gmail.com>
2123
*/
2224
class SerializerPassTest extends \PHPUnit_Framework_TestCase

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"symfony/process": "~2.8|~3.0",
4747
"symfony/security-core": "~3.2",
4848
"symfony/security-csrf": "~2.8|~3.0",
49-
"symfony/serializer": "~2.8|~3.0",
49+
"symfony/serializer": "~3.3",
5050
"symfony/translation": "~2.8|~3.0",
5151
"symfony/templating": "~2.8|~3.0",
5252
"symfony/validator": "~3.2",
@@ -60,7 +60,8 @@
6060
"conflict": {
6161
"phpdocumentor/reflection-docblock": "<3.0",
6262
"phpdocumentor/type-resolver": "<0.2.0",
63-
"symfony/console": "<3.3"
63+
"symfony/console": "<3.3",
64+
"symfony/serializer": "<3.3"
6465
},
6566
"suggest": {
6667
"ext-apcu": "For best performance of the system caches",

0 commit comments

Comments
 (0)