feat: enable/disable service providers#379
Merged
binaryfire merged 5 commits into0.4from May 1, 2026
Merged
Conversation
Lets a provider opt out of registration via runtime config / env / feature flags. Defaults to true so existing providers behave unchanged. When false, Application skips register(), boot(), bindings/singletons properties, and provider tracking entirely.
Honors ServiceProvider::isEnabled() during registration. Disabled providers are instantiated but never registered, never booted, never tracked, and their bindings/singletons properties are not applied — getProvider() and getLoadedProviders() do not see them.
Adds three unit tests: default returns true, override returns false, and override can read from the container/config. Also switches the file's base class to Hypervel\Tests\TestCase per porting conventions and adds the parent::setUp() call.
Adds integration tests for: a disabled provider is not registered or
tracked (getLoadedProviders, providerIsLoaded, getProvider, getProviders),
its bindings/singletons properties are skipped, and the late-register
branch (called after the app is booted) does not boot it. Three pre-
existing mockery-based tests gain shouldReceive('isEnabled')->andReturn(true)
since strict mocks throw on unstubbed lifecycle calls.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds
ServiceProvider::isEnabled(), giving providers a simple way to opt out of registration and booting.The default implementation returns
true, so existing providers keep working exactly as before. Packages that need conditional loading can override it and read from config, env or any other application state available during provider registration:When a provider is disabled, Hypervel skips
register(), skipsboot(), does not process the provider'sbindings/singletonsproperties, and does not mark the provider as loaded. This makes it useful for modular codebases where the same package set is installed across multiple apps, but each app enables only the modules it actually uses.This also pairs nicely with the existing
$priorityproperty, which allows setting a custom load order.