Skip to content

[DependencyInjection] remove deprecated autowiring_types feature #22773

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
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
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,6 @@ private function getContainerDefinitionData(Definition $definition, $omitTags =
'autoconfigure' => $definition->isAutoconfigured(),
);

// forward compatibility with DependencyInjection component in version 4.0
if (method_exists($definition, 'getAutowiringTypes')) {
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
$data['autowiring_types'][] = $autowiringType;
}
}

if ($showArguments) {
$data['arguments'] = $this->describeValue($definition->getArguments(), $omitTags, $showArguments);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,6 @@ protected function describeContainerDefinition(Definition $definition, array $op
."\n".'- Autoconfigured: '.($definition->isAutoconfigured() ? 'yes' : 'no')
;

// forward compatibility with DependencyInjection component in version 4.0
if (method_exists($definition, 'getAutowiringTypes')) {
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
$output .= "\n".'- Autowiring Type: `'.$autowiringType.'`';
}
}

if (isset($options['show_arguments']) && $options['show_arguments']) {
$output .= "\n".'- Arguments: '.($definition->getArguments() ? 'yes' : 'no');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,6 @@ protected function describeContainerDefinition(Definition $definition, array $op
$tableRows[] = array('Autowired', $definition->isAutowired() ? 'yes' : 'no');
$tableRows[] = array('Autoconfigured', $definition->isAutoconfigured() ? 'yes' : 'no');

// forward compatibility with DependencyInjection component in version 4.0
if (method_exists($definition, 'getAutowiringTypes') && $autowiringTypes = $definition->getAutowiringTypes(false)) {
$tableRows[] = array('Autowiring Types', implode(', ', $autowiringTypes));
}

if ($definition->getFile()) {
$tableRows[] = array('Required File', $definition->getFile() ? $definition->getFile() : '-');
}
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/DependencyInjection/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
4.0.0
-----

* removed support for autowiring types
* removed `Container::isFrozen`
* removed support for dumping an ucompiled container in `PhpDumper`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
*/
class AutowirePass extends AbstractRecursivePass
{
private $definedTypes = array();
private $types;
private $ambiguousServiceTypes = array();
private $autowired = array();
Expand Down Expand Up @@ -62,7 +61,6 @@ public function process(ContainerBuilder $container)
try {
parent::process($container);
} finally {
$this->definedTypes = array();
$this->types = null;
$this->ambiguousServiceTypes = array();
$this->autowired = array();
Expand Down Expand Up @@ -324,10 +322,6 @@ private function getAutowiredReference(TypedReference $reference)
$this->populateAvailableTypes();
}

if (isset($this->definedTypes[$type])) {
return new TypedReference($this->types[$type], $type);
}

if (isset($this->types[$type])) {
@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);

Expand Down Expand Up @@ -370,12 +364,6 @@ private function populateAvailableType($id, Definition $definition)
return;
}

foreach ($definition->getAutowiringTypes(false) as $type) {
$this->definedTypes[$type] = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this property is not used anymore, it should be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? It seems the property remains used several times in this class.

Copy link
Member

@nicolas-grekas nicolas-grekas May 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's read, but never written to, so yes, I'm sure :)

$this->types[$type] = $id;
unset($this->ambiguousServiceTypes[$type]);
}

if ($definition->isDeprecated() || !$reflectionClass = $this->container->getReflectionClass($definition->getClass(), true)) {
return;
}
Expand All @@ -397,10 +385,6 @@ private function populateAvailableType($id, Definition $definition)
*/
private function set($type, $id)
{
if (isset($this->definedTypes[$type])) {
return;
}

// is this already a type/class that is known to match multiple services?
if (isset($this->ambiguousServiceTypes[$type])) {
$this->ambiguousServiceTypes[$type][] = $id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,9 @@ public function process(ContainerBuilder $container)
} else {
$decoratedDefinition = $container->getDefinition($inner);
$definition->setTags(array_merge($decoratedDefinition->getTags(), $definition->getTags()));
if ($types = array_merge($decoratedDefinition->getAutowiringTypes(false), $definition->getAutowiringTypes(false))) {
$definition->setAutowiringTypes($types);
}
$public = $decoratedDefinition->isPublic();
$decoratedDefinition->setPublic(false);
$decoratedDefinition->setTags(array());
if ($decoratedDefinition->getAutowiringTypes(false)) {
$decoratedDefinition->setAutowiringTypes(array());
}
$container->setDefinition($renamedId, $decoratedDefinition);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ private function doResolveDefinition(ChildDefinition $definition)
$def->setArguments($parentDef->getArguments());
$def->setMethodCalls($parentDef->getMethodCalls());
$def->setProperties($parentDef->getProperties());
if ($parentDef->getAutowiringTypes(false)) {
$def->setAutowiringTypes($parentDef->getAutowiringTypes(false));
}
if ($parentDef->isDeprecated()) {
$def->setDeprecated(true, $parentDef->getDeprecationMessage('%service_id%'));
}
Expand Down Expand Up @@ -162,11 +159,6 @@ private function doResolveDefinition(ChildDefinition $definition)
$def->setMethodCalls(array_merge($def->getMethodCalls(), $calls));
}

// merge autowiring types
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
$def->addAutowiringType($autowiringType);
}

// these attributes are always taken from the child
$def->setAbstract($definition->isAbstract());
$def->setTags($definition->getTags());
Expand Down
91 changes: 0 additions & 91 deletions src/Symfony/Component/DependencyInjection/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Definition
private $lazy = false;
private $decoratedService;
private $autowired = false;
private $autowiringTypes = array();
private $changes = array();

protected $arguments = array();
Expand Down Expand Up @@ -745,28 +744,6 @@ public function getConfigurator()
return $this->configurator;
}

/**
* Sets types that will default to this 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) {
$this->autowiringTypes[$type] = true;
}

return $this;
}

/**
* Is the definition autowired?
*
Expand All @@ -792,72 +769,4 @@ public function setAutowired($autowired)

return $this;
}

/**
* 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(/*$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);
}

/**
* Adds a type that will default to this 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;
}

/**
* Removes a type.
*
* @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;
}

/**
* Will this definition default for the given type?
*
* @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]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,6 @@ private function addService($definition, $id, \DOMElement $parent)
$service->setAttribute('autowire', 'true');
}

foreach ($definition->getAutowiringTypes(false) as $autowiringTypeValue) {
$autowiringType = $this->document->createElement('autowiring-type');
$autowiringType->appendChild($this->document->createTextNode($autowiringTypeValue));

$service->appendChild($autowiringType);
}

if ($definition->isAutoconfigured()) {
$service->setAttribute('autoconfigure', 'true');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,6 @@ private function addService($id, $definition)
$code .= " autowire: true\n";
}

$autowiringTypesCode = '';
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
$autowiringTypesCode .= sprintf(" - %s\n", $this->dumper->dump($autowiringType));
}
if ($autowiringTypesCode) {
$code .= sprintf(" autowiring_types:\n%s", $autowiringTypesCode);
}

if ($definition->isLazy()) {
$code .= " lazy: true\n";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,6 @@ private function parseDefinition(\DOMElement $service, $file, array $defaults)
$definition->addTag($tag->getAttribute('name'), $parameters);
}

foreach ($this->getChildren($service, 'autowiring-type') as $type) {
$definition->addAutowiringType($type->textContent);
}

if ($value = $service->getAttribute('decorates')) {
$renameId = $service->hasAttribute('decoration-inner-name') ? $service->getAttribute('decoration-inner-name') : null;
$priority = $service->hasAttribute('decoration-priority') ? $service->getAttribute('decoration-priority') : 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class YamlFileLoader extends FileLoader
'decoration_inner_name' => 'decoration_inner_name',
'decoration_priority' => 'decoration_priority',
'autowire' => 'autowire',
'autowiring_types' => 'autowiring_types',
'autoconfigure' => 'autoconfigure',
);

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

if (isset($service['autowiring_types'])) {
if (is_string($service['autowiring_types'])) {
$definition->addAutowiringType($service['autowiring_types']);
} else {
if (!is_array($service['autowiring_types'])) {
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));
}

foreach ($service['autowiring_types'] as $autowiringType) {
if (!is_string($autowiringType)) {
throw new InvalidArgumentException(sprintf('A "autowiring_types" attribute must be of type string for service "%s" in %s. Check your YAML syntax.', $id, $file));
}

$definition->addAutowiringType($autowiringType);
}
}
}

if (isset($service['autoconfigure'])) {
if (!$definition instanceof ChildDefinition) {
$definition->setAutoconfigured($service['autoconfigure']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
<xsd:element name="call" type="call" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="tag" type="tag" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="property" type="property" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="autowiring-type" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
</xsd:choice>
<xsd:attribute name="id" type="xsd:string" />
<xsd:attribute name="class" type="xsd:string" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,30 +144,6 @@ public function testProcessMovesTagsFromDecoratedDefinitionToDecoratingDefinitio
$this->assertEquals(array('bar' => array('attr' => 'baz'), 'foobar' => array('attr' => 'bar')), $container->getDefinition('baz')->getTags());
}

/**
* @group legacy
*/
public function testProcessMergesAutowiringTypesInDecoratingDefinitionAndRemoveThemFromDecoratedDefinition()
{
$container = new ContainerBuilder();

$container
->register('parent')
->addAutowiringType('Bar')
;

$container
->register('child')
->setDecoratedService('parent')
->addAutowiringType('Foo')
;

$this->process($container);

$this->assertEquals(array('Bar', 'Foo'), $container->getDefinition('child')->getAutowiringTypes());
$this->assertEmpty($container->getDefinition('child.inner')->getAutowiringTypes());
}

protected function process(ContainerBuilder $container)
{
$repeatedPass = new DecoratorServicePass();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,32 +324,6 @@ public function testDecoratedServiceCanOverwriteDeprecatedParentStatus()
$this->assertFalse($container->getDefinition('decorated_deprecated_parent')->isDeprecated());
}

/**
* @group legacy
*/
public function testProcessMergeAutowiringTypes()
{
$container = new ContainerBuilder();

$container
->register('parent')
->addAutowiringType('Foo')
;

$container
->setDefinition('child', new ChildDefinition('parent'))
->addAutowiringType('Bar')
;

$this->process($container);

$childDef = $container->getDefinition('child');
$this->assertEquals(array('Foo', 'Bar'), $childDef->getAutowiringTypes());

$parentDef = $container->getDefinition('parent');
$this->assertSame(array('Foo'), $parentDef->getAutowiringTypes());
}

public function testProcessResolvesAliases()
{
$container = new ContainerBuilder();
Expand Down
Loading