Skip to content

Commit 9948b09

Browse files
[DI] Turn services and aliases private by default, with BC layer
1 parent c4159b1 commit 9948b09

File tree

78 files changed

+264
-121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+264
-121
lines changed

UPGRADE-3.4.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ UPGRADE FROM 3.3 to 3.4
44
DependencyInjection
55
-------------------
66

7+
* Definitions and aliases will be made private by default in 4.0. You should either use service injection
8+
or explicitly define your services as public if you really need to inject the container.
9+
710
* Relying on service auto-registration while autowiring is deprecated and won't be supported
811
in Symfony 4.0. Explicitly inject your dependencies or create services
912
whose ids are their fully-qualified class name.
@@ -154,7 +157,7 @@ FrameworkBundle
154157
* The `Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader`
155158
class has been deprecated and will be removed in 4.0. Use the
156159
`Symfony\Component\Translation\Reader\TranslationReader` class instead.
157-
160+
158161
* The `translation.loader` service has been deprecated and will be removed in 4.0.
159162
Use the `translation.reader` service instead..
160163

@@ -269,9 +272,9 @@ SecurityBundle
269272
Translation
270273
-----------
271274

272-
* `Symfony\Component\Translation\Writer\TranslationWriter::writeTranslations` has been deprecated
273-
and will be removed in 4.0, use `Symfony\Component\Translation\Writer\TranslationWriter::write`
274-
instead.
275+
* `Symfony\Component\Translation\Writer\TranslationWriter::writeTranslations` has been deprecated
276+
and will be removed in 4.0, use `Symfony\Component\Translation\Writer\TranslationWriter::write`
277+
instead.
275278

276279
* Passing a `Symfony\Component\Translation\MessageSelector` to `Translator` has been
277280
deprecated. You should pass a message formatter instead

UPGRADE-4.0.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ Debug
7777
DependencyInjection
7878
-------------------
7979

80+
* Definitions and aliases are now private by default in 4.0. You should either use service injection
81+
or explicitly define your services as public if you really need to inject the container.
82+
8083
* Relying on service auto-registration while autowiring is not supported anymore.
8184
Explicitly inject your dependencies or create services whose ids are
8285
their fully-qualified class name.
@@ -449,14 +452,14 @@ FrameworkBundle
449452
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass`
450453
class has been removed. Use the
451454
`Symfony\Component\Translation\DependencyInjection\TranslatorPass` class instead.
452-
455+
453456
* The `Symfony\Bundle\FrameworkBundle\Translation\TranslationLoader`
454457
class has been deprecated and will be removed in 4.0. Use the
455458
`Symfony\Component\Translation\Reader\TranslationReader` class instead.
456459

457460
* The `translation.loader` service has been removed.
458461
Use the `translation.reader` service instead.
459-
462+
460463
* `AssetsInstallCommand::__construct()` now requires an instance of
461464
`Symfony\Component\Filesystem\Filesystem` as first argument.
462465

@@ -673,11 +676,11 @@ Translation
673676
-----------
674677

675678
* Removed the backup feature from the file dumper classes.
676-
679+
677680
* The default value of the `$readerServiceId` argument of `TranslatorPass::__construct()` has been changed to `"translation.reader"`.
678-
679-
* Removed `Symfony\Component\Translation\Writer\TranslationWriter::writeTranslations`,
680-
use `Symfony\Component\Translation\Writer\TranslationWriter::write` instead.
681+
682+
* Removed `Symfony\Component\Translation\Writer\TranslationWriter::writeTranslations`,
683+
use `Symfony\Component\Translation\Writer\TranslationWriter::write` instead.
681684

682685
* Removed support for passing `Symfony\Component\Translation\MessageSelector` as a second argument to the
683686
`Translator::__construct()`. You should pass an instance of `Symfony\Component\Translation\Formatter\MessageFormatterInterface` instead.

src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/Dumper/PhpDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private function dumpLazyServiceProjectServiceContainer()
6161
{
6262
$container = new ContainerBuilder();
6363

64-
$container->register('foo', 'stdClass');
64+
$container->register('foo', 'stdClass')->setPublic(true);
6565
$container->getDefinition('foo')->setLazy(true);
6666
$container->compile();
6767

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,12 +1012,12 @@ private function registerTemplatingConfiguration(array $config, ContainerBuilder
10121012

10131013
// Use a delegation unless only a single engine was registered
10141014
if (1 === count($engines)) {
1015-
$container->setAlias('templating', (string) reset($engines));
1015+
$container->setAlias('templating', (string) reset($engines))->setPublic(true);
10161016
} else {
10171017
foreach ($engines as $engine) {
10181018
$container->getDefinition('templating.engine.delegating')->addMethodCall('addEngine', array($engine));
10191019
}
1020-
$container->setAlias('templating', 'templating.engine.delegating');
1020+
$container->setAlias('templating', 'templating.engine.delegating')->setPublic(true);
10211021
}
10221022

10231023
$container->getDefinition('fragment.renderer.hinclude')
@@ -1213,7 +1213,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
12131213
$container->getDefinition('translation.writer')->setPrivate(true);
12141214

12151215
// Use the "real" translator instead of the identity default
1216-
$container->setAlias('translator', 'translator.default');
1216+
$container->setAlias('translator', 'translator.default')->setPublic(true);
12171217
$container->setAlias('translator.formatter', new Alias($config['formatter'], false));
12181218
$translator = $container->findDefinition('translator.default');
12191219
$translator->addMethodCall('setFallbackLocales', array($config['fallbacks']));

src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernelTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
7272
if ($this instanceof EventSubscriberInterface) {
7373
$container->register('kernel', static::class)
7474
->setSynthetic(true)
75+
->setPublic(true)
7576
->addTag('kernel.event_subscriber')
7677
;
7778
}

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ imports:
22
- { resource: ../config/default.yml }
33

44
services:
5+
_defaults: { public: true }
56
test.autowiring_types.autowired_services:
67
class: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\AutowiringTypes\AutowiredServices
78
autowire: true

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/ContainerDebug/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ imports:
22
- { resource: ../config/default.yml }
33

44
services:
5+
_defaults: { public: true }
56
public:
67
class: Symfony\Bundle\FrameworkBundle\Tests\Fixtures\DeclaredClass
78
private_alias:

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/Serializer/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ imports:
22
- { resource: ../config/default.yml }
33

44
services:
5+
_defaults: { public: true }
56
test.property_info: '@property_info'
67

78
framework:

src/Symfony/Bundle/FrameworkBundle/Tests/Kernel/ConcreteMicroKernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
8282
));
8383

8484
$c->setParameter('halloween', 'Have a great day!');
85-
$c->register('halloween', 'stdClass');
85+
$c->register('halloween', 'stdClass')->setPublic(true);
8686
}
8787

8888
/**

src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private function configureDbalAclProvider(array $config, ContainerBuilder $conta
185185
$container->getAlias('security.acl.provider')->setPrivate(true);
186186

187187
if (null !== $config['connection']) {
188-
$container->setAlias('security.acl.dbal.connection', sprintf('doctrine.dbal.%s_connection', $config['connection']));
188+
$container->setAlias('security.acl.dbal.connection', sprintf('doctrine.dbal.%s_connection', $config['connection']))->setPrivate(true);
189189
}
190190

191191
$container

0 commit comments

Comments
 (0)