Permalink
Browse files

feature #21494 [DI] Deprecate autowiring-types in favor of aliases (n…

…icolas-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
  • Loading branch information...
2 parents 29db096 + b11d391 commit 1b2801591e274aef6864078f5fee7d742f4d100e @fabpot fabpot committed Feb 1, 2017
Showing with 230 additions and 176 deletions.
  1. +17 −0 UPGRADE-3.3.md
  2. +17 −0 UPGRADE-4.0.md
  3. +1 −2 src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/JsonDescriptor.php
  4. +2 −2 src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/MarkdownDescriptor.php
  5. +3 −2 src/Symfony/Bundle/FrameworkBundle/Console/Descriptor/TextDescriptor.php
  6. +3 −2 src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TemplatingPass.php
  7. +1 −1 src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
  8. +2 −3 src/Symfony/Bundle/FrameworkBundle/Resources/config/annotations.xml
  9. +4 −6 src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml
  10. +1 −2 src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml
  11. +0 −1 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.json
  12. +15 −16 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_1.txt
  13. +0 −1 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.json
  14. +19 −20 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/alias_with_definition_2.txt
  15. +0 −2 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_arguments.json
  16. +1 −2 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_public.json
  17. +2 −4 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_services.json
  18. +1 −2 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tag1.json
  19. +2 −4 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/builder_1_tags.json
  20. +1 −2 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.json
  21. +15 −16 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_1.txt
  22. +1 −2 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.json
  23. +19 −20 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_2.txt
  24. +0 −2 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.json
  25. +18 −19 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_1.txt
  26. +0 −1 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_2.json
  27. +19 −20 src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/definition_arguments_2.txt
  28. +1 −0 src/Symfony/Component/DependencyInjection/CHANGELOG.md
  29. +8 −1 src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php
  30. +6 −2 src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php
  31. +1 −1 src/Symfony/Component/DependencyInjection/Compiler/PassConfig.php
  32. +4 −2 src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php
  33. +23 −1 src/Symfony/Component/DependencyInjection/Definition.php
  34. +1 −1 src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php
  35. +1 −1 src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php
  36. +5 −4 src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php
  37. +3 −0 src/Symfony/Component/DependencyInjection/Tests/Compiler/DecoratorServicePassTest.php
  38. +3 −0 src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php
  39. +3 −0 src/Symfony/Component/DependencyInjection/Tests/DefinitionTest.php
  40. +0 −2 src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container24.php
  41. +1 −4 src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services24.xml
  42. +0 −3 src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services24.yml
  43. +3 −0 src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php
  44. +3 −0 src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php
View
@@ -14,6 +14,23 @@ Debug
DependencyInjection
-------------------
+ * Autowiring-types have been deprecated, use aliases instead.
+
+ Before:
+
+ ```xml
+ <service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader" public="false">
+ <autowiring-type>Doctrine\Common\Annotations\Reader</autowiring-type>
+ </service>
+ ```
+
+ After:
+
+ ```xml
+ <service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader" public="false" />
+ <service id="Doctrine\Common\Annotations\Reader" alias="annotations.reader" public="false" />
+ ```
+
* The `Reference` and `Alias` classes do not make service identifiers lowercase anymore.
* Case insensitivity of service identifiers is deprecated and will be removed in 4.0.
View
@@ -24,6 +24,23 @@ Debug
DependencyInjection
-------------------
+ * Autowiring-types have been removed, use aliases instead.
+
+ Before:
+
+ ```xml
+ <service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader" public="false">
+ <autowiring-type>Doctrine\Common\Annotations\Reader</autowiring-type>
+ </service>
+ ```
+
+ After:
+
+ ```xml
+ <service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader" public="false" />
+ <service id="Doctrine\Common\Annotations\Reader" alias="annotations.reader" public="false" />
+ ```
+
* Service identifiers are now case sensitive.
* The `Reference` and `Alias` classes do not make service identifiers lowercase anymore.
@@ -220,10 +220,9 @@ private function getContainerDefinitionData(Definition $definition, $omitTags =
'shared' => $definition->isShared(),
'abstract' => $definition->isAbstract(),
'autowire' => $definition->isAutowired(),
- 'autowiring_types' => array(),
);
- foreach ($definition->getAutowiringTypes() as $autowiringType) {
+ foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
$data['autowiring_types'][] = $autowiringType;
}
@@ -185,8 +185,8 @@ protected function describeContainerDefinition(Definition $definition, array $op
."\n".'- Autowired: '.($definition->isAutowired() ? 'yes' : 'no')
;
- foreach ($definition->getAutowiringTypes() as $autowiringType) {
- $output .= "\n" . '- Autowiring Type: `' . $autowiringType . '`';
+ foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
+ $output .= "\n".'- Autowiring Type: `'.$autowiringType.'`';
}
if (isset($options['show_arguments']) && $options['show_arguments']) {
@@ -294,8 +294,9 @@ protected function describeContainerDefinition(Definition $definition, array $op
$tableRows[] = array('Abstract', $definition->isAbstract() ? 'yes' : 'no');
$tableRows[] = array('Autowired', $definition->isAutowired() ? 'yes' : 'no');
- $autowiringTypes = $definition->getAutowiringTypes();
- $tableRows[] = array('Autowiring Types', $autowiringTypes ? implode(', ', $autowiringTypes) : '-');
+ if ($autowiringTypes = $definition->getAutowiringTypes(false)) {
+ $tableRows[] = array('Autowiring Types', implode(', ', $autowiringTypes));
+ }
if ($definition->getFile()) {
$tableRows[] = array('Required File', $definition->getFile() ? $definition->getFile() : '-');
@@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as FrameworkBundleEngineInterface;
+use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\Templating\EngineInterface as ComponentEngineInterface;
@@ -25,8 +26,8 @@ public function process(ContainerBuilder $container)
}
if ($container->hasAlias('templating')) {
- $definition = $container->findDefinition('templating');
- $definition->setAutowiringTypes(array(ComponentEngineInterface::class, FrameworkBundleEngineInterface::class));
+ $container->setAlias(ComponentEngineInterface::class, new Alias('templating', false));
+ $container->setAlias(FrameworkBundleEngineInterface::class, new Alias('templating', false));
}
if ($container->hasDefinition('templating.engine.php')) {
@@ -1096,8 +1096,8 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
->getDefinition('annotations.cached_reader')
->replaceArgument(1, new Reference($cacheService))
->replaceArgument(2, $config['debug'])
- ->addAutowiringType(Reader::class)
;
+ $container->setAlias(Reader::class, new Alias('annotations.cached_reader', false));
} else {
$container->removeDefinition('annotations.cached_reader');
}
@@ -5,9 +5,8 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
- <service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader" public="false">
- <autowiring-type>Doctrine\Common\Annotations\Reader</autowiring-type>
- </service>
+ <service id="annotations.reader" class="Doctrine\Common\Annotations\AnnotationReader" public="false" />
+ <service id="Doctrine\Common\Annotations\Reader" alias="annotations.reader" public="false" />
<service id="annotations.cached_reader" class="Doctrine\Common\Annotations\CachedReader" public="false">
<argument type="service" id="annotations.reader" />
@@ -7,9 +7,9 @@
<services>
<service id="event_dispatcher" class="Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher">
<argument type="service" id="service_container" />
- <autowiring-type>Symfony\Component\EventDispatcher\EventDispatcherInterface</autowiring-type>
- <autowiring-type>Symfony\Component\EventDispatcher\EventDispatcher</autowiring-type>
</service>
+ <service id="Symfony\Component\EventDispatcher\EventDispatcherInterface" alias="event_dispatcher" public="false" />
+ <service id="Symfony\Component\EventDispatcher\EventDispatcher" alias="event_dispatcher" public="false" />
<service id="http_kernel" class="Symfony\Component\HttpKernel\HttpKernel">
<argument type="service" id="event_dispatcher" />
@@ -40,10 +40,8 @@
<argument type="collection" />
</service>
- <service id="service_container" synthetic="true">
- <autowiring-type>Symfony\Component\DependencyInjection\ContainerInterface</autowiring-type>
- <autowiring-type>Symfony\Component\DependencyInjection\Container</autowiring-type>
- </service>
+ <service id="Symfony\Component\DependencyInjection\ContainerInterface" alias="service_container" public="false" />
+ <service id="Symfony\Component\DependencyInjection\Container" alias="service_container" public="false" />
<service id="kernel" synthetic="true" />
@@ -17,9 +17,8 @@
<call method="setConfigCacheFactory">
<argument type="service" id="config_cache_factory" />
</call>
-
- <autowiring-type>Symfony\Component\Translation\TranslatorInterface</autowiring-type>
</service>
+ <service id="Symfony\Component\Translation\TranslatorInterface" alias="translator" public="false" />
<service id="translator.logging" class="Symfony\Component\Translation\LoggingTranslator" public="false">
<argument type="service" id="translator.logging.inner" />
@@ -11,7 +11,6 @@
"shared": true,
"abstract": true,
"autowire": false,
- "autowiring_types": [],
"file": null,
"factory_class": "Full\\Qualified\\FactoryClass",
"factory_method": "get",
@@ -3,19 +3,18 @@
Information for Service "service_1"
===================================
- ------------------ -----------------------------
-  Option   Value 
- ------------------ -----------------------------
- Service ID service_1
- Class Full\Qualified\Class1
- Tags -
- Public yes
- Synthetic no
- Lazy yes
- Shared yes
- Abstract yes
- Autowired no
- Autowiring Types -
- Factory Class Full\Qualified\FactoryClass
- Factory Method get
- ------------------ -----------------------------
+ ---------------- -----------------------------
+  Option   Value 
+ ---------------- -----------------------------
+ Service ID service_1
+ Class Full\Qualified\Class1
+ Tags -
+ Public yes
+ Synthetic no
+ Lazy yes
+ Shared yes
+ Abstract yes
+ Autowired no
+ Factory Class Full\Qualified\FactoryClass
+ Factory Method get
+ ---------------- -----------------------------
@@ -11,7 +11,6 @@
"shared": true,
"abstract": false,
"autowire": false,
- "autowiring_types": [],
"file": "\/path\/to\/file",
"factory_service": "factory.service",
"factory_method": "get",
@@ -3,23 +3,22 @@
Information for Service "service_2"
===================================
- ------------------ ---------------------------------
-  Option   Value 
- ------------------ ---------------------------------
- Service ID service_2
- Class Full\Qualified\Class2
- Tags tag1 (attr1: val1, attr2: val2)
- tag1 (attr3: val3)
- tag2
- Calls setMailer
- Public no
- Synthetic yes
- Lazy no
- Shared yes
- Abstract no
- Autowired no
- Autowiring Types -
- Required File /path/to/file
- Factory Service factory.service
- Factory Method get
- ------------------ ---------------------------------
+ ----------------- ---------------------------------
+  Option   Value 
+ ----------------- ---------------------------------
+ Service ID service_2
+ Class Full\Qualified\Class2
+ Tags tag1 (attr1: val1, attr2: val2)
+ tag1 (attr3: val3)
+ tag2
+ Calls setMailer
+ Public no
+ Synthetic yes
+ Lazy no
+ Shared yes
+ Abstract no
+ Autowired no
+ Required File /path/to/file
+ Factory Service factory.service
+ Factory Method get
+ ----------------- ---------------------------------
@@ -14,7 +14,6 @@
],
"autowire": false,
- "autowiring_types": [],
"arguments": [
{
"type": "service",
@@ -29,7 +28,6 @@
"shared": true,
"abstract": false,
"autowire": false,
- "autowiring_types": [],
"arguments": [
"arg1",
"arg2"
@@ -13,8 +13,7 @@
"tags": [
],
- "autowire": false,
- "autowiring_types": []
+ "autowire": false
}
},
"aliases": {
@@ -13,8 +13,7 @@
"tags": [
],
- "autowire": false,
- "autowiring_types": []
+ "autowire": false
},
"definition_2": {
"class": "Full\\Qualified\\Class2",
@@ -50,8 +49,7 @@
"calls": [
"setMailer"
],
- "autowire": false,
- "autowiring_types": []
+ "autowire": false
}
},
"aliases": {
@@ -34,8 +34,7 @@
"calls": [
"setMailer"
],
- "autowire": false,
- "autowiring_types": []
+ "autowire": false
}
},
"aliases": [
@@ -13,8 +13,7 @@
],
"factory_service": "factory.service",
"factory_method": "get",
- "autowire": false,
- "autowiring_types": []
+ "autowire": false
}
],
"tag2": [
@@ -31,8 +30,7 @@
],
"factory_service": "factory.service",
"factory_method": "get",
- "autowire": false,
- "autowiring_types": []
+ "autowire": false
}
]
}
@@ -11,6 +11,5 @@
"tags": [
],
- "autowire": false,
- "autowiring_types": []
+ "autowire": false
}
@@ -1,17 +1,16 @@
- ------------------ -----------------------------
-  Option   Value 
- ------------------ -----------------------------
- Service ID -
- Class Full\Qualified\Class1
- Tags -
- Public yes
- Synthetic no
- Lazy yes
- Shared yes
- Abstract yes
- Autowired no
- Autowiring Types -
- Factory Class Full\Qualified\FactoryClass
- Factory Method get
- ------------------ -----------------------------
+ ---------------- -----------------------------
+  Option   Value 
+ ---------------- -----------------------------
+ Service ID -
+ Class Full\Qualified\Class1
+ Tags -
+ Public yes
+ Synthetic no
+ Lazy yes
+ Shared yes
+ Abstract yes
+ Autowired no
+ Factory Class Full\Qualified\FactoryClass
+ Factory Method get
+ ---------------- -----------------------------
@@ -32,6 +32,5 @@
"calls": [
"setMailer"
],
- "autowire": false,
- "autowiring_types": []
+ "autowire": false
}
Oops, something went wrong.

0 comments on commit 1b28015

Please sign in to comment.