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

Skip to content

[DependencyInjection] allow extending Autowire attribute #49433

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
Feb 21, 2023

Conversation

kbond
Copy link
Member

@kbond kbond commented Feb 17, 2023

Q A
Branch? 6.3
Bug fix? no
New feature? yes
Deprecations? no
Tickets n/a
License MIT
Doc PR todo

This allows 3rd party package developers to make custom Autowire attribute helpers. Example:

class Repository extends Autowire
{
    public function __construct(string $class)
    {
        parent::__construct(expression: \sprintf("service('some.repository.factory').create('%s')", $class));
    }
}

And then it could be used with:

/**
 * @param ObjectRepository<User> $repository
 */
public function __construct(#[Repository(User::class)] private ObjectRepository $repository)
{
}

@kbond kbond requested a review from dunglas as a code owner February 17, 2023 21:18
@carsonbot carsonbot added this to the 6.3 milestone Feb 17, 2023
@carsonbot carsonbot changed the title [DI] allow extending Autowire attribute [DependencyInjection] allow extending Autowire attribute Feb 17, 2023
@nicolas-grekas
Copy link
Member

Thank you @kbond.

@nicolas-grekas nicolas-grekas merged commit bef46c8 into symfony:6.3 Feb 21, 2023
@kbond kbond deleted the di-extend-autowire branch February 26, 2023 11:17
@fabpot fabpot mentioned this pull request May 1, 2023
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