Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2bc467f

Browse files
committed
[DependencyInjection] Document FQCN aliases
1 parent01b10f1 commit2bc467f

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

‎components/dependency_injection/autowiring.rst‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ and a Twitter client using it:
307307
308308
services:
309309
rot13_transformer:
310-
class:Acme\Rot13Transformer
311-
autowiring_types:Acme\TransformerInterface
310+
class:Acme\Rot13Transformer
311+
312+
Acme\TransformerInterface:@rot13_transformer
312313
313314
twitter_client:
314315
class:Acme\TwitterClient
@@ -330,9 +331,8 @@ and a Twitter client using it:
330331
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
331332
332333
<services>
333-
<serviceid="rot13_transformer"class="Acme\Rot13Transformer">
334-
<autowiring-type>Acme\TransformerInterface</autowiring-type>
335-
</service>
334+
<serviceid="rot13_transformer"class="Acme\Rot13Transformer" />
335+
<serviceid="Acme\TransformerInterface"alias="rot13_transformer" />
336336
337337
<serviceid="twitter_client"class="Acme\TwitterClient"autowire="true" />
338338
@@ -356,9 +356,8 @@ and a Twitter client using it:
356356
use Symfony\Component\DependencyInjection\Definition;
357357
358358
// ...
359-
$rot13Definition = new Definition(Rot13Transformer::class);
360-
$rot13Definition->setAutowiringTypes(array(TransformerInterface::class));
361-
$container->setDefinition('rot13_transformer', $rot13Definition);
359+
$container->register('rot13_transformer', Rot13Transformer::class);
360+
$container->setAlias(TransformerInterface::class, 'rot13_transformer')
362361
363362
$clientDefinition = new Definition(TwitterClient::class);
364363
$clientDefinition->setAutowired(true);
@@ -382,10 +381,14 @@ to use which leads to errors like this:
382381
[Symfony\Component\DependencyInjection\Exception\RuntimeException]
383382
Unable to autowire argument of type "Acme\TransformerInterface" for the service "twitter_client".
384383
385-
Fortunately, the ``autowiring_types`` key is here to specify which implementation
386-
to use by default. This key can take a list of types if necessary.
384+
Fortunately, the FQCN alias is here to specify which implementation
385+
to use by default.
386+
387+
..versionadded::3.2
388+
Using FQCN aliases to fix autowiring ambiguities is allowed since Symfony
389+
3.3. Prior to version 3.3, you needed to use the ``autowiring_types`` key.
387390

388-
Thanks to thissetting, the ``rot13_transformer`` service is automatically injected
391+
Thanks to thisalias, the ``rot13_transformer`` service is automatically injected
389392
as an argument of the ``uppercase_transformer`` and ``twitter_client`` services. For
390393
the ``uppercase_twitter_client``, a standard service definition is used to
391394
inject the specific ``uppercase_transformer`` service.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp