Skip to content
Permalink
Browse files

feature #31321 [DI] deprecates tag !tagged in favor of !tagged_iterat…

…or (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
-------

ab8fb18 [DI] deprecates tag !tagged in favor of !tagged_iterator
  • Loading branch information...
nicolas-grekas committed Jun 9, 2019
2 parents cdaa4d6 + ab8fb18 commit 7f39f36379732fbb5e3c054d52ba5fd967838628
Showing with 80 additions and 16 deletions.
  1. +21 −0 UPGRADE-4.4.md
  2. +21 −0 UPGRADE-5.0.md
  3. +1 −1 src/Symfony/Bundle/FrameworkBundle/Resources/config/messenger.xml
  4. +3 −3 src/Symfony/Bundle/FrameworkBundle/Resources/config/services.xml
  5. +1 −1 src/Symfony/Bundle/FrameworkBundle/composer.json
  6. +1 −0 src/Symfony/Component/DependencyInjection/CHANGELOG.md
  7. +1 −1 src/Symfony/Component/DependencyInjection/Dumper/XmlDumper.php
  8. +1 −1 src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php
  9. +12 −0 src/Symfony/Component/DependencyInjection/Loader/Configurator/ContainerConfigurator.php
  10. +3 −0 src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php
  11. +5 −1 src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php
  12. +2 −0 src/Symfony/Component/DependencyInjection/Loader/schema/dic/services/services-1.0.xsd
  13. +1 −1 src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/anonymous.expected.yml
  14. +1 −1 src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/anonymous.php
  15. +1 −1 src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/services9.php
  16. +1 −1 src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services9.xml
  17. +1 −1 src/Symfony/Component/DependencyInjection/Tests/Fixtures/xml/services_with_tagged_arguments.xml
  18. +1 −1 src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/service_instanceof_factory.yml
  19. +1 −1 src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml
  20. +1 −1 src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services_with_tagged_argument.yml
@@ -24,6 +24,27 @@ DependencyInjection
my_service:
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
----------
@@ -84,6 +84,27 @@ DependencyInjection
my_service:
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
--------------
@@ -61,7 +61,7 @@

<!-- transports -->
<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 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="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.cache_dir%/%kernel.container_class%Deprecations.log</argument>
</service>

<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 id="kernel" synthetic="true" public="true" />
@@ -99,7 +99,7 @@
</service>

<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 id="dependency_injection.config.container_parameters_resource_checker" class="Symfony\Component\DependencyInjection\Config\ContainerParametersResourceChecker">
@@ -20,7 +20,7 @@
"ext-xml": "*",
"symfony/cache": "^4.3|^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-kernel": "^4.3|^5.0",
"symfony/polyfill-mbstring": "~1.0",
@@ -5,6 +5,7 @@ CHANGELOG
-----

* deprecated support for short factories and short configurators in Yaml
* deprecated `tagged` in favor of `tagged_iterator`

4.3.0
-----
@@ -287,7 +287,7 @@ private function convertParameters(array $parameters, $type, \DOMElement $parent
$element->setAttribute('type', 'collection');
$this->convertParameters($value, $type, $element, 'key');
} 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());
if (null !== $tag->getIndexAttribute()) {
@@ -248,7 +248,7 @@ private function dumpValue($value)
}
}
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) {
@@ -115,8 +115,20 @@ function iterator(array $values): IteratorArgument
/**
* 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
{
@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);
}
@@ -545,6 +545,9 @@ private function getArgumentsAsPhp(\DOMElement $node, $name, $file, $lowercase =
}
break;
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':
$type = $arg->getAttribute('type');
$forLocator = 'tagged_locator' === $type;
@@ -725,7 +725,11 @@ private function resolveServices($value, $file, $isParameter = false)
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();
if (\is_string($argument) && $argument) {
@@ -264,7 +264,9 @@
<xsd:enumeration value="constant" />
<xsd:enumeration value="iterator" />
<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_iterator" />
<xsd:enumeration value="tagged_locator" />
</xsd:restriction>
</xsd:simpleType>
@@ -7,7 +7,7 @@ services:
listener_aggregator:
class: Bar\FooClass
public: true
arguments: [!tagged listener]
arguments: [!tagged_iterator listener]
.2_stdClass~%s:
class: stdClass
public: false
@@ -15,7 +15,7 @@
->decorate('decorated', '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');
};
@@ -128,7 +128,7 @@
$s->set('tagged_iterator', 'Bar')
->public()
->args([tagged('foo')]);
->args([tagged_iterator('foo')]);
$s->set('runtime_error', 'stdClass')
->args([new Reference('errored_definition', ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE)])
@@ -142,7 +142,7 @@
<tag name="foo"/>
</service>
<service id="tagged_iterator" class="Bar" public="true">
<argument type="tagged" tag="foo"/>
<argument type="tagged_iterator" tag="foo"/>
</service>
<service id="runtime_error" class="stdClass" public="true">
<argument type="service" id="errored_definition"/>
@@ -6,7 +6,7 @@
<tag name="foo_tag"/>
</service>
<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 id="foo_tagged_locator" class="Bar" public="true">
<argument type="tagged_locator" tag="foo_tag" index-by="barfoo" default-index-method="foobar"/>
@@ -8,7 +8,7 @@ services:
public: true

Symfony\Component\DependencyInjection\Tests\Fixtures\BarFactory:
arguments: [!tagged 'bar']
arguments: [!tagged_iterator 'bar']

Symfony\Component\DependencyInjection\Tests\Fixtures\BarInterface:
factory: ['@Symfony\Component\DependencyInjection\Tests\Fixtures\BarFactory', 'getDefaultBar']
@@ -157,7 +157,7 @@ services:
tagged_iterator:
class: Bar
arguments:
- !tagged foo
- !tagged_iterator foo
public: true
Psr\Container\ContainerInterface:
alias: service_container
@@ -10,7 +10,7 @@ services:
- { name: foo }
foo_service_tagged_iterator:
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:
class: Bar
arguments: [!tagged_locator { tag: foo, index_by: barfoo, default_index_method: foobar }]

0 comments on commit 7f39f36

Please sign in to comment.
You can’t perform that action at this time.