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
This commit is contained in:
commit
88cddb8a31
@ -231,13 +231,6 @@ class JsonDescriptor extends Descriptor
|
||||
'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);
|
||||
}
|
||||
|
@ -191,13 +191,6 @@ class MarkdownDescriptor extends Descriptor
|
||||
."\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');
|
||||
}
|
||||
|
@ -309,11 +309,6 @@ class TextDescriptor extends Descriptor
|
||||
$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() : '-');
|
||||
}
|
||||
|
@ -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`
|
||||
* removed support for generating a dumped `Container` without populating the method map
|
||||
|
@ -27,7 +27,6 @@ use Symfony\Component\DependencyInjection\TypedReference;
|
||||
*/
|
||||
class AutowirePass extends AbstractRecursivePass
|
||||
{
|
||||
private $definedTypes = array();
|
||||
private $types;
|
||||
private $ambiguousServiceTypes = array();
|
||||
private $autowired = array();
|
||||
@ -62,7 +61,6 @@ class AutowirePass extends AbstractRecursivePass
|
||||
try {
|
||||
parent::process($container);
|
||||
} finally {
|
||||
$this->definedTypes = array();
|
||||
$this->types = null;
|
||||
$this->ambiguousServiceTypes = array();
|
||||
$this->autowired = array();
|
||||
@ -324,10 +322,6 @@ class AutowirePass extends AbstractRecursivePass
|
||||
$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);
|
||||
|
||||
@ -370,12 +364,6 @@ class AutowirePass extends AbstractRecursivePass
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($definition->getAutowiringTypes(false) as $type) {
|
||||
$this->definedTypes[$type] = true;
|
||||
$this->types[$type] = $id;
|
||||
unset($this->ambiguousServiceTypes[$type]);
|
||||
}
|
||||
|
||||
if ($definition->isDeprecated() || !$reflectionClass = $this->container->getReflectionClass($definition->getClass(), true)) {
|
||||
return;
|
||||
}
|
||||
@ -397,10 +385,6 @@ class AutowirePass extends AbstractRecursivePass
|
||||
*/
|
||||
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;
|
||||
|
@ -53,15 +53,9 @@ class DecoratorServicePass implements CompilerPassInterface
|
||||
} 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);
|
||||
}
|
||||
|
||||
|
@ -89,9 +89,6 @@ class ResolveDefinitionTemplatesPass extends AbstractRecursivePass
|
||||
$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%'));
|
||||
}
|
||||
@ -162,11 +159,6 @@ class ResolveDefinitionTemplatesPass extends AbstractRecursivePass
|
||||
$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());
|
||||
|
@ -39,7 +39,6 @@ class Definition
|
||||
private $lazy = false;
|
||||
private $decoratedService;
|
||||
private $autowired = false;
|
||||
private $autowiringTypes = array();
|
||||
private $changes = array();
|
||||
|
||||
protected $arguments = array();
|
||||
@ -745,28 +744,6 @@ class Definition
|
||||
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?
|
||||
*
|
||||
@ -792,72 +769,4 @@ class Definition
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
@ -198,13 +198,6 @@ class XmlDumper extends Dumper
|
||||
$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');
|
||||
}
|
||||
|
@ -109,14 +109,6 @@ class YamlDumper extends Dumper
|
||||
$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";
|
||||
}
|
||||
|
@ -341,10 +341,6 @@ class XmlFileLoader extends FileLoader
|
||||
$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;
|
||||
|
@ -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',
|
||||
);
|
||||
|
||||
@ -500,24 +499,6 @@ class YamlFileLoader extends FileLoader
|
||||
$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']);
|
||||
|
@ -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" />
|
||||
|
@ -144,30 +144,6 @@ class DecoratorServicePassTest extends TestCase
|
||||
$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();
|
||||
|
@ -324,32 +324,6 @@ class ResolveDefinitionTemplatesPassTest extends TestCase
|
||||
$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();
|
||||
|
@ -364,22 +364,6 @@ class DefinitionTest extends TestCase
|
||||
$this->assertSame(array(), $def->getChanges());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testTypes()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
|
||||
$this->assertEquals(array(), $def->getAutowiringTypes());
|
||||
$this->assertSame($def, $def->setAutowiringTypes(array('Foo')));
|
||||
$this->assertEquals(array('Foo'), $def->getAutowiringTypes());
|
||||
$this->assertSame($def, $def->addAutowiringType('Bar'));
|
||||
$this->assertTrue($def->hasAutowiringType('Bar'));
|
||||
$this->assertSame($def, $def->removeAutowiringType('Foo'));
|
||||
$this->assertEquals(array('Bar'), $def->getAutowiringTypes());
|
||||
}
|
||||
|
||||
public function testShouldAutoconfigure()
|
||||
{
|
||||
$def = new Definition('stdClass');
|
||||
|
@ -1,9 +0,0 @@
|
||||
<?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">
|
||||
<autowiring-type>Bar</autowiring-type>
|
||||
<autowiring-type>Baz</autowiring-type>
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
@ -1,5 +0,0 @@
|
||||
services:
|
||||
foo_service:
|
||||
class: FooClass
|
||||
# types is not an array
|
||||
autowiring_types: 1
|
@ -1,5 +0,0 @@
|
||||
services:
|
||||
foo_service:
|
||||
class: FooClass
|
||||
# autowiring_types is not a string
|
||||
autowiring_types: [ 1 ]
|
@ -1,8 +0,0 @@
|
||||
services:
|
||||
foo_service:
|
||||
class: FooClass
|
||||
autowiring_types: [ Foo, Bar ]
|
||||
|
||||
baz_service:
|
||||
class: Baz
|
||||
autowiring_types: Foo
|
@ -563,18 +563,6 @@ class XmlFileLoaderTest extends TestCase
|
||||
$this->assertSame('configureBar', $barConfigurator[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testType()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
|
||||
$loader->load('services22.xml');
|
||||
|
||||
$this->assertEquals(array('Bar', 'Baz'), $container->getDefinition('foo')->getAutowiringTypes());
|
||||
}
|
||||
|
||||
public function testAutowire()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
@ -307,37 +307,6 @@ class YamlFileLoaderTest extends TestCase
|
||||
$loader->load('tag_name_no_string.yml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function testTypesNotArray()
|
||||
{
|
||||
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
|
||||
$loader->load('bad_types1.yml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
*/
|
||||
public function testTypeNotString()
|
||||
{
|
||||
$loader = new YamlFileLoader(new ContainerBuilder(), new FileLocator(self::$fixturesPath.'/yaml'));
|
||||
$loader->load('bad_types2.yml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testTypes()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
|
||||
$loader->load('services22.yml');
|
||||
|
||||
$this->assertEquals(array('Foo', 'Bar'), $container->getDefinition('foo_service')->getAutowiringTypes());
|
||||
$this->assertEquals(array('Foo'), $container->getDefinition('baz_service')->getAutowiringTypes());
|
||||
}
|
||||
|
||||
public function testParsesIteratorArgument()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
Reference in New Issue
Block a user