Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b28015

Browse files
committed
feature #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 | #21351, #19970, ~~#18040~~, ~~#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" />

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"shared": true,
1212
"abstract": true,
1313
"autowire": false,
14-
"autowiring_types": [],
1514
"file": null,
1615
"factory_class": "Full\\Qualified\\FactoryClass",
1716
"factory_method": "get",

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.txt

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
Information for Service "service_1"
44
===================================
55

6-
------------------ -----------------------------
7-
 Option   Value 
8-
------------------ -----------------------------
9-
Service ID service_1
10-
Class Full\Qualified\Class1
11-
Tags -
12-
Public yes
13-
Synthetic no
14-
Lazy yes
15-
Shared yes
16-
Abstract yes
17-
Autowired no
18-
Autowiring Types -
19-
Factory Class Full\Qualified\FactoryClass
20-
Factory Method get
21-
------------------ -----------------------------
6+
---------------- -----------------------------
7+
 Option   Value 
8+
---------------- -----------------------------
9+
Service ID service_1
10+
Class Full\Qualified\Class1
11+
Tags -
12+
Public yes
13+
Synthetic no
14+
Lazy yes
15+
Shared yes
16+
Abstract yes
17+
Autowired no
18+
Factory Class Full\Qualified\FactoryClass
19+
Factory Method get
20+
---------------- -----------------------------

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"shared": true,
1212
"abstract": false,
1313
"autowire": false,
14-
"autowiring_types": [],
1514
"file": "\/path\/to\/file",
1615
"factory_service": "factory.service",
1716
"factory_method": "get",

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.txt

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,22 @@
33
Information for Service "service_2"
44
===================================
55

6-
------------------ ---------------------------------
7-
 Option   Value 
8-
------------------ ---------------------------------
9-
Service ID service_2
10-
Class Full\Qualified\Class2
11-
Tags tag1 (attr1: val1, attr2: val2)
12-
tag1 (attr3: val3)
13-
tag2
14-
Calls setMailer
15-
Public no
16-
Synthetic yes
17-
Lazy no
18-
Shared yes
19-
Abstract no
20-
Autowired no
21-
Autowiring Types -
22-
Required File /path/to/file
23-
Factory Service factory.service
24-
Factory Method get
25-
------------------ ---------------------------------
6+
----------------- ---------------------------------
7+
 Option   Value 
8+
----------------- ---------------------------------
9+
Service ID service_2
10+
Class Full\Qualified\Class2
11+
Tags tag1 (attr1: val1, attr2: val2)
12+
tag1 (attr3: val3)
13+
tag2
14+
Calls setMailer
15+
Public no
16+
Synthetic yes
17+
Lazy no
18+
Shared yes
19+
Abstract no
20+
Autowired no
21+
Required File /path/to/file
22+
Factory Service factory.service
23+
Factory Method get
24+
----------------- ---------------------------------

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
],
1616
"autowire": false,
17-
"autowiring_types": [],
1817
"arguments": [
1918
{
2019
"type": "service",
@@ -29,7 +28,6 @@
2928
"shared": true,
3029
"abstract": false,
3130
"autowire": false,
32-
"autowiring_types": [],
3331
"arguments": [
3432
"arg1",
3533
"arg2"

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
"tags": [
1414

1515
],
16-
"autowire": false,
17-
"autowiring_types": []
16+
"autowire": false
1817
}
1918
},
2019
"aliases": {

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
"tags": [
1414

1515
],
16-
"autowire": false,
17-
"autowiring_types": []
16+
"autowire": false
1817
},
1918
"definition_2": {
2019
"class": "Full\\Qualified\\Class2",
@@ -50,8 +49,7 @@
5049
"calls": [
5150
"setMailer"
5251
],
53-
"autowire": false,
54-
"autowiring_types": []
52+
"autowire": false
5553
}
5654
},
5755
"aliases": {

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
"calls": [
3535
"setMailer"
3636
],
37-
"autowire": false,
38-
"autowiring_types": []
37+
"autowire": false
3938
}
4039
},
4140
"aliases": [

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
],
1414
"factory_service": "factory.service",
1515
"factory_method": "get",
16-
"autowire": false,
17-
"autowiring_types": []
16+
"autowire": false
1817
}
1918
],
2019
"tag2": [
@@ -31,8 +30,7 @@
3130
],
3231
"factory_service": "factory.service",
3332
"factory_method": "get",
34-
"autowire": false,
35-
"autowiring_types": []
33+
"autowire": false
3634
}
3735
]
3836
}

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@
1111
"tags": [
1212

1313
],
14-
"autowire": false,
15-
"autowiring_types": []
14+
"autowire": false
1615
}
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
------------------ -----------------------------
2-
 Option   Value 
3-
------------------ -----------------------------
4-
Service ID -
5-
Class Full\Qualified\Class1
6-
Tags -
7-
Public yes
8-
Synthetic no
9-
Lazy yes
10-
Shared yes
11-
Abstract yes
12-
Autowired no
13-
Autowiring Types -
14-
Factory Class Full\Qualified\FactoryClass
15-
Factory Method get
16-
------------------ -----------------------------
1+
---------------- -----------------------------
2+
 Option   Value 
3+
---------------- -----------------------------
4+
Service ID -
5+
Class Full\Qualified\Class1
6+
Tags -
7+
Public yes
8+
Synthetic no
9+
Lazy yes
10+
Shared yes
11+
Abstract yes
12+
Autowired no
13+
Factory Class Full\Qualified\FactoryClass
14+
Factory Method get
15+
---------------- -----------------------------
1716

src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,5 @@
3232
"calls": [
3333
"setMailer"
3434
],
35-
"autowire": false,
36-
"autowiring_types": []
35+
"autowire": false
3736
}

0 commit comments

Comments
 (0)