Skip to content

[DependencyInjection] add AsAliasOf attribute #48523

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

Closed
wants to merge 1 commit into from

Conversation

kbond
Copy link
Member

@kbond kbond commented Dec 6, 2022

Q A
Branch? 6.3
Bug fix? no
New feature? yes
Deprecations? no
Tickets #47323, #41207, #41188
License MIT
Doc PR todo

This attribute is meant to be added to an interface to mark the implementation you wish it to be an alias for.

#[AsAliasOf(B::class)]
interface I {}

class A implements I;
class B implements I;

Now autowiring I gives you B.

Looking for feedback before finishing up.


TODO:

  • finish implementation
  • tests
  • changelog

@carsonbot carsonbot added Status: Needs Review DependencyInjection Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed) labels Dec 6, 2022
@carsonbot carsonbot changed the title [DependencyInjection][RFC] add AsAliasOf attribute add AsAliasOf attribute Dec 6, 2022
@carsonbot carsonbot added this to the 6.3 milestone Dec 6, 2022
@carsonbot carsonbot changed the title add AsAliasOf attribute [DependencyInjection] add AsAliasOf attribute Dec 6, 2022
@carsonbot
Copy link

Hey!

I think @Jean-Beru has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@chalasr
Copy link
Member

chalasr commented Dec 7, 2022

👍 for this (at least my mind changed since #41207)

@nicolas-grekas
Copy link
Member

I like it :)

On the implementation side, I feel like this implem might not work.

public function registerAliasesForSinglyImplementedInterfaces()

interfaces will not be declared as services, so that no compiler pass will be able to sniff the flag on them
maybe the attribute is something that should be dealt with by the file loader instead, to augment that "singly-implemented" logic
there's this also:
$autoconfigureAttributes->processClass($this->container, $r);

food for thoughts 🙂

@nicolas-grekas
Copy link
Member

Thanks for the try. I'm closing in favor of #49361, please have a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DependencyInjection Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed) Status: Needs Work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants