8000 Allow service subscriber to have non-service name keys under certain circumstances. by Basster · Pull Request #352 · phpstan/phpstan-symfony · GitHub
[go: up one dir, main page]

Skip to content

Conversation

Basster
Copy link
@Basster Basster commented May 8, 2023

You can define service subscribers with non-service name keys, e.g.

class SubmissionStrategyFactory implements ServiceSubscriberInterface
{
    public function __construct(private readonly ContainerInterface $locator)
    {
    }

    public function getStrategy(IllustrationSubmission $submission): SubmissionStrategyInterface
    {
        if ($submission->getIllustrationFile()) {
            return $this->locator->get('upload');
        }

        return $this->locator->get('url');
    }

    public static function getSubscribedServices(): iterable
    {
        yield 'upload' => UploadStrategy::class;
        yield 'url' => UrlStrategy::class;
    }
}

phpstan currently reports this as Service "upload" is not registered in the container.

This PR allows non-service argument names when the argument is a container and its called within a ServiceLocator.

Maybe, this is also related to #89

@stof
Copy link
Contributor
stof commented Sep 28, 2023

As is, this won't solve #89. For that, you would have to do the same detection of ServiceSubscriberInterface in the ContainerInterfacePrivateServiceRule.

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

Successfully merging this pull request may close these issues.

2 participants

0