Skip to content

Commit 88cddb8

Browse files
feature #22773 [DependencyInjection] remove deprecated autowiring_types feature (hhamon)
This PR was merged into the 4.0-dev branch. Discussion ---------- [DependencyInjection] remove deprecated autowiring_types feature | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | no | Fixed tickets | ~ | License | MIT | Doc PR | ~ Commits ------- 6fdcb84 [DependencyInjection] remove deprecated autowiring_types feature
2 parents 5370a02 + 6fdcb84 commit 88cddb8

22 files changed

+1
-315
lines changed

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

-7
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,6 @@ private function getContainerDefinitionData(Definition $definition, $omitTags =
231231
'autoconfigure' => $definition->isAutoconfigured(),
232232
);
233233

234-
// forward compatibility with DependencyInjection component in version 4.0
235-
if (method_exists($definition, 'getAutowiringTypes')) {
236-
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
237-
$data['autowiring_types'][] = $autowiringType;
238-
}
239-
}
240-
241234
if ($showArguments) {
242235
$data['arguments'] = $this->describeValue($definition->getArguments(), $omitTags, $showArguments);
243236
}

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

-7
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,6 @@ protected function describeContainerDefinition(Definition $definition, array $op
191191
."\n".'- Autoconfigured: '.($definition->isAutoconfigured() ? 'yes' : 'no')
192192
;
193193

194-
// forward compatibility with DependencyInjection component in version 4.0
195-
if (method_exists($definition, 'getAutowiringTypes')) {
196-
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
197-
$output .= "\n".'- Autowiring Type: `'.$autowiringType.'`';
198-
}
199-
}
200-
201194
if (isset($options['show_arguments']) && $options['show_arguments']) {
202195
$output .= "\n".'- Arguments: '.($definition->getArguments() ? 'yes' : 'no');
203196
}

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

-5
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,6 @@ protected function describeContainerDefinition(Definition $definition, array $op
309309
$tableRows[] = array('Autowired', $definition->isAutowired() ? 'yes' : 'no');
310310
$tableRows[] = array('Autoconfigured', $definition->isAutoconfigured() ? 'yes' : 'no');
311311

312-
// forward compatibility with DependencyInjection component in version 4.0
313-
if (method_exists($definition, 'getAutowiringTypes') && $autowiringTypes = $definition->getAutowiringTypes(false)) {
314-
$tableRows[] = array('Autowiring Types', implode(', ', $autowiringTypes));
315-
}
316-
317312
if ($definition->getFile()) {
318313
$tableRows[] = array('Required File', $definition->getFile() ? $definition->getFile() : '-');
319314
}

src/Symfony/Component/DependencyInjection/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
4.0.0
55
-----
66

7+
* removed support for autowiring types
78
* removed `Container::isFrozen`
89
* removed support for dumping an ucompiled container in `PhpDumper`
910
* removed support for generating a dumped `Container` without populating the method map

src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

-16
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
*/
2828
class AutowirePass extends AbstractRecursivePass
2929
{
30-
private $definedTypes = array();
3130
private $types;
3231
private $ambiguousServiceTypes = array();
3332
private $autowired = array();
@@ -62,7 +61,6 @@ public function process(ContainerBuilder $container)
6261
try {
6362
parent::process($container);
6463
} finally {
65-
$this->definedTypes = array();
6664
$this->types = null;
6765
$this->ambiguousServiceTypes = array();
6866
$this->autowired = array();
@@ -324,10 +322,6 @@ private function getAutowiredReference(TypedReference $reference)
324322
$this->populateAvailableTypes();
325323
}
326324

327-
if (isset($this->definedTypes[$type])) {
328-
return new TypedReference($this->types[$type], $type);
329-
}
330-
331325
if (isset($this->types[$type])) {
332326
@trigger_error(sprintf('Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won\'t be supported in version 4.0. You should %s the "%s" service to "%s" instead.', isset($this->types[$this->types[$type]]) ? 'alias' : 'rename (or alias)', $this->types[$type], $type), E_USER_DEPRECATED);
333327

@@ -370,12 +364,6 @@ private function populateAvailableType($id, Definition $definition)
370364
return;
371365
}
372366

373-
foreach ($definition->getAutowiringTypes(false) as $type) {
374-
$this->definedTypes[$type] = true;
375-
$this->types[$type] = $id;
376-
unset($this->ambiguousServiceTypes[$type]);
377-
}
378-
379367
if ($definition->isDeprecated() || !$reflectionClass = $this->container->getReflectionClass($definition->getClass(), true)) {
380368
return;
381369
}
@@ -397,10 +385,6 @@ private function populateAvailableType($id, Definition $definition)
397385
*/
398386
private function set($type, $id)
399387
{
400-
if (isset($this->definedTypes[$type])) {
401-
return;
402-
}
403-
404388
// is this already a type/class that is known to match multiple services?
405389
if (isset($this->ambiguousServiceTypes[$type])) {
406390
$this->ambiguousServiceTypes[$type][] = $id;

src/Symfony/Component/DependencyInjection/Compiler/DecoratorServicePass.php

-6
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,9 @@ public function process(ContainerBuilder $container)
5353
} else {
5454
$decoratedDefinition = $container->getDefinition($inner);
5555
$definition->setTags(array_merge($decoratedDefinition->getTags(), $definition->getTags()));
56-
if ($types = array_merge($decoratedDefinition->getAutowiringTypes(false), $definition->getAutowiringTypes(false))) {
57-
$definition->setAutowiringTypes($types);
58-
}
5956
$public = $decoratedDefinition->isPublic();
6057
$decoratedDefinition->setPublic(false);
6158
$decoratedDefinition->setTags(array());
62-
if ($decoratedDefinition->getAutowiringTypes(false)) {
63-
$decoratedDefinition->setAutowiringTypes(array());
64-
}
6559
$container->setDefinition($renamedId, $decoratedDefinition);
6660
}
6761

src/Symfony/Component/DependencyInjection/Compiler/ResolveDefinitionTemplatesPass.php

-8
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ private function doResolveDefinition(ChildDefinition $definition)
8989
$def->setArguments($parentDef->getArguments());
9090
$def->setMethodCalls($parentDef->getMethodCalls());
9191
$def->setProperties($parentDef->getProperties());
92-
if ($parentDef->getAutowiringTypes(false)) {
93-
$def->setAutowiringTypes($parentDef->getAutowiringTypes(false));
94-
}
9592
if ($parentDef->isDeprecated()) {
9693
$def->setDeprecated(true, $parentDef->getDeprecationMessage('%service_id%'));
9794
}
@@ -162,11 +159,6 @@ private function doResolveDefinition(ChildDefinition $definition)
162159
$def->setMethodCalls(array_merge($def->getMethodCalls(), $calls));
163160
}
164161

165-
// merge autowiring types
166-
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
167-
$def->addAutowiringType($autowiringType);
168-
}
169-
170162
// these attributes are always taken from the child
171163
$def->setAbstract($definition->isAbstract());
172164
$def->setTags($definition->getTags());

src/Symfony/Component/DependencyInjection/Definition.php

-91
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class Definition
3939
private $lazy = false;
4040
private $decoratedService;
4141
private $autowired = false;
42-
private $autowiringTypes = array();
4342
private $changes = array();
4443

4544
protected $arguments = array();
@@ -745,28 +744,6 @@ public function getConfigurator()
745744
return $this->configurator;
746745
}
747746

748-
/**
749-
* Sets types that will default to this definition.
750-
*
751-
* @param string[] $types
752-
*
753-
* @return $this
754-
*
755-
* @deprecated since version 3.3, to be removed in 4.0.
756-
*/
757-
public function setAutowiringTypes(array $types)
758-
{
759-
@trigger_error('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead.', E_USER_DEPRECATED);
760-
761-
$this->autowiringTypes = array();
762-
763-
foreach ($types as $type) {
764-
$this->autowiringTypes[$type] = true;
765-
}
766-
767-
return $this;
768-
}
769-
770747
/**
771748
* Is the definition autowired?
772749
*
@@ -792,72 +769,4 @@ public function setAutowired($autowired)
792769

793770
return $this;
794771
}
795-
796-
/**
797-
* Gets autowiring types that will default to this definition.
798-
*
799-
* @return string[]
800-
*
801-
* @deprecated since version 3.3, to be removed in 4.0.
802-
*/
803-
public function getAutowiringTypes(/*$triggerDeprecation = true*/)
804-
{
805-
if (1 > func_num_args() || func_get_arg(0)) {
806-
@trigger_error('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead.', E_USER_DEPRECATED);
807-
}
808-
809-
return array_keys($this->autowiringTypes);
810-
}
811-
812-
/**
813-
* Adds a type that will default to this definition.
814-
*
815-
* @param string $type
816-
*
817-
* @return $this
818-
*
819-
* @deprecated since version 3.3, to be removed in 4.0.
820-
*/
821-
public function addAutowiringType($type)
822-
{
823-
@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);
824-
825-
$this->autowiringTypes[$type] = true;
826-
827-
return $this;
828-
}
829-
830-
/**
831-
* Removes a type.
832-
*
833-
* @param string $type
834-
*
835-
* @return $this
836-
*
837-
* @deprecated since version 3.3, to be removed in 4.0.
838-
*/
839-
public function removeAutowiringType($type)
840-
{
841-
@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);
842-
843-
unset($this->autowiringTypes[$type]);
844-
845-
return $this;
846-
}
847-
848-
/**
849-
* Will this definition default for the given type?
850-
*
851-
* @param string $type
852-
*
853-
* @return bool
854-
*
855-
* @deprecated since version 3.3, to be removed in 4.0.
856-
*/
857-
public function hasAutowiringType($type)
858-
{
859-
@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);
860-
861-
return isset($this->autowiringTypes[$type]);
862-
}
863772
}

src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php

-7
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,6 @@ private function addService($definition, $id, \DOMElement $parent)
198198
$service->setAttribute('autowire', 'true');
199199
}
200200

201-
foreach ($definition->getAutowiringTypes(false) as $autowiringTypeValue) {
202-
$autowiringType = $this->document->createElement('autowiring-type');
203-
$autowiringType->appendChild($this->document->createTextNode($autowiringTypeValue));
204-
205-
$service->appendChild($autowiringType);
206-
}
207-
208201
if ($definition->isAutoconfigured()) {
209202
$service->setAttribute('autoconfigure', 'true');
210203
}

src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php

-8
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,6 @@ private function addService($id, $definition)
109109
$code .= " autowire: true\n";
110110
}
111111

112-
$autowiringTypesCode = '';
113-
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
114-
$autowiringTypesCode .= sprintf(" - %s\n", $this->dumper->dump($autowiringType));
115-
}
116-
if ($autowiringTypesCode) {
117-
$code .= sprintf(" autowiring_types:\n%s", $autowiringTypesCode);
118-
}
119-
120112
if ($definition->isLazy()) {
121113
$code .= " lazy: true\n";
122114
}

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

-4
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,6 @@ private function parseDefinition(\DOMElement $service, $file, array $defaults)
341341
$definition->addTag($tag->getAttribute('name'), $parameters);
342342
}
343343

344-
foreach ($this->getChildren($service, 'autowiring-type') as $type) {
345-
$definition->addAutowiringType($type->textContent);
346-
}
347-
348344
if ($value = $service->getAttribute('decorates')) {
349345
$renameId = $service->hasAttribute('decoration-inner-name') ? $service->getAttribute('decoration-inner-name') : null;
350346
$priority = $service->hasAttribute('decoration-priority') ? $service->getAttribute('decoration-priority') : 0;

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

-19
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class YamlFileLoader extends FileLoader
5555
'decoration_inner_name' => 'decoration_inner_name',
5656
'decoration_priority' => 'decoration_priority',
5757
'autowire' => 'autowire',
58-
'autowiring_types' => 'autowiring_types',
5958
'autoconfigure' => 'autoconfigure',
6059
);
6160

@@ -500,24 +499,6 @@ private function parseDefinition($id, $service, $file, array $defaults)
500499
$definition->setAutowired($service['autowire']);
501500
}
502501

503-
if (isset($service['autowiring_types'])) {
504-
if (is_string($service['autowiring_types'])) {
505-
$definition->addAutowiringType($service['autowiring_types']);
506-
} else {
507-
if (!is_array($service['autowiring_types'])) {
508-
throw new InvalidArgumentException(sprintf('Parameter "autowiring_types" must be a string or an array for service "%s" in %s. Check your YAML syntax.', $id, $file));
509-
}
510-
511-
foreach ($service['autowiring_types'] as $autowiringType) {
512-
if (!is_string($autowiringType)) {
513-
throw new InvalidArgumentException(sprintf('A "autowiring_types" attribute must be of type string for service "%s" in %s. Check your YAML syntax.', $id, $file));
514-
}
515-
516-
$definition->addAutowiringType($autowiringType);
517-
}
518-
}
519-
}
520-
521502
if (isset($service['autoconfigure'])) {
522503
if (!$definition instanceof ChildDefinition) {
523504
$definition->setAutoconfigured($service['autoconfigure']);

src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd

-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@
116116
<xsd:element name="call" type="call" minOccurs="0" maxOccurs="unbounded" />
117117
<xsd:element name="tag" type="tag" minOccurs="0" maxOccurs="unbounded" />
118118
<xsd:element name="property" type="property" minOccurs="0" maxOccurs="unbounded" />
119-
<xsd:element name="autowiring-type" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
120119
</xsd:choice>
121120
<xsd:attribute name="id" type="xsd:string" />
122121
<xsd:attribute name="class" type="xsd:string" />

src/Symfony/Component/DependencyInjection/Tests/Compiler/DecoratorServicePassTest.php

-24
Original file line numberDiff line numberDiff line change
@@ -144,30 +144,6 @@ public function testProcessMovesTagsFromDecoratedDefinitionToDecoratingDefinitio
144144
$this->assertEquals(array('bar' => array('attr' => 'baz'), 'foobar' => array('attr' => 'bar')), $container->getDefinition('baz')->getTags());
145145
}
146146

147-
/**
148-
* @group legacy
149-
*/
150-
public function testProcessMergesAutowiringTypesInDecoratingDefinitionAndRemoveThemFromDecoratedDefinition()
151-
{
152-
$container = new ContainerBuilder();
153-
154-
$container
155-
->register('parent')
156-
->addAutowiringType('Bar')
157-
;
158-
159-
$container
160-
->register('child')
161-
->setDecoratedService('parent')
162-
->addAutowiringType('Foo')
163-
;
164-
165-
$this->process($container);
166-
167-
$this->assertEquals(array('Bar', 'Foo'), $container->getDefinition('child')->getAutowiringTypes());
168-
$this->assertEmpty($container->getDefinition('child.inner')->getAutowiringTypes());
169-
}
170-
171147
protected function process(ContainerBuilder $container)
172148
{
173149
$repeatedPass = new DecoratorServicePass();

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveDefinitionTemplatesPassTest.php

-26
Original file line numberDiff line numberDiff line change
@@ -324,32 +324,6 @@ public function testDecoratedServiceCanOverwriteDeprecatedParentStatus()
324324
$this->assertFalse($container->getDefinition('decorated_deprecated_parent')->isDeprecated());
325325
}
326326

327-
/**
328-
* @group legacy
329-
*/
330-
public function testProcessMergeAutowiringTypes()
331-
{
332-
$container = new ContainerBuilder();
333-
334-
$container
335-
->register('parent')
336-
->addAutowiringType('Foo')
337-
;
338-
339-
$container
340-
->setDefinition('child', new ChildDefinition('parent'))
341-
->addAutowiringType('Bar')
342-
;
343-
344-
$this->process($container);
345-
346-
$childDef = $container->getDefinition('child');
347-
$this->assertEquals(array('Foo', 'Bar'), $childDef->getAutowiringTypes());
348-
349-
$parentDef = $container->getDefinition('parent');
350-
$this->assertSame(array('Foo'), $parentDef->getAutowiringTypes());
351-
}
352-
353327
public function testProcessResolvesAliases()
354328
{
355329
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)