Skip to content

feat: enable/disable service providers#379

Merged
binaryfire merged 5 commits into0.4from
feat/enableable-service-providers
May 1, 2026
Merged

feat: enable/disable service providers#379
binaryfire merged 5 commits into0.4from
feat/enableable-service-providers

Conversation

@binaryfire
Copy link
Copy Markdown
Collaborator

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:

public function isEnabled(): bool
{
    return (bool) config('modules.billing.enabled');
}

When a provider is disabled, Hypervel skips register(), skips boot(), does not process the provider's bindings / singletons properties, 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 $priority property, which allows setting a custom load order.

binaryfire added 5 commits May 1, 2026 18:32
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.
@binaryfire binaryfire merged commit 0ce2c1e into 0.4 May 1, 2026
34 checks passed
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.

1 participant