Lacking way to order specific providers _from 3rd party_ libraries causing a big head ache #41334
-
A framework should make things easy to overwrite. statamic overwrites the 'translator' implementation e.g. Now I work on a package that wants to overwrite that translator as well. Problem is, the way it gets overwritten by statamic, does not forward calls to an existing translator like a decorator. furthermore, looking at the statamic translator implementation, using a decorator pattern would not even be enough for them, they need more than that e.g. maybe solve with calls to magic methods... but that is a different issue my issue is that the providers are loaded in an order I cannot control I tried using deferred provider, still gives me the wrong one. Implementation details of statamic: Provider order, they specify the provider in their own https://github.com/statamic/cms/blob/3.2/src/Providers/CpServiceProvider.php#L51 which they load here https://github.com/statamic/cms/blob/3.2/src/Providers/StatamicServiceProvider.php#L31 which they load via composer https://github.com/statamic/cms/blob/3.2/composer.json#L58 in bootstrap/cache/packages.php you can see that the order is alphabetically and since s for statamic/cms is very far "down" in the alphabet, it almost always gets loaded at the end I assume. What I want is a way to say "if a provider with class name Foo\Bar::class exists, load it before my provider MyCool\Provider::class" or a variation of that. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I do not think any external package for Laravel should be able to modify its bootstrap behavior. A compromise for you is that, if you decide to publish your package, you must make the user, add your service provider manually to This is how Laravel bootstraps the providers:
|
Beta Was this translation helpful? Give feedback.
I do not think any external package for Laravel should be able to modify its bootstrap behavior.
A compromise for you is that, if you decide to publish your package, you must make the user, add your service provider manually to
config/app.php
providers array, since any providers specified there are loaded after any package providers.This is how Laravel bootstraps the providers:
providers
array inconfig/app.php
.package:discover
command.