Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DependencyInjection] adjust Autowire attribute docs #16779

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
May 4, 2022
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
6 changes: 3 additions & 3 deletions controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ command:

.. tip::

If you need control over the *exact* value of an argument, you can use the
``#[Autowire]`` attribute::
If you need control over the *exact* value of an argument, or require a parameter,
you can use the ``#[Autowire]`` attribute::

// ...
use Psr\Log\LoggerInterface;
Expand All @@ -239,7 +239,7 @@ command:
int $max,

// inject a specific logger service
#[Autowire('@monolog.logger.request')]
#[Autowire(service: 'monolog.logger.request')]
LoggerInterface $logger,

// or inject parameter values
Expand Down
10 changes: 5 additions & 5 deletions service_container/autowiring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,8 @@ To fix this, you can :ref:`manually wire the problematic argument <services-manu
in the service configuration. You wire up only the difficult arguments,
Symfony takes care of the rest.

You can also use the ``#[Autowire]`` parameter attribute to configure the
problematic arguments:
You can also use the ``#[Autowire]`` parameter attribute to instruct the autowiring
logic about those arguments:

// src/Service/MessageGenerator.php
namespace App\Service;
Expand All @@ -557,7 +557,7 @@ problematic arguments:
class MessageGenerator
{
public function __construct(
#[Autowire('@monolog.logger.request')] LoggerInterface $logger
#[Autowire(service: 'monolog.logger.request')] LoggerInterface $logger
) {
// ...
}
Expand Down Expand Up @@ -586,8 +586,8 @@ and even :doc:`complex expressions </service_container/expression_language>`::
#[Autowire('%kernel.debug%')]
bool $debugMode,

// and @=... for expressions
#[Autowire("@=service("App\\Mail\\MailerConfiguration").getMailerMethod()")]
// and expressions
#[Autowire(expression: "service("App\\Mail\\MailerConfiguration").getMailerMethod()")]
string $mailerMethod
) {
}
Expand Down