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

Allow service subscriber to have non-service name keys under certain circumstances. #352

Open
wants to merge 4 commits into
base: 1.2.x
Choose a base branch
from

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.

None yet

2 participants