Skip to content

Commit a1d6eed

Browse files
committed
feature #21394 [FrameworkBundle] Simplify usage of the #[Target] attribute (javiereguiluz)
This PR was merged into the 7.4 branch. Discussion ---------- [FrameworkBundle] Simplify usage of the `#[Target]` attribute This continues #21382 and fixes #21134. Commits ------- cb29685 [FrameworkBundle] Simplify usage of the Target attribute
2 parents 84ca32e + cb29685 commit a1d6eed

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

lock.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ For example, to inject the ``invoice`` package defined earlier::
319319

320320
When :ref:`dealing with multiple implementations of the same type <autowiring-multiple-implementations-same-type>`
321321
the ``#[Target]`` attribute helps you select which one to inject. Symfony creates
322-
a target called "asset package name" + ``.lock.factory`` suffix.
322+
a target with the same name as the lock.
323323

324324
For example, to select the ``invoice`` lock defined earlier::
325325

@@ -329,8 +329,13 @@ For example, to select the ``invoice`` lock defined earlier::
329329
class SomeService
330330
{
331331
public function __construct(
332-
#[Target('invoice.lock.factory')] private LockFactory $lockFactory
332+
#[Target('invoice')] private LockFactory $lockFactory
333333
): void {
334334
// ...
335335
}
336336
}
337+
338+
.. versionadded:: 7.4
339+
340+
Before Symfony 7.4, the target name had to include the ``.lock.factory``
341+
suffix (e.g. ``#[Target('invoice.lock.factory')]``).

rate_limiter.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ argument named ``$anonymousApiLimiter``::
262262

263263
When :ref:`dealing with multiple implementations of the same type <autowiring-multiple-implementations-same-type>`
264264
the ``#[Target]`` attribute helps you select which one to inject. Symfony creates
265-
a target called "rate limiter name" + ``.limiter`` suffix.
265+
a target with the same name as the rate limiter.
266266

267267
For example, to select the ``anonymous_api`` limiter defined earlier, use
268268
``anonymous_api.limiter`` as the target::
@@ -273,7 +273,7 @@ For example, to select the ``anonymous_api`` limiter defined earlier, use
273273
class ApiController extends AbstractController
274274
{
275275
public function index(
276-
#[Target('anonymous_api.limiter')] RateLimiterFactoryInterface $rateLimiter
276+
#[Target('anonymous_api')] RateLimiterFactoryInterface $rateLimiter
277277
): Response
278278
{
279279
// ...
@@ -286,6 +286,11 @@ For example, to select the ``anonymous_api`` limiter defined earlier, use
286286
added and should now be used for autowiring instead of
287287
:class:`Symfony\\Component\\RateLimiter\\RateLimiterFactory`.
288288

289+
.. versionadded:: 7.4
290+
291+
Before Symfony 7.4, the target name had to include the ``.limiter``
292+
suffix (e.g. ``#[Target('anonymous_api.limiter')]``).
293+
289294
Using the Rate Limiter Service
290295
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
291296

reference/configuration/framework.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ to inject the ``foo_package`` package defined earlier::
301301

302302
When :ref:`dealing with multiple implementations of the same type <autowiring-multiple-implementations-same-type>`
303303
the ``#[Target]`` attribute helps you select which one to inject. Symfony creates
304-
a target called "asset package name" + ``.package`` suffix.
304+
a target with the same name as the asset package.
305305

306306
For example, to select the ``foo_package`` package defined earlier::
307307

@@ -311,12 +311,17 @@ For example, to select the ``foo_package`` package defined earlier::
311311
class SomeService
312312
{
313313
public function __construct(
314-
#[Target('foo_package.package')] private PackageInterface $package
314+
#[Target('foo_package')] private PackageInterface $package
315315
): void {
316316
// ...
317317
}
318318
}
319319

320+
.. versionadded:: 7.4
321+
322+
Before Symfony 7.4, the target name had to include the ``.package``
323+
suffix (e.g. ``#[Target('foo_package.package')]``).
324+
320325
.. _reference-framework-assets-packages:
321326

322327
packages

0 commit comments

Comments
 (0)