[DI] Deprecate autowiring-types in favor of aliases
This commit is contained in:
parent
b4ff1c8767
commit
b11d391cb7
@ -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.
|
||||
|
@ -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 @@ class JsonDescriptor extends Descriptor
|
||||
'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 @@ class MarkdownDescriptor extends Descriptor
|
||||
."\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 @@ class TextDescriptor extends Descriptor
|
||||
$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 @@ class TemplatingPass implements CompilerPassInterface
|
||||
}
|
||||
|
||||
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 @@ class FrameworkExtension extends Extension
|
||||
->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 @@
|
||||
[33mInformation for Service "[39m[32mservice_1[39m[33m"[39m
|
||||
[33m===================================[39m
|
||||
|
||||
------------------ -----------------------------
|
||||
[32m Option [39m [32m Value [39m
|
||||
------------------ -----------------------------
|
||||
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
|
||||
------------------ -----------------------------
|
||||
---------------- -----------------------------
|
||||
[32m Option [39m [32m Value [39m
|
||||
---------------- -----------------------------
|
||||
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 @@
|
||||
[33mInformation for Service "[39m[32mservice_2[39m[33m"[39m
|
||||
[33m===================================[39m
|
||||
|
||||
------------------ ---------------------------------
|
||||
[32m Option [39m [32m Value [39m
|
||||
------------------ ---------------------------------
|
||||
Service ID service_2
|
||||
Class Full\Qualified\Class2
|
||||
Tags tag1 ([32mattr1[39m: val1, [32mattr2[39m: val2)
|
||||
tag1 ([32mattr3[39m: 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
|
||||
------------------ ---------------------------------
|
||||
----------------- ---------------------------------
|
||||
[32m Option [39m [32m Value [39m
|
||||
----------------- ---------------------------------
|
||||
Service ID service_2
|
||||
Class Full\Qualified\Class2
|
||||
Tags tag1 ([32mattr1[39m: val1, [32mattr2[39m: val2)
|
||||
tag1 ([32mattr3[39m: 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 @@
|
||||
------------------ -----------------------------
|
||||
[32m Option [39m [32m Value [39m
|
||||
------------------ -----------------------------
|
||||
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
|
||||
------------------ -----------------------------
|
||||
---------------- -----------------------------
|
||||
[32m Option [39m [32m Value [39m
|
||||
---------------- -----------------------------
|
||||
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
|
||||
}
|
||||
|
@ -1,21 +1,20 @@
|
||||
------------------ ---------------------------------
|
||||
[32m Option [39m [32m Value [39m
|
||||
------------------ ---------------------------------
|
||||
Service ID -
|
||||
Class Full\Qualified\Class2
|
||||
Tags tag1 ([32mattr1[39m: val1, [32mattr2[39m: val2)
|
||||
tag1 ([32mattr3[39m: 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
|
||||
------------------ ---------------------------------
|
||||
----------------- ---------------------------------
|
||||
[32m Option [39m [32m Value [39m
|
||||
----------------- ---------------------------------
|
||||
Service ID -
|
||||
Class Full\Qualified\Class2
|
||||
Tags tag1 ([32mattr1[39m: val1, [32mattr2[39m: val2)
|
||||
tag1 ([32mattr3[39m: 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
|
||||
----------------- ---------------------------------
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
"shared": true,
|
||||
"abstract": true,
|
||||
"autowire": false,
|
||||
"autowiring_types": [],
|
||||
"arguments": [
|
||||
{
|
||||
"type": "service",
|
||||
@ -21,7 +20,6 @@
|
||||
"shared": true,
|
||||
"abstract": false,
|
||||
"autowire": false,
|
||||
"autowiring_types": [],
|
||||
"arguments": [
|
||||
"arg1",
|
||||
"arg2"
|
||||
|
@ -1,20 +1,19 @@
|
||||
------------------ -----------------------------
|
||||
[32m Option [39m [32m Value [39m
|
||||
------------------ -----------------------------
|
||||
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
|
||||
Arguments Service(definition2)
|
||||
%parameter%
|
||||
Inlined Service
|
||||
------------------ -----------------------------
|
||||
---------------- -----------------------------
|
||||
[32m Option [39m [32m Value [39m
|
||||
---------------- -----------------------------
|
||||
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
|
||||
Arguments Service(definition2)
|
||||
%parameter%
|
||||
Inlined Service
|
||||
---------------- -----------------------------
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
"shared": true,
|
||||
"abstract": false,
|
||||
"autowire": false,
|
||||
"autowiring_types": [],
|
||||
"arguments": [],
|
||||
"file": "\/path\/to\/file",
|
||||
"factory_service": "factory.service",
|
||||
|
@ -1,21 +1,20 @@
|
||||
------------------ ---------------------------------
|
||||
[32m Option [39m [32m Value [39m
|
||||
------------------ ---------------------------------
|
||||
Service ID -
|
||||
Class Full\Qualified\Class2
|
||||
Tags tag1 ([32mattr1[39m: val1, [32mattr2[39m: val2)
|
||||
tag1 ([32mattr3[39m: 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
|
||||
------------------ ---------------------------------
|
||||
----------------- ---------------------------------
|
||||
[32m Option [39m [32m Value [39m
|
||||
----------------- ---------------------------------
|
||||
Service ID -
|
||||
Class Full\Qualified\Class2
|
||||
Tags tag1 ([32mattr1[39m: val1, [32mattr2[39m: val2)
|
||||
tag1 ([32mattr3[39m: 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
|
||||
----------------- ---------------------------------
|
||||
|
||||
|
@ -4,6 +4,7 @@ CHANGELOG
|
||||
3.3.0
|
||||
-----
|
||||
|
||||
* deprecated autowiring-types, use aliases instead
|
||||
* [EXPERIMENTAL] added support for getter-injection
|
||||
* added support for omitting the factory class name in a service definition if the definition class is set
|
||||
* deprecated case insensitivity of service identifiers
|
||||
|
@ -245,6 +245,13 @@ class AutowirePass extends AbstractRecursivePass
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->container->has($typeName) && !$this->container->findDefinition($typeName)->isAbstract()) {
|
||||
$arguments[$index] = new Reference($typeName);
|
||||
$didAutowire = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (null === $this->types) {
|
||||
$this->populateAvailableTypes();
|
||||
}
|
||||
@ -332,7 +339,7 @@ class AutowirePass extends AbstractRecursivePass
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($definition->getAutowiringTypes() as $type) {
|
||||
foreach ($definition->getAutowiringTypes(false) as $type) {
|
||||
$this->definedTypes[$type] = true;
|
||||
$this->types[$type] = $id;
|
||||
}
|
||||
|
@ -53,11 +53,15 @@ class DecoratorServicePass implements CompilerPassInterface
|
||||
} else {
|
||||
$decoratedDefinition = $container->getDefinition($inner);
|
||||
$definition->setTags(array_merge($decoratedDefinition->getTags(), $definition->getTags()));
|
||||
$definition->setAutowiringTypes(array_merge($decoratedDefinition->getAutowiringTypes(), $definition->getAutowiringTypes()));
|
||||
if ($types = array_merge($decoratedDefinition->getAutowiringTypes(false), $definition->getAutowiringTypes(false))) {
|
||||
$definition->setAutowiringTypes($types);
|
||||
}
|
||||
$public = $decoratedDefinition->isPublic();
|
||||
$decoratedDefinition->setPublic(false);
|
||||
$decoratedDefinition->setTags(array());
|
||||
$decoratedDefinition->setAutowiringTypes(array());
|
||||
if ($decoratedDefinition->getAutowiringTypes(false)) {
|
||||
$decoratedDefinition->setAutowiringTypes(array());
|
||||
}
|
||||
$container->setDefinition($renamedId, $decoratedDefinition);
|
||||
}
|
||||
|
||||
|
@ -53,9 +53,9 @@ class PassConfig
|
||||
new ResolveFactoryClassPass(),
|
||||
new FactoryReturnTypePass($resolveClassPass),
|
||||
new CheckDefinitionValidityPass(),
|
||||
new AutowirePass(),
|
||||
new ResolveReferencesToAliasesPass(),
|
||||
new ResolveInvalidReferencesPass(),
|
||||
new AutowirePass(),
|
||||
new AnalyzeServiceReferencesPass(true),
|
||||
new CheckCircularReferencesPass(),
|
||||
new CheckReferenceValidityPass(),
|
||||
|
@ -90,7 +90,9 @@ class ResolveDefinitionTemplatesPass extends AbstractRecursivePass
|
||||
$def->setMethodCalls($parentDef->getMethodCalls());
|
||||
$def->setOverriddenGetters($parentDef->getOverriddenGetters());
|
||||
$def->setProperties($parentDef->getProperties());
|
||||
$def->setAutowiringTypes($parentDef->getAutowiringTypes());
|
||||
if ($parentDef->getAutowiringTypes(false)) {
|
||||
$def->setAutowiringTypes($parentDef->getAutowiringTypes(false));
|
||||
}
|
||||
if ($parentDef->isDeprecated()) {
|
||||
$def->setDeprecated(true, $parentDef->getDeprecationMessage('%service_id%'));
|
||||
}
|
||||
@ -167,7 +169,7 @@ class ResolveDefinitionTemplatesPass extends AbstractRecursivePass
|
||||
}
|
||||
|
||||
// merge autowiring types
|
||||
foreach ($definition->getAutowiringTypes() as $autowiringType) {
|
||||
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
|
||||
$def->addAutowiringType($autowiringType);
|
||||
}
|
||||
|
||||
|
@ -679,9 +679,13 @@ class Definition
|
||||
* @param string[] $types
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
public function setAutowiringTypes(array $types)
|
||||
{
|
||||
@trigger_error('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead.', E_USER_DEPRECATED);
|
||||
|
||||
$this->autowiringTypes = array();
|
||||
|
||||
foreach ($types as $type) {
|
||||
@ -750,9 +754,15 @@ class Definition
|
||||
* Gets autowiring types that will default to this definition.
|
||||
*
|
||||
* @return string[]
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
public function getAutowiringTypes()
|
||||
public function getAutowiringTypes(/*$triggerDeprecation = true*/)
|
||||
{
|
||||
if (1 > func_num_args() || func_get_arg(0)) {
|
||||
@trigger_error('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead.', E_USER_DEPRECATED);
|
||||
}
|
||||
|
||||
return array_keys($this->autowiringTypes);
|
||||
}
|
||||
|
||||
@ -762,9 +772,13 @@ class Definition
|
||||
* @param string $type
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
public function addAutowiringType($type)
|
||||
{
|
||||
@trigger_error(sprintf('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead for "%s".', $type), E_USER_DEPRECATED);
|
||||
|
||||
$this->autowiringTypes[$type] = true;
|
||||
|
||||
return $this;
|
||||
@ -776,9 +790,13 @@ class Definition
|
||||
* @param string $type
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
public function removeAutowiringType($type)
|
||||
{
|
||||
@trigger_error(sprintf('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead for "%s".', $type), E_USER_DEPRECATED);
|
||||
|
||||
unset($this->autowiringTypes[$type]);
|
||||
|
||||
return $this;
|
||||
@ -790,9 +808,13 @@ class Definition
|
||||
* @param string $type
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @deprecated since version 3.3, to be removed in 4.0.
|
||||
*/
|
||||
public function hasAutowiringType($type)
|
||||
{
|
||||
@trigger_error(sprintf('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead for "%s".', $type), E_USER_DEPRECATED);
|
||||
|
||||
return isset($this->autowiringTypes[$type]);
|
||||
}
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ class XmlDumper extends Dumper
|
||||
$service->setAttribute('autowire', 'true');
|
||||
}
|
||||
|
||||
foreach ($definition->getAutowiringTypes() as $autowiringTypeValue) {
|
||||
foreach ($definition->getAutowiringTypes(false) as $autowiringTypeValue) {
|
||||
$autowiringType = $this->document->createElement('autowiring-type');
|
||||
$autowiringType->appendChild($this->document->createTextNode($autowiringTypeValue));
|
||||
|
||||
|
@ -107,7 +107,7 @@ class YamlDumper extends Dumper
|
||||
}
|
||||
|
||||
$autowiringTypesCode = '';
|
||||
foreach ($definition->getAutowiringTypes() as $autowiringType) {
|
||||
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
|
||||
$autowiringTypesCode .= sprintf(" - %s\n", $this->dumper->dump($autowiringType));
|
||||
}
|
||||
if ($autowiringTypesCode) {
|
||||
|
@ -191,7 +191,7 @@ class AutowirePassTest extends \PHPUnit_Framework_TestCase
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('a1', __NAMESPACE__.'\Foo');
|
||||
$container->register('a2', __NAMESPACE__.'\Foo')->addAutowiringType(__NAMESPACE__.'\Foo');
|
||||
$container->register(Foo::class, Foo::class);
|
||||
$aDefinition = $container->register('a', __NAMESPACE__.'\NotGuessableArgument');
|
||||
$aDefinition->setAutowired(true);
|
||||
|
||||
@ -199,7 +199,7 @@ class AutowirePassTest extends \PHPUnit_Framework_TestCase
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertCount(1, $container->getDefinition('a')->getArguments());
|
||||
$this->assertEquals('a2', (string) $container->getDefinition('a')->getArgument(0));
|
||||
$this->assertEquals(Foo::class, (string) $container->getDefinition('a')->getArgument(0));
|
||||
}
|
||||
|
||||
public function testWithTypeSet()
|
||||
@ -207,7 +207,8 @@ class AutowirePassTest extends \PHPUnit_Framework_TestCase
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$container->register('c1', __NAMESPACE__.'\CollisionA');
|
||||
$container->register('c2', __NAMESPACE__.'\CollisionB')->addAutowiringType(__NAMESPACE__.'\CollisionInterface');
|
||||
$container->register('c2', __NAMESPACE__.'\CollisionB');
|
||||
$container->setAlias(CollisionInterface::class, 'c2');
|
||||
$aDefinition = $container->register('a', __NAMESPACE__.'\CannotBeAutowired');
|
||||
$aDefinition->setAutowired(true);
|
||||
|
||||
@ -215,7 +216,7 @@ class AutowirePassTest extends \PHPUnit_Framework_TestCase
|
||||
$pass->process($container);
|
||||
|
||||
$this->assertCount(1, $container->getDefinition('a')->getArguments());
|
||||
$this->assertEquals('c2', (string) $container->getDefinition('a')->getArgument(0));
|
||||
$this->assertEquals(CollisionInterface::class, (string) $container->getDefinition('a')->getArgument(0));
|
||||
}
|
||||
|
||||
public function testCreateDefinition()
|
||||
|
@ -143,6 +143,9 @@ class DecoratorServicePassTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array('bar' => array('attr' => 'baz'), 'foobar' => array('attr' => 'bar')), $container->getDefinition('baz')->getTags());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testProcessMergesAutowiringTypesInDecoratingDefinitionAndRemoveThemFromDecoratedDefinition()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
@ -322,6 +322,9 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($container->getDefinition('decorated_deprecated_parent')->isDeprecated());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testProcessMergeAutowiringTypes()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
@ -313,6 +313,9 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue($def->isAutowired());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testTypes()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
|
@ -7,8 +7,6 @@ $container = new ContainerBuilder();
|
||||
$container
|
||||
->register('foo', 'Foo')
|
||||
->setAutowired(true)
|
||||
->addAutowiringType('A')
|
||||
->addAutowiringType('B')
|
||||
;
|
||||
|
||||
return $container;
|
||||
|
@ -1,9 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
<services>
|
||||
<service id="foo" class="Foo" autowire="true">
|
||||
<autowiring-type>A</autowiring-type>
|
||||
<autowiring-type>B</autowiring-type>
|
||||
</service>
|
||||
<service id="foo" class="Foo" autowire="true"/>
|
||||
</services>
|
||||
</container>
|
||||
|
@ -3,6 +3,3 @@ services:
|
||||
foo:
|
||||
class: Foo
|
||||
autowire: true
|
||||
autowiring_types:
|
||||
- A
|
||||
- B
|
||||
|
@ -554,6 +554,9 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame('configureBar', $barConfigurator[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testType()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
@ -325,6 +325,9 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$loader->load('bad_types2.yml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testTypes()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
Reference in New Issue
Block a user