8000 [DI] deprecates tag !tagged in favor of !tagged_iterator by jschaedl · Pull Request #31321 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] deprecates tag !tagged in favor of !tagged_iterator #31321

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 1 commit into from
Jun 9, 2019
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
21 changes: 21 additions & 0 deletions UPGRADE-4.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
```

MonologBridge
--------------
Expand Down
21 changes: 21 additions & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Copy link
Member

Choose a reason for hiding this comment

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

this means FWB now needs DI v4.4
this is why tests fail: the composer.json needs an update

</service>

<service id="messenger.transport.amqp.factory" class="Symfony\Component\Messenger\Transport\AmqpExt\AmqpTransportFactory">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand All @@ -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">
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
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 @@ -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
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ services:
tagged_iterator:
class: Bar
arguments:
- !tagged foo
- !tagged_iterator foo
public: true
Psr\Container\ContainerInterface:
alias: service_container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }]
Expand Down
0