-
-
Notifications
You must be signed in to change notification settings - Fork 15
Description
RFC
| Q | A |
|---|---|
| Proposed Version(s) | 1.10.0 |
| BC Break? | No |
Goal
laminas/laminas-modulemanager has a great feature that allows modules to be in a dependency tree. I would like a similar feature in this component.
There should be no changes to the current mechanisms, but dependent providers should be obtained and required in the order that they first appear, ahead of the ConfigProvider that requires them. (Edit: A clarification on this last point, and not my original intention but after a good suggestion by @boesing, the current list of providers in config.php should be considered as the first appearance if a provider is listed there).
Background
It is always necessary at the application level to include the ConfigProvider from all components used, even if there is no application code that specifically relies on those components (as they would be required and used internally by the external component). This can often lead to not knowing about providers that also need adding and there is no check to ensure that they are, nor any sufficient error message to explain to the user that this is the case.
Considerations
To use the new proposed mechanism should be an opt-in, and not require changes for those applications or components that do not wish to use it. This should be checked only the once and not affect the performance of retrieving from cache. Dependent providers should only be included once, and in the order that they first appear in the tree.
Since the changes would need to be made to provider loading, doing this as an external package would not be possible without also providing a modified ConfigAggregator.
Proposal(s)
I propose to introduce a new interface which requires a method providing a list of direct dependent ConfigProvider classes. This component would then check for this interface and prepend those required classes to the list of providers.
Appendix
Possible interface (names are just my first suggestions):
interface HasConfigProviderDependencies
{
/**
* @return iterable Array or \Iterator of provider dependencies. These are string values representing
* classes that act as providers. They must be instantiable without constructor arguments.
*/
public function configProviderDependencies(): iterable;
}Similar to/overlap with: