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

Skip to content

[DependencyInjection] Target attribute with invalid name should throw exception #45020

Closed
@kbond

Description

@kbond

Symfony version(s) affected

5.3+

Description

There is nothing stopping you from using an invalid name for the Target DI attribute.

How to reproduce

public function __construct(#[Target('someLogger')] LoggerInterface $logger)

In the above example, autowiring is not configured for Psr\Log\LoggerInterface $someLogger, the default logger is injected. I can imagine a scenario where you have a service injected but after an upgrade, the name is no longer valid so it is silently swapped for the default.

Possible Solution

I think the Target name should be validated when building the container and an exception thrown if invalid.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions