From 87868baacbd7f17197d3948d0482c0c9478ca845 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Mon, 4 May 2020 19:01:18 +0200 Subject: [PATCH] [FrameworkBundle] Deprecate some public services to private --- UPGRADE-5.2.md | 6 ++++++ UPGRADE-6.0.md | 2 ++ src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md | 2 ++ .../Bundle/FrameworkBundle/Resources/config/form.php | 2 ++ .../Resources/config/identity_translator.php | 1 + .../Resources/config/security_csrf.php | 1 + .../FrameworkBundle/Resources/config/serializer.php | 1 + .../FrameworkBundle/Resources/config/services.php | 2 ++ .../FrameworkBundle/Resources/config/validator.php | 1 + .../Fixtures/php/validation_annotations.php | 2 ++ .../Fixtures/xml/validation_annotations.xml | 4 ++++ .../Fixtures/yml/validation_annotations.yml | 5 +++++ .../DependencyInjection/FrameworkExtensionTest.php | 2 +- .../Tests/Functional/BundlePathsTest.php | 6 +++--- .../Tests/Functional/CachePoolsTest.php | 2 +- .../Tests/Functional/SerializerTest.php | 2 +- .../Tests/Functional/app/BundlePaths/config.yml | 11 +++++++++++ .../Tests/Functional/app/CachePools/config.yml | 5 +++++ .../Tests/Functional/app/Serializer/config.yml | 5 +++++ 19 files changed, 56 insertions(+), 6 deletions(-) diff --git a/UPGRADE-5.2.md b/UPGRADE-5.2.md index 0eaced68a90ef..d4465cff923d7 100644 --- a/UPGRADE-5.2.md +++ b/UPGRADE-5.2.md @@ -6,6 +6,12 @@ DependencyInjection * Deprecated `Definition::setPrivate()` and `Alias::setPrivate()`, use `setPublic()` instead +FrameworkBundle +--------------- + + * Deprecated the public `form.factory`, `form.type.file`, `translator`, `security.csrf.token_manager`, `serializer`, + `cache_clearer`, `filesystem` and `validator` services to private. + Mime ---- diff --git a/UPGRADE-6.0.md b/UPGRADE-6.0.md index e2694dd9b4a97..195d644fd5f9a 100644 --- a/UPGRADE-6.0.md +++ b/UPGRADE-6.0.md @@ -55,6 +55,8 @@ FrameworkBundle * `MicroKernelTrait::configureRoutes()` is now always called with a `RoutingConfigurator` * The "framework.router.utf8" configuration option defaults to `true` * Removed `session.attribute_bag` service and `session.flash_bag` service. + * The `form.factory`, `form.type.file`, `translator`, `security.csrf.token_manager`, `serializer`, + `cache_clearer`, `filesystem` and `validator` services are now private. HttpFoundation -------------- diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 214209bedc9ac..d1511a991218d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -6,6 +6,8 @@ CHANGELOG * Added `framework.http_cache` configuration tree * Added `framework.trusted_proxies` and `framework.trusted_headers` configuration options + * Deprecated the public `form.factory`, `form.type.file`, `translator`, `security.csrf.token_manager`, `serializer`, + `cache_clearer`, `filesystem` and `validator` services to private. 5.1.0 ----- diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.php index e3ac863490e30..50bd1e30672bb 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/form.php @@ -61,6 +61,7 @@ ->set('form.factory', FormFactory::class) ->public() ->args([service('form.registry')]) + ->tag('container.private', ['package' => 'symfony/framework-bundle', 'version' => '5.2']) ->alias(FormFactoryInterface::class, 'form.factory') @@ -103,6 +104,7 @@ ->public() ->args([service('translator')->ignoreOnInvalid()]) ->tag('form.type') + ->tag('container.private', ['package' => 'symfony/framework-bundle', 'version' => '5.2']) ->set('form.type.color', ColorType::class) ->args([service('translator')->ignoreOnInvalid()]) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/identity_translator.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/identity_translator.php index 7ef293d24a339..a9066e1f00e80 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/identity_translator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/identity_translator.php @@ -18,6 +18,7 @@ $container->services() ->set('translator', IdentityTranslator::class) ->public() + ->tag('container.private', ['package' => 'symfony/framework-bundle', 'version' => '5.2']) ->alias(TranslatorInterface::class, 'translator') ->set('identity_translator', IdentityTranslator::class) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/security_csrf.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/security_csrf.php index 0350333ac167b..0afc740cd89bf 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/security_csrf.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/security_csrf.php @@ -38,6 +38,7 @@ service('security.csrf.token_storage'), service('request_stack')->ignoreOnInvalid(), ]) + ->tag('container.private', ['package' => 'symfony/framework-bundle', 'version' => '5.2']) ->alias(CsrfTokenManagerInterface::class, 'security.csrf.token_manager') diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.php index 272fadcfefe17..fbeb348b6e550 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/serializer.php @@ -55,6 +55,7 @@ ->set('serializer', Serializer::class) ->public() ->args([[], []]) + ->tag('container.private', ['package' => 'symfony/framework-bundle', 'version' => '5.2']) ->alias(SerializerInterface::class, 'serializer') ->alias(NormalizerInterface::class, 'serializer') diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.php index a5ffe1c072400..4df97ed19c531 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/services.php @@ -118,6 +118,7 @@ class_exists(WorkflowEvents::class) ? WorkflowEvents::ALIASES : [] ->args([ tagged_iterator('kernel.cache_clearer'), ]) + ->tag('container.private', ['package' => 'symfony/framework-bundle', 'version' => '5.2']) ->set('kernel') ->synthetic() @@ -126,6 +127,7 @@ class_exists(WorkflowEvents::class) ? WorkflowEvents::ALIASES : [] ->set('filesystem', Filesystem::class) ->public() + ->tag('container.private', ['package' => 'symfony/framework-bundle', 'version' => '5.2']) ->alias(Filesystem::class, 'filesystem') ->set('file_locator', FileLocator::class) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.php index 449ae9bc7a754..5dcb427b565bc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/validator.php @@ -30,6 +30,7 @@ ->set('validator', ValidatorInterface::class) ->public() ->factory([service('validator.builder'), 'getValidator']) + ->tag('container.private', ['package' => 'symfony/framework-bundle', 'version' => '5.2']) ->alias(ValidatorInterface::class, 'validator') ->set('validator.builder', ValidatorBuilder::class) diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_annotations.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_annotations.php index dff03e398e2dc..933410dfee767 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_annotations.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/validation_annotations.php @@ -7,3 +7,5 @@ 'enable_annotations' => true, ], ]); + +$container->setAlias('validator.alias', 'validator')->setPublic(true); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_annotations.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_annotations.xml index f993a20d97314..2324b9ca6e374 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_annotations.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/validation_annotations.xml @@ -9,4 +9,8 @@ + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_annotations.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_annotations.yml index 41f17969b83ca..97b433f8cfb08 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_annotations.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/validation_annotations.yml @@ -3,3 +3,8 @@ framework: validation: enabled: true enable_annotations: true + +services: + validator.alias: + alias: validator + public: true diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 5480ec7ecf133..291808e1ee2e0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -839,7 +839,7 @@ public function testValidationService() { $container = $this->createContainerFromFile('validation_annotations', ['kernel.charset' => 'UTF-8'], false); - $this->assertInstanceOf('Symfony\Component\Validator\Validator\ValidatorInterface', $container->get('validator')); + $this->assertInstanceOf('Symfony\Component\Validator\Validator\ValidatorInterface', $container->get('validator.alias')); } public function testAnnotations() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/BundlePathsTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/BundlePathsTest.php index 22956fa0fcb11..65f2361451619 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/BundlePathsTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/BundlePathsTest.php @@ -53,7 +53,7 @@ public function testBundleTwigTemplatesDir() public function testBundleTranslationsDir() { static::bootKernel(['test_case' => 'BundlePaths']); - $translator = static::$container->get('translator'); + $translator = static::$container->get('translator.alias'); $this->assertSame('OK', $translator->trans('ok_label', [], 'legacy')); $this->assertSame('OK', $translator->trans('ok_label', [], 'modern')); @@ -62,7 +62,7 @@ public function testBundleTranslationsDir() public function testBundleValidationConfigDir() { static::bootKernel(['test_case' => 'BundlePaths']); - $validator = static::$container->get('validator'); + $validator = static::$container->get('validator.alias'); $this->assertTrue($validator->hasMetadataFor(LegacyPerson::class)); $this->assertCount(1, $constraintViolationList = $validator->validate(new LegacyPerson('john', 5))); @@ -76,7 +76,7 @@ public function testBundleValidationConfigDir() public function testBundleSerializationConfigDir() { static::bootKernel(['test_case' => 'BundlePaths']); - $serializer = static::$container->get('serializer'); + $serializer = static::$container->get('serializer.alias'); $this->assertEquals(['full_name' => 'john', 'age' => 5], $serializer->normalize(new LegacyPerson('john', 5), 'json')); $this->assertEquals(['full_name' => 'john', 'age' => 5], $serializer->normalize(new ModernPerson('john', 5), 'json')); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php index e6f6bbb3158d8..8fa9374ab8d51 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolsTest.php @@ -96,7 +96,7 @@ private function doTestCachePools($options, $adapterClass) $pool2 = $container->get('cache.pool2'); $pool2->save($item); - $container->get('cache_clearer')->clear($container->getParameter('kernel.cache_dir')); + $container->get('cache_clearer.alias')->clear($container->getParameter('kernel.cache_dir')); $item = $pool1->getItem($key); $this->assertFalse($item->isHit()); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SerializerTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SerializerTest.php index b0d774bdd55e8..bbb66e53845aa 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SerializerTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/SerializerTest.php @@ -20,7 +20,7 @@ public function testDeserializeArrayOfObject() { static::bootKernel(['test_case' => 'Serializer']); - $result = static::$container->get('serializer')->deserialize('{"bars": [{"id": 1}, {"id": 2}]}', Foo::class, 'json'); + $result = static::$container->get('serializer.alias')->deserialize('{"bars": [{"id": 1}, {"id": 2}]}', Foo::class, 'json'); $bar1 = new Bar(); $bar1->id = 1; diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/BundlePaths/config.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/BundlePaths/config.yml index 9108caf29fd88..82a5a5422ab7d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/BundlePaths/config.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/BundlePaths/config.yml @@ -12,4 +12,15 @@ twig: services: twig.alias: alias: twig + + validator.alias: + alias: validator + public: true + + serializer.alias: + alias: serializer + public: true + + translator.alias: + alias: translator public: true diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CachePools/config.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CachePools/config.yml index 8c7bcb4eb1fac..d299f2d9546b0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CachePools/config.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/CachePools/config.yml @@ -24,3 +24,8 @@ framework: cache.pool7: adapter: cache.pool4 public: true + +services: + cache_clearer.alias: + alias: cache_clearer + public: true diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/config.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/config.yml index cac135c315d00..7878c2ecb68d4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/config.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/config.yml @@ -4,3 +4,8 @@ imports: framework: serializer: { enabled: true } property_info: { enabled: true } + +services: + serializer.alias: + alias: serializer + public: true