8000 [DI] Deprecate autowiring-types in favor of aliases by nicolas-grekas · Pull Request #21494 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] Deprecate autowiring-types in favor of aliases #21494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions UPGRADE-3.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() : '-');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
10 changes: 4 additions & 6 deletions src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down Expand Up @@ -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" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"shared": true,
"abstract": true,
"autowire": false,
"autowiring_types": [],
"file": null,
"factory_class": "Full\\Qualified\\FactoryClass",
"factory_method": "get",
Expand Down
F438
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------- -----------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"shared": true,
"abstract": false,
"autowire": false,
"autowiring_types": [],
"file": "\/path\/to\/file",
"factory_service": "factory.service",
"factory_method": "get",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 10000
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
----------------- ---------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

],
"autowire": false,
"autowiring_types": [],
"arguments": [
{
"type": "service",
Expand All @@ -29,7 +28,6 @@
"shared": true,
"abstract": false,
"autowire": false,
"autowiring_types": [],
"arguments": [
"arg1",
"arg2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"tags": [

],
"autowire": false,
"autowiring_types": []
"autowire": false
}
},
"aliases": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
"tags": [

],
"autowire": false,
"autowiring_types": []
"autowire": false
},
"definition_2": {
"class": "Full\\Qualified\\Class2",
Expand Down Expand Up @@ -50,8 +49,7 @@
"calls": [
"setMailer"
],
"autowire": false,
"autowiring_types": []
"autowire": false
}
},
"aliases": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
"calls": [
"setMailer"
],
"autowire": false,
"autowiring_types": []
"autowire": false
}
},
"aliases": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
],
"factory_service": "factory.service",
"factory_method": "get",
"autowire": false,
"autowiring_types": []
"autowire": false
}
],
"tag2": [
Expand All @@ -31,8 +30,7 @@
],
"factory_service": "factory.service",
"factory_method": "get",
"autowire": false,
"autowiring_types": []
"autowire": false
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
"tags": [

],
"autowire": false,
"autowiring_types": []
"autowire": false
}
Original file line number Diff line number Diff line change
@@ -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
---------------- -----------------------------

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@
"calls": [
"setMailer"
],
"autowire": false,
"autowiring_types": []
"autowire": false
}
Loading
0