feature #31321 [DI] deprecates tag !tagged in favor of !tagged_iterator (jschaedl)
This PR was squashed before being merged into the 4.4 branch (closes #31321).
Discussion
----------
[DI] deprecates tag !tagged in favor of !tagged_iterator
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | yes
| Tests pass? | yes
| Fixed tickets | #31289
| License | MIT
| Doc PR | tbd.
### Todo
- [x] fix tests
Commits
-------
ab8fb1868f
[DI] deprecates tag !tagged in favor of !tagged_iterator
This commit is contained in:
commit
7f39f36379
@ -24,6 +24,27 @@ DependencyInjection
|
|||||||
my_service:
|
my_service:
|
||||||
factory: ['@factory_service', method]
|
factory: ['@factory_service', method]
|
||||||
```
|
```
|
||||||
|
* Deprecated `tagged` in favor of `tagged_iterator`
|
||||||
|
|
||||||
|
Before:
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
App\Handler:
|
||||||
|
tags: ['app.handler']
|
||||||
|
|
||||||
|
App\HandlerCollection:
|
||||||
|
arguments: [!tagged app.handler]
|
||||||
|
```
|
||||||
|
|
||||||
|
After:
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
App\Handler:
|
||||||
|
tags: ['app.handler']
|
||||||
|
|
||||||
|
App\HandlerCollection:
|
||||||
|
arguments: [!tagged_iterator app.handler]
|
||||||
|
```
|
||||||
|
|
||||||
HttpClient
|
HttpClient
|
||||||
----------
|
----------
|
||||||
|
@ -84,6 +84,27 @@ DependencyInjection
|
|||||||
my_service:
|
my_service:
|
||||||
factory: ['@factory_service', method]
|
factory: ['@factory_service', method]
|
||||||
```
|
```
|
||||||
|
* Removed `tagged` in favor of `tagged_iterator`
|
||||||
|
|
||||||
|
Before:
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
App\Handler:
|
||||||
|
tags: ['app.handler']
|
||||||
|
|
||||||
|
App\HandlerCollection:
|
||||||
|
arguments: [!tagged app.handler]
|
||||||
|
```
|
||||||
|
|
||||||
|
After:
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
App\Handler:
|
||||||
|
tags: ['app.handler']
|
||||||
|
|
||||||
|
App\HandlerCollection:
|
||||||
|
arguments: [!tagged_iterator app.handler]
|
||||||
|
```
|
||||||
|
|
||||||
DoctrineBridge
|
DoctrineBridge
|
||||||
--------------
|
--------------
|
||||||
|
@ -61,7 +61,7 @@
|
|||||||
|
|
||||||
<!-- transports -->
|
<!-- transports -->
|
||||||
<service id="messenger.transport_factory" class="Symfony\Component\Messenger\Transport\TransportFactory">
|
<service id="messenger.transport_factory" class="Symfony\Component\Messenger\Transport\TransportFactory">
|
||||||
<argument type="tagged" tag="messenger.transport_factory" />
|
<argument type="tagged_iterator" tag="messenger.transport_factory" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="messenger.transport.amqp.factory" class="Symfony\Component\Messenger\Transport\AmqpExt\AmqpTransportFactory">
|
<service id="messenger.transport.amqp.factory" class="Symfony\Component\Messenger\Transport\AmqpExt\AmqpTransportFactory">
|
||||||
|
@ -70,13 +70,13 @@
|
|||||||
<service id="Symfony\Component\HttpFoundation\UrlHelper" alias="url_helper" />
|
<service id="Symfony\Component\HttpFoundation\UrlHelper" alias="url_helper" />
|
||||||
|
|
||||||
<service id="cache_warmer" class="Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate" public="true">
|
<service id="cache_warmer" class="Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate" public="true">
|
||||||
<argument type="tagged" tag="kernel.cache_warmer" />
|
<argument type="tagged_iterator" tag="kernel.cache_warmer" />
|
||||||
<argument>%kernel.debug%</argument>
|
<argument>%kernel.debug%</argument>
|
||||||
<argument>%kernel.cache_dir%/%kernel.container_class%Deprecations.log</argument>
|
<argument>%kernel.cache_dir%/%kernel.container_class%Deprecations.log</argument>
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="cache_clearer" class="Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer" public="true">
|
<service id="cache_clearer" class="Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer" public="true">
|
||||||
<argument type="tagged" tag="kernel.cache_clearer" />
|
<argument type="tagged_iterator" tag="kernel.cache_clearer" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="kernel" synthetic="true" public="true" />
|
<service id="kernel" synthetic="true" public="true" />
|
||||||
@ -99,7 +99,7 @@
|
|||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="config_cache_factory" class="Symfony\Component\Config\ResourceCheckerConfigCacheFactory">
|
<service id="config_cache_factory" class="Symfony\Component\Config\ResourceCheckerConfigCacheFactory">
|
||||||
<argument type="tagged" tag="config_cache.resource_checker" />
|
<argument type="tagged_iterator" tag="config_cache.resource_checker" />
|
||||||
</service>
|
</service>
|
||||||
|
|
||||||
<service id="dependency_injection.config.container_parameters_resource_checker" class="Symfony\Component\DependencyInjection\Config\ContainerParametersResourceChecker">
|
<service id="dependency_injection.config.container_parameters_resource_checker" class="Symfony\Component\DependencyInjection\Config\ContainerParametersResourceChecker">
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
"ext-xml": "*",
|
"ext-xml": "*",
|
||||||
"symfony/cache": "^4.3|^5.0",
|
"symfony/cache": "^4.3|^5.0",
|
||||||
"symfony/config": "^4.2|^5.0",
|
"symfony/config": "^4.2|^5.0",
|
||||||
"symfony/dependency-injection": "^4.3|^5.0",
|
"symfony/dependency-injection": "^4.4|^5.0",
|
||||||
"symfony/http-foundation": "^4.3|^5.0",
|
"symfony/http-foundation": "^4.3|^5.0",
|
||||||
"symfony/http-kernel": "^4.3|^5.0",
|
"symfony/http-kernel": "^4.3|^5.0",
|
||||||
"symfony/polyfill-mbstring": "~1.0",
|
"symfony/polyfill-mbstring": "~1.0",
|
||||||
|
@ -5,6 +5,7 @@ CHANGELOG
|
|||||||
-----
|
-----
|
||||||
|
|
||||||
* deprecated support for short factories and short configurators in Yaml
|
* deprecated support for short factories and short configurators in Yaml
|
||||||
|
* deprecated `tagged` in favor of `tagged_iterator`
|
||||||
|
|
||||||
4.3.0
|
4.3.0
|
||||||
-----
|
-----
|
||||||
|
@ -287,7 +287,7 @@ class XmlDumper extends Dumper
|
|||||||
$element->setAttribute('type', 'collection');
|
$element->setAttribute('type', 'collection');
|
||||||
$this->convertParameters($value, $type, $element, 'key');
|
$this->convertParameters($value, $type, $element, 'key');
|
||||||
} elseif ($value instanceof TaggedIteratorArgument || ($value instanceof ServiceLocatorArgument && $tag = $value->getTaggedIteratorArgument())) {
|
} elseif ($value instanceof TaggedIteratorArgument || ($value instanceof ServiceLocatorArgument && $tag = $value->getTaggedIteratorArgument())) {
|
||||||
$element->setAttribute('type', $value instanceof TaggedIteratorArgument ? 'tagged' : 'tagged_locator');
|
$element->setAttribute('type', $value instanceof TaggedIteratorArgument ? 'tagged_iterator' : 'tagged_locator');
|
||||||
$element->setAttribute('tag', $tag->getTag());
|
$element->setAttribute('tag', $tag->getTag());
|
||||||
|
|
||||||
if (null !== $tag->getIndexAttribute()) {
|
if (null !== $tag->getIndexAttribute()) {
|
||||||
|
@ -248,7 +248,7 @@ class YamlDumper extends Dumper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TaggedValue($value instanceof TaggedIteratorArgument ? 'tagged' : 'tagged_locator', $content);
|
return new TaggedValue($value instanceof TaggedIteratorArgument ? 'tagged_iterator' : 'tagged_locator', $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($value instanceof IteratorArgument) {
|
if ($value instanceof IteratorArgument) {
|
||||||
|
@ -115,8 +115,20 @@ function iterator(array $values): IteratorArgument
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a lazy iterator by tag name.
|
* Creates a lazy iterator by tag name.
|
||||||
|
*
|
||||||
|
* @deprecated since Symfony 4.4, to be removed in 5.0, use "tagged_iterator" instead.
|
||||||
*/
|
*/
|
||||||
function tagged(string $tag, string $indexAttribute = null, string $defaultIndexMethod = null): TaggedIteratorArgument
|
function tagged(string $tag, string $indexAttribute = null, string $defaultIndexMethod = null): TaggedIteratorArgument
|
||||||
|
{
|
||||||
|
@trigger_error(__NAMESPACE__.'\tagged() is deprecated since Symfony 4.4 and will be removed in 5.0, use '.__NAMESPACE__.'\tagged_iterator() instead.', E_USER_DEPRECATED);
|
||||||
|
|
||||||
|
return new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a lazy iterator by tag name.
|
||||||
|
*/
|
||||||
|
function tagged_iterator(string $tag, string $indexAttribute = null, string $defaultIndexMethod = null): TaggedIteratorArgument
|
||||||
{
|
{
|
||||||
return new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod);
|
return new TaggedIteratorArgument($tag, $indexAttribute, $defaultIndexMethod);
|
||||||
}
|
}
|
||||||
|
@ -545,6 +545,9 @@ class XmlFileLoader extends FileLoader
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'tagged':
|
case 'tagged':
|
||||||
|
@trigger_error(sprintf('Type "%s" of tag <%s> in "%s" is deprecated since Symfony 4.4 and will be removed in 5.0, use "tagged_iterator" instead.', $arg->getAttribute('type'), $name, $file), E_USER_DEPRECATED);
|
||||||
|
// no break
|
||||||
|
case 'tagged_iterator':
|
||||||
case 'tagged_locator':
|
case 'tagged_locator':
|
||||||
$type = $arg->getAttribute('type');
|
$type = $arg->getAttribute('type');
|
||||||
$forLocator = 'tagged_locator' === $type;
|
$forLocator = 'tagged_locator' === $type;
|
||||||
|
@ -725,7 +725,11 @@ class YamlFileLoader extends FileLoader
|
|||||||
throw new InvalidArgumentException(sprintf('"!service_locator" tag only accepts maps of "@service" references in "%s".', $file));
|
throw new InvalidArgumentException(sprintf('"!service_locator" tag only accepts maps of "@service" references in "%s".', $file));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (\in_array($value->getTag(), ['tagged', 'tagged_locator'], true)) {
|
if (\in_array($value->getTag(), ['tagged', 'tagged_iterator', 'tagged_locator'], true)) {
|
||||||
|
if ('tagged' === $value->getTag()) {
|
||||||
|
@trigger_error('"!tagged" is deprecated since Symfony 4.4 and will be removed in 5.0, use "!tagged_iterator" instead.', E_USER_DEPRECATED);
|
||||||
|
}
|
||||||
|
|
||||||
$forLocator = 'tagged_locator' === $value->getTag();
|
$forLocator = 'tagged_locator' === $value->getTag();
|
||||||
|
|
||||||
if (\is_string($argument) && $argument) {
|
if (\is_string($argument) && $argument) {
|
||||||
|
@ -264,7 +264,9 @@
|
|||||||
<xsd:enumeration value="constant" />
|
<xsd:enumeration value="constant" />
|
||||||
<xsd:enumeration value="iterator" />
|
<xsd:enumeration value="iterator" />
|
||||||
<xsd:enumeration value="service_locator" />
|
<xsd:enumeration value="service_locator" />
|
||||||
|
<!-- "tagged" is deprecated since Symfony 4.4 and will be removed in 5.0, use "tagged_iterator" instead. -->
|
||||||
<xsd:enumeration value="tagged" />
|
<xsd:enumeration value="tagged" />
|
||||||
|
<xsd:enumeration value="tagged_iterator" />
|
||||||
<xsd:enumeration value="tagged_locator" />
|
<xsd:enumeration value="tagged_locator" />
|
||||||
</xsd:restriction>
|
</xsd:restriction>
|
||||||
</xsd:simpleType>
|
</xsd:simpleType>
|
||||||
|
@ -7,7 +7,7 @@ services:
|
|||||||
listener_aggregator:
|
listener_aggregator:
|
||||||
class: Bar\FooClass
|
class: Bar\FooClass
|
||||||
public: true
|
public: true
|
||||||
arguments: [!tagged listener]
|
arguments: [!tagged_iterator listener]
|
||||||
.2_stdClass~%s:
|
.2_stdClass~%s:
|
||||||
class: stdClass
|
class: stdClass
|
||||||
public: false
|
public: false
|
||||||
|
@ -15,7 +15,7 @@ return function (ContainerConfigurator $c) {
|
|||||||
->decorate('decorated', 'decorator42')
|
->decorate('decorated', 'decorator42')
|
||||||
->args([ref('decorator42')]);
|
->args([ref('decorator42')]);
|
||||||
|
|
||||||
$s->set('listener_aggregator', FooClass::class)->public()->args([tagged('listener')]);
|
$s->set('listener_aggregator', FooClass::class)->public()->args([tagged_iterator('listener')]);
|
||||||
|
|
||||||
$s->set(null, stdClass::class)->tag('listener');
|
$s->set(null, stdClass::class)->tag('listener');
|
||||||
};
|
};
|
||||||
|
@ -128,7 +128,7 @@ return function (ContainerConfigurator $c) {
|
|||||||
|
|
||||||
$s->set('tagged_iterator', 'Bar')
|
$s->set('tagged_iterator', 'Bar')
|
||||||
->public()
|
->public()
|
||||||
->args([tagged('foo')]);
|
->args([tagged_iterator('foo')]);
|
||||||
|
|
||||||
$s->set('runtime_error', 'stdClass')
|
$s->set('runtime_error', 'stdClass')
|
||||||
->args([new Reference('errored_definition', ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE)])
|
->args([new Reference('errored_definition', ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE)])
|
||||||
|
@ -142,7 +142,7 @@
|
|||||||
<tag name="foo"/>
|
<tag name="foo"/>
|
||||||
</service>
|
</service>
|
||||||
<service id="tagged_iterator" class="Bar" public="true">
|
<service id="tagged_iterator" class="Bar" public="true">
|
||||||
<argument type="tagged" tag="foo"/>
|
<argument type="tagged_iterator" tag="foo"/>
|
||||||
</service>
|
</service>
|
||||||
<service id="runtime_error" class="stdClass" public="true">
|
<service id="runtime_error" class="stdClass" public="true">
|
||||||
<argument type="service" id="errored_definition"/>
|
<argument type="service" id="errored_definition"/>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<tag name="foo_tag"/>
|
<tag name="foo_tag"/>
|
||||||
</service>
|
</service>
|
||||||
<service id="foo_tagged_iterator" class="Bar" public="true">
|
<service id="foo_tagged_iterator" class="Bar" public="true">
|
||||||
<argument type="tagged" tag="foo_tag" index-by="barfoo" default-index-method="foobar"/>
|
<argument type="tagged_iterator" tag="foo_tag" index-by="barfoo" default-index-method="foobar"/>
|
||||||
</service>
|
</service>
|
||||||
<service id="foo_tagged_locator" class="Bar" public="true">
|
<service id="foo_tagged_locator" class="Bar" public="true">
|
||||||
<argument type="tagged_locator" tag="foo_tag" index-by="barfoo" default-index-method="foobar"/>
|
<argument type="tagged_locator" tag="foo_tag" index-by="barfoo" default-index-method="foobar"/>
|
||||||
|
@ -8,7 +8,7 @@ services:
|
|||||||
public: true
|
public: true
|
||||||
|
|
||||||
Symfony\Component\DependencyInjection\Tests\Fixtures\BarFactory:
|
Symfony\Component\DependencyInjection\Tests\Fixtures\BarFactory:
|
||||||
arguments: [!tagged 'bar']
|
arguments: [!tagged_iterator 'bar']
|
||||||
|
|
||||||
Symfony\Component\DependencyInjection\Tests\Fixtures\BarInterface:
|
Symfony\Component\DependencyInjection\Tests\Fixtures\BarInterface:
|
||||||
factory: ['@Symfony\Component\DependencyInjection\Tests\Fixtures\BarFactory', 'getDefaultBar']
|
factory: ['@Symfony\Component\DependencyInjection\Tests\Fixtures\BarFactory', 'getDefaultBar']
|
||||||
|
@ -157,7 +157,7 @@ services:
|
|||||||
tagged_iterator:
|
tagged_iterator:
|
||||||
class: Bar
|
class: Bar
|
||||||
arguments:
|
arguments:
|
||||||
- !tagged foo
|
- !tagged_iterator foo
|
||||||
public: true
|
public: true
|
||||||
Psr\Container\ContainerInterface:
|
Psr\Container\ContainerInterface:
|
||||||
alias: service_container
|
alias: service_container
|
||||||
|
@ -10,7 +10,7 @@ services:
|
|||||||
- { name: foo }
|
- { name: foo }
|
||||||
foo_service_tagged_iterator:
|
foo_service_tagged_iterator:
|
||||||
class: Bar
|
class: Bar
|
||||||
arguments: [!tagged { tag: foo, index_by: barfoo, default_index_method: foobar }]
|
arguments: [!tagged_iterator { tag: foo, index_by: barfoo, default_index_method: foobar }]
|
||||||
foo_service_tagged_locator:
|
foo_service_tagged_locator:
|
||||||
class: Bar
|
class: Bar
|
||||||
arguments: [!tagged_locator { tag: foo, index_by: barfoo, default_index_method: foobar }]
|
arguments: [!tagged_locator { tag: foo, index_by: barfoo, default_index_method: foobar }]
|
||||||
|
Reference in New Issue
Block a user