Skip to content

Commit 1b28015

Browse files
committed
feature symfony#21494 [DI] Deprecate autowiring-types in favor of aliases (nicolas-grekas)
This PR was merged into the 3.3-dev branch. Discussion ---------- [DI] Deprecate autowiring-types in favor of aliases | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | symfony#21351, symfony#19970, ~~symfony#18040~~, ~~symfony#17783~~ | License | MIT | Doc PR | symfony/symfony-docs#7445 https://github.com/symfony/symfony/pull/21494/files?w=1 This PR deprecates autowiring-types and replaces them by plain aliases. ping @dunglas @weaverryan Eg instead of ```xml <service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader" public="false"> <autowiring-type>Doctrine\Common\Annotations\Reader</autowiring-type> </service> ``` just do: ```xml <service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader" public="false" /> <service id="Doctrine\Common\Annotations\Reader" alias="annotations.reader" public="false" /> ``` Commits ------- b11d391 [DI] Deprecate autowiring-types in favor of aliases
2 parents 29db096 + b11d391 commit 1b28015

Some content is hidden

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

44 files changed

+230
-176
lines changed

UPGRADE-3.3.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ Debug
1414
DependencyInjection
1515
-------------------
1616

17+
* Autowiring-types have been deprecated, use aliases instead.
18+
19+
Before:
20+
21+
```xml
22+
<service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader" public="false">
23+
<autowiring-type>Doctrine\Common\Annotations\Reader</autowiring-type>
24+
</service>
25+
```
26+
27+
After:
28+
29+
```xml
30+
<service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader" public="false" />
31+
<service id="Doctrine\Common\Annotations\Reader" alias="annotations.reader" public="false" />
32+
```
33+
1734
* The `Reference` and `Alias` classes do not make service identifiers lowercase anymore.
1835

1936
* Case insensitivity of service identifiers is deprecated and will be removed in 4.0.

UPGRADE-4.0.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ Debug
2424
DependencyInjection
2525
-------------------
2626

27+
* Autowiring-types have been removed, use aliases instead.
28+
29+
Before:
30+
31+
```xml
32+
<service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader" public="false">
33+
<autowiring-type>Doctrine\Common\Annotations\Reader</autowiring-type>
34+
</service>
35+
```
36+
37+
After:
38+
39+
```xml
40+
<service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader" public="false" />
41+
<service id="Doctrine\Common\Annotations\Reader" alias="annotations.reader" public="false" />
42+
```
43+
2744
* Service identifiers are now case sensitive.
2845

2946
* The `Reference` and `Alias` classes do not make service identifiers lowercase anymore.

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,9 @@ private function getContainerDefinitionData(Definition $definition, $omitTags =
220220
'shared' => $definition->isShared(),
221221
'abstract' => $definition->isAbstract(),
222222
'autowire' => $definition->isAutowired(),
223-
'autowiring_types' => array(),
224223
);
225224

226-
foreach ($definition->getAutowiringTypes() as $autowiringType) {
225+
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
227226
$data['autowiring_types'][] = $autowiringType;
228227
}
229228

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ protected function describeContainerDefinition(Definition $definition, array $op
185185
."\n".'- Autowired: '.($definition->isAutowired() ? 'yes' : 'no')
186186
;
187187

188-
foreach ($definition->getAutowiringTypes() as $autowiringType) {
189-
$output .= "\n" . '- Autowiring Type: `' . $autowiringType . '`';
188+
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
189+
$output .= "\n".'- Autowiring Type: `'.$autowiringType.'`';
190190
}
191191

192192
if (isset($options['show_arguments']) && $options['show_arguments']) {

src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,9 @@ protected function describeContainerDefinition(Definition $definition, array $op
294294
$tableRows[] = array('Abstract', $definition->isAbstract() ? 'yes' : 'no');
295295
$tableRows[] = array('Autowired', $definition->isAutowired() ? 'yes' : 'no');
296296

297-
$autowiringTypes = $definition->getAutowiringTypes();
298-
$tableRows[] = array('Autowiring Types', $autowiringTypes ? implode(', ', $autowiringTypes) : '-');
297+
if ($autowiringTypes = $definition->getAutowiringTypes(false)) {
298+
$tableRows[] = array('Autowiring Types', implode(', ', $autowiringTypes));
299+
}
299300

300301
if ($definition->getFile()) {
301302
$tableRows[] = array('Required File', $definition->getFile() ? $definition->getFile() : '-');

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TemplatingPass.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

1414
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as FrameworkBundleEngineInterface;
15+
use Symfony\Component\DependencyInjection\Alias;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1718
use Symfony\Component\Templating\EngineInterface as ComponentEngineInterface;
@@ -25,8 +26,8 @@ public function process(ContainerBuilder $container)
2526
}
2627

2728
if ($container->hasAlias('templating')) {
28-
$definition = $container->findDefinition('templating');
29-
$definition->setAutowiringTypes(array(ComponentEngineInterface::class, FrameworkBundleEngineInterface::class));
29+
$container->setAlias(ComponentEngineInterface::class, new Alias('templating', false));
30+
$container->setAlias(FrameworkBundleEngineInterface::class, new Alias('templating', false));
3031
}
3132

3233
if ($container->hasDefinition('templating.engine.php')) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,8 +1096,8 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
10961096
->getDefinition('annotations.cached_reader')
10971097
->replaceArgument(1, new Reference($cacheService))
10981098
->replaceArgument(2, $config['debug'])
1099-
->addAutowiringType(Reader::class)
11001099
;
1100+
$container->setAlias(Reader::class, new Alias('annotations.cached_reader', false));
11011101
} else {
11021102
$container->removeDefinition('annotations.cached_reader');
11031103
}

src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<services>
8-
<service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader" public="false">
9-
<autowiring-type>Doctrine\Common\Annotations\Reader</autowiring-type>
10-
</service>
8+
<service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader" public="false" />
9+
<service id="Doctrine\Common\Annotations\Reader" alias="annotations.reader" public="false" />
1110

1211
<service id="annotations.cached_reader" class="Doctrine\Common\Annotations\CachedReader" public="false">
1312
<argument type="service" id="annotations.reader" />

src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<services>
88
<service id="event_dispatcher" class="Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher">
99
<argument type="service" id="service_container" />
10-
<autowiring-type>Symfony\Component\EventDispatcher\EventDispatcherInterface</autowiring-type>
11-
<autowiring-type>Symfony\Component\EventDispatcher\EventDispatcher</autowiring-type>
1210
</service>
11+
<service id="Symfony\Component\EventDispatcher\EventDispatcherInterface" alias="event_dispatcher" public="false" />
12+
<service id="Symfony\Component\EventDispatcher\EventDispatcher" alias="event_dispatcher" public="false" />
1313

1414
<service id="http_kernel" class="Symfony\Component\HttpKernel\HttpKernel">
1515
<argument type="service" id="event_dispatcher" />
@@ -40,10 +40,8 @@
4040
<argument type="collection" />
4141
</service>
4242

43-
<service id="service_container" synthetic="true">
44-
<autowiring-type>Symfony\Component\DependencyInjection\ContainerInterface</autowiring-type>
45-
<autowiring-type>Symfony\Component\DependencyInjection\Container</autowiring-type>
46-
</service>
43+
<service id="Symfony\Component\DependencyInjection\ContainerInterface" alias="service_container" public="false" />
44+
<service id="Symfony\Component\DependencyInjection\Container" alias="service_container" public="false" />
4745

4846
<service id="kernel" synthetic="true" />
4947

src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
<call method="setConfigCacheFactory">
1818
<argument type="service" id="config_cache_factory" />
1919
</call>
20-
21-
<autowiring-type>Symfony\Component\Translation\TranslatorInterface</autowiring-type>
2220
</service>
21+
<service id="Symfony\Component\Translation\TranslatorInterface" alias="translator" public="false" />
2322

2423
<service id="translator.logging" class="Symfony\Component\Translation\LoggingTranslator" public="false">
2524
<argument type="service" id="translator.logging.inner" />

0 commit comments

Comments
 (0)