Add a 'signature' method to ServiceProviderInterface #93
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The existing ServiceProviderAggregate invariantly uses
get_class
to keep track of each provider to quickly and efficiently check to see if it has already been registered at some point in the past. This implementation prevents the use of the same Provider class to register services for multiple service providers.For example, in instances where an application has a number of providers, all of which register services in a similar way, then a single simple service provider, such as SimpleServiceProvider could potentially be used to handle all of them. (Example usage).
This technique works fine for the first module, but the second use of the same provider is not registered due to the
get_class
check in ServiceProviderAggregate.This PR adds a
signature
method to the ServiceProviderInterface, so that providers such as the SimpleServiceProvider may provide some different signature than its class name. The AbstractServiceProvider provides a default implementation ofsignature
that simply returnsget_class
, so existing providers that extend AbstractServiceProvider will continue to function in the same way they always have.The one downside of this implementation is that any provider that implements ServiceProviderInterface without extending AbstractServiceProvider will break, and will need to add a signature method in order to work again. This adjustment is trivial, but does break backwards compatibility.
If the concept of this PR looks acceptable, but strict backwards compatibility is desired, then I could add another ServiceProviderSignatureInterface, and test for it in ServiceProviderAggregate with a fallback to
get_class
for providers that do not implement the new interface. Such an implementation would be slightly more awkward than what is presented here, but would maintain strict backwards compatibility.