Skip to content
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

Support #[AutowireLocator] #411

Open
mvhirsch opened this issue Oct 7, 2024 · 3 comments
Open

Support #[AutowireLocator] #411

mvhirsch opened this issue Oct 7, 2024 · 3 comments

Comments

@mvhirsch
Copy link

mvhirsch commented Oct 7, 2024

Symfony 6.4 introduced an attribute called #[AutowireLocator] which automatically creates and injects a ServiceLocator into a service. Looks like a similar feature was already implemented with #151.

Is it possible to add support for this feature, too?

final class TranscriptAdmin
{
   // ...

    #[Required]
    public function setContainer(
        #[AutowireLocator([ProfileRepository::class])] ContainerInterface $container
    ): void {
        $this->locator = $container;
    }
}
 ------ ---------------------------------------------------------------------- 
  Line   src/TranscriptBundle/Admin/TranscriptAdmin.php                        
 ------ ---------------------------------------------------------------------- 
  56     Service "App\ProfileBundle\Repository\ProfileRepository" is private.  
         ✏️  src/TranscriptBundle/Admin/TranscriptAdmin.php                    
 ------ ---------------------------------------------------------------------- 
@RafaelKr
Copy link

The current workaround is to use // @phpstan-ignore symfonyContainer.privateService above the line where we use $this->locator->get. Of course this is not a nice solution.

Looking at https://github.com/phpstan/phpstan-symfony/blob/1ef4dce2baabd464c2dd3109d051bad94efa1e79/src/Rules/Symfony/ContainerInterfacePrivateServiceRule.php and #151 it shouldn't be very hard to implement a fix, unfortunately I currently don't have time for that.

@RafaelKr
Copy link

I just implemented support for the basic syntax as described in the OP (#[AutowireLocator([ProfileRepository::class])]). See #420

@RafaelKr
Copy link

RafaelKr commented Jan 3, 2025

I actually took the time and implemented AutowireLocator attribute support in #420
Currently there are some failing checks I can't resolve, but besides from that everything should be ready!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants