Skip to content

Conversation

javiereguiluz
Copy link
Member

@javiereguiluz javiereguiluz commented Sep 15, 2025

In #21134 we need to document how much easier is in 7.4 to pick the implementation using the #[Target] attribute. But, we don't have many examples of using that attribute in the first place. So, let's add it now and we'll later improve this in 7.4 branch and up.

Still WIP because we need to show the same for Lock and Semaphore.

@javiereguiluz javiereguiluz added this to the 6.4 milestone Sep 15, 2025
@carsonbot carsonbot changed the title (WIP) Use the #[Target] attribute in some examples (WIP) Use the #[Target] attribute in some examples Sep 15, 2025
@OskarStark OskarStark changed the title (WIP) Use the #[Target] attribute in some examples (WIP) Use the #[Target] attribute in some examples Sep 15, 2025
@javiereguiluz javiereguiluz changed the title (WIP) Use the #[Target] attribute in some examples Use the #[Target] attribute in some examples Sep 16, 2025
@carsonbot carsonbot changed the title Use the #[Target] attribute in some examples Use the #[Target] attribute in some examples Sep 16, 2025
@carsonbot carsonbot changed the title Use the #[Target] attribute in some examples [Asset][Lock][RateLimiter] Use the #[Target] attribute in some examples Sep 16, 2025
@javiereguiluz
Copy link
Member Author

I completed the pending work. This is now ready for review. Thanks.

lock.rst Outdated
class SomeService
{
public function __construct(
#[Target('invoice.lock.factory')] private LockFactory $invoiceLockFactory
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#[Target('invoice.lock.factory')] private LockFactory $invoiceLockFactory
#[Target('invoice.lock.factory')] private LockFactory $lockFactory

Like this to avoid confusion with the argument name used in the example before?

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#[Target('invoice.lock.factory')] private LockFactory $invoiceLockFactory
#[Target('invoice')] private LockFactory $lockFactory

And reading the code of the FrameworkExtension class I wonder if this would work too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but that only works in 7.4 and up because of #21134.

Here we're documenting the old way of doing it so we can update this in 7.4 to show the better way. Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

Oh indeed, but I guess renaming the argument would still be a good idea.

Copy link
Member Author

Choose a reason for hiding this comment

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

Absolutely! Good catch.

I just updated the argument names of the Target examples. Thanks for reviewing it!

class SomeService
{
public function __construct(
#[Target('foo_package.package')] private PackageInterface $fooPackage
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#[Target('foo_package.package')] private PackageInterface $fooPackage
#[Target('foo_package.package')] private PackageInterface $package

to avoid confusion with the previous argument

Copy link
Member

Choose a reason for hiding this comment

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

reading the code of the FrameworkExtension class this should be even easier like this:

Suggested change
#[Target('foo_package.package')] private PackageInterface $fooPackage
#[Target('foo_package')] private PackageInterface $package

@javiereguiluz javiereguiluz merged commit c251130 into symfony:6.4 Sep 19, 2025
@javiereguiluz javiereguiluz deleted the target_attribute branch September 19, 2025 14:07
OskarStark added a commit that referenced this pull request Sep 19, 2025
…tribute (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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants